Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iom128.h>
- #include <inavr.h>
- #include "sys_event.h"
- #include "kb_drv.h"
- //Program configuration
- //#define ISR_PROCESSING
- #define PTR_ACCESS
- #define LED_SEG PORTE
- #define LED_SEG_DIR DDRE
- #define LED_DG PORTB
- #define LED_DG_DIR DDRB
- #define DV_480Hz 15
- #define DV_DEMO 40
- #define DV_NEXT 13
- #define DEC_OFF 0x3F
- #define DISP_MAX 6
- #define LED_BLANK 10
- //Decoding table based on CD4056 -> '0123456789LHPA- '
- __flash unsigned char BCD_2_LED[] = {
- 0xDE, 0x82, 0xEC, 0xE6,
- 0xB2, 0x76, 0x7E, 0xC2,
- 0xFE, 0xF6, 0x1C, 0xBA,
- 0xF8, 0xFA, 0x20, 0x00 };
- __flash unsigned char DEC_1_OF_6[] =
- {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
- //Global variables
- unsigned char disp[6] = {0,0,0,0,0,0};
- unsigned char dv_demo = DV_DEMO;
- unsigned char dv_next = DV_NEXT;
- unsigned char arr[20] = {1,2,1,3,7,2,1,3,4,2,2,1,3,2,3,4,1,2,3,2};
- __no_init unsigned char idx;
- #define UPDATE_DISP_RQ 0x01
- volatile TSystemEvent rq;
- unsigned char cnt;
- int diff;
- int counter;
- volatile unsigned char start=0;
- void InitDevices()
- {
- LED_DG = 0xFE;
- LED_DG_DIR = 0xFF;
- LED_SEG_DIR = 0xFF;
- kbInit();
- //Prescaler fclk / 1024 = 7200Hz
- //Prescaler for T0 is different than for T1,T2,T3
- OCR0 = DV_480Hz - 1;
- TCCR0 = (1 << WGM01) | (1 << CS02) | (1 << CS01) | (1 << CS00);
- TCCR1B = (1<<CS12);//|(1<<CS10);
- TIMSK = (1 << OCIE0)|(1<<TOIE1);
- __enable_interrupt();
- }
- void display()
- {
- for(unsigned char i = 0; i <= 19; i++)
- {
- disp[5] = arr[i];
- }
- }
- #pragma vector = TIMER1_OVF_vect
- __interrupt void T1_OVF_ISR()
- {
- static unsigned char cur_disp = 0;
- if (start==1)
- {
- disp[5] = arr[cur_disp];
- if((++cur_disp) == 5)
- {
- cur_disp = 0;
- }
- }
- }
- #pragma vector = TIMER0_COMP_vect
- __interrupt void T0_COMP_ISR()
- {
- static unsigned char cur_disp = 0;
- LED_DG |= DEC_OFF;
- LED_SEG = BCD_2_LED[disp[cur_disp]];
- LED_DG = DEC_1_OF_6[cur_disp];
- if((++cur_disp) == DISP_MAX)
- {
- cur_disp = 0;
- kbService();
- }
- }
- void incVal()
- {
- if((++cnt) == 9) cnt = 0;
- disp[5] = BCD_2_LED[cnt];
- }
- void decVal()
- {
- if((--cnt) == 255) cnt = 9;
- disp[5] = BCD_2_LED[cnt];
- }
- void main()
- {
- InitDevices();
- while(1)
- {
- if(rq.kb)
- {
- rq.kb = 0;
- switch(kb_reg) {
- case KEY_0:
- incVal();
- break;
- case KEY_1:
- decVal();
- break;
- case KEY_2:
- start=1;
- break;
- case KEY_3:
- break;
- case KEY_4:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement