Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ioavr.h>
- #include <inavr.h>
- #include "kb_drv.h"
- #include "sys_event.h"
- //#include "stdlib.h"
- //#include "features.h"
- //#include "time.h"
- #define DV_50Hz 144
- #define DV_1Hz 25
- #define DV_96Hz 5
- #define SYS_IDLE 0x00
- #define TIME_UPDATE 0x01
- #define KB_HIT 0x02
- //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 KB DDRA
- //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
- };
- //Global variables
- unsigned char freq_dv, symb_ID;
- unsigned int arr[20] = {1,3,2,4,3,2,1,3,4,2,2,1,3,2,3,4,1,2,3,2};
- unsigned int diff;
- unsigned int counter;
- static unsigned char kb_dv = DV_96Hz;
- void InitDevices()
- {
- KB = 0;
- kbInit();
- LED_DG = 0xFE;
- LED_DG_DIR = 0xFF;
- LED_SEG_DIR = 0xFF;
- //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();
- }
- #pragma vector = TIMER0_COMP_vect
- __interrupt void T0_COMP_ISR()
- {
- //static -> global variabl, visible insied declaration scope (file, function)
- static unsigned char freq_dv = DV_1Hz;
- if(--freq_dv) return;
- freq_dv = DV_1Hz;
- //Update to nexy symbol from bcd_to_led array
- symb_ID = (symb_ID + 1) & 0x0F; // & 0x0F -> mod 16
- if(symb_ID > 9)
- {
- symb_ID = 0;
- }
- LED_SEG = bcd_to_led[symb_ID];
- if((--kb_dv) == 0)
- {
- kb_dv = DV_96Hz;
- kbService();
- }
- }
- //void generateArray()
- //{
- // for( int i = 0; i < diff; i++)
- // {
- // arr[i] = (rand() % 4) + 1;
- // }
- //}
- void start()
- {
- }
- void lose()
- {
- }
- void gz()
- {
- }
- void main()
- {
- rq.ev = SYS_IDLE;
- symb_ID = -1;
- InitDevices();
- kb_rep = 0x0F;
- diff = 4;
- counter = 0;
- while(counter < diff)
- {
- if(rq.kb)
- {
- rq.kb = EVENT_PROCESSED;
- if(kb_reg & 0x01)
- {
- if(arr[counter] == 1)
- {
- counter++;
- continue;
- }
- else
- lose();
- }
- else if(kb_reg & 0x02)
- {
- if(arr[counter] == 2)
- {
- counter++;
- continue;
- }
- else
- lose();
- }
- else if(kb_reg & 0x04)
- {
- if(arr[counter] == 3)
- {
- counter++;
- continue;
- }
- else
- lose();
- }
- else if(kb_reg & 0x08)
- {
- if(arr[counter] == 4)
- {
- counter++;
- continue;
- }
- else
- lose();
- }
- else if(kb_reg & 0x10)
- {
- start();
- }
- //else if(kb_reg & 0x20);
- //else if(kb_reg & 0x40);
- else if(kb_reg & 0x80)
- {
- lose();
- }
- else
- //Remove notifications
- kb_reg = KB_IDLE;
- }
- }
- if (counter == diff)
- {
- gz();
- }
- else
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement