Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ioavr.h>
- #include <inavr.h>
- #define DV_50Hz 144
- #define DV_1Hz 36
- //Symbolic names for connecting 7-segment LED display
- #define LED_SEG PORTE
- #define LED_SEG_DIR DDRE
- #define LED_DG PORTB
- #define LED_DG_DIR DDRB
- #define DEC_OFF 0x3F
- #define DISP_MAX 6
- //Decoding table based on CD4056 -> '0123456789LHPA- '
- __flash unsigned char bcd_to_led[] = {
- 0xDE, 0x82, 0xEC, 0xE6,
- 0xB2, 0x76, 0x7E, 0xC2,
- 0xFE, 0xF6, 0x1C, 0xBA,
- 0xF8, 0xFA, 0x20, 0x00
- };
- unsigned char DEC_1_OF_6[] =
- {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
- //Global variables
- unsigned char freq_dv;
- unsigned char disp[6] = {0,0,0,0,0,0};
- unsigned static char time=0;
- //time should be set in form: [minute, second];
- unsigned static char lowerBorder[2]= {0,10};
- unsigned static char upperBorder[2]= {0,30};
- /*
- const char bordersLCD[] =
- lowe;
- void displayBorder()
- {
- LCDGoTo(LINE_1 + 21);
- LCDPuts(endingMes);
- }
- */
- void InitDevices()
- {
- LED_DG = 0xFE;
- LED_DG_DIR = 0xFF;
- LED_SEG_DIR = 0xFF;
- DDRA = 0x0;
- //Prescaler fclk / 1024 = 7200Hz
- //Prescaler for T0 is different than for T1,T2,T3
- OCR0 = DV_50Hz - 1;
- TCCR0 = (1 << CS02) | (1 << CS01) | (1 << CS00);
- TIMSK = (1 << OCIE0);
- __enable_interrupt();
- }
- int checkBorders(){
- if((time>(lowerBorder[0]*60+lowerBorder[1]) && time<(upperBorder[0]*60+upperBorder[1]))){
- return 1;
- } else {
- return 0;
- }
- }
- void Timer() {
- static unsigned char timer[4] = { 0, 0, 0, 0 };
- time++;
- timer[0] = time % 10;
- timer[1] = ((time - (time % 10) )/ 10) % 6;
- timer[2] = ((time - (time % 60))/60) %10;
- timer[3] = ((time - (time % 60)) / 60)/10 % 6;
- //bcd_to_led[
- // LED_SEG = bcd_to_led[(i++)%10];
- disp[0] = bcd_to_led[timer[0]];
- disp[1] = bcd_to_led[timer[1]];
- disp[2] = bcd_to_led[timer[2]];
- disp[3] = bcd_to_led[timer[3]];
- }
- #pragma vector = TIMER0_COMP_vect
- __interrupt void T0_COMP_ISR()
- {
- //static -> global variabl, visible insied declaration scope (file, function)
- static unsigned char cur_disp = 0;
- // LED_DG |= DEC_OFF;
- LED_SEG = disp[cur_disp];
- LED_DG = DEC_1_OF_6[cur_disp];
- if((++cur_disp) == DISP_MAX) cur_disp = 0;
- static unsigned char freq_dv = DV_1Hz;
- if(--freq_dv) return;
- freq_dv = DV_1Hz;
- //Update to nexy symbol from bcd_to_led array
- Timer();
- }
- void main()
- {
- InitDevices();
- while(1)
- {
- if(checkBorders()){
- DDRA = 0xFF;
- }else{
- DDRA = 0x0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement