Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TH0_RELOAD 0xF1
- #define TL0_RELOAD 0x00
- #define TIK 1
- int limit = 50;
- int glob=1;
- char state[4] = {0, 0, 0, 0};
- char number[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
- int btn_before[4] = {1, 1, 1, 1};
- int btn_current[4] = {0, 0, 0, 0};
- int debounce_cnt[4] = {0, 0, 0, 0};
- void timer0_init(void)
- {
- TH0 = TH0_RELOAD; // za.adowanie czasu odliczania
- TL0 = TL0_RELOAD; // TH0 . starszy bajt, TL0 - m.odszy
- TMOD = TMOD | 0x01; // tryb nr 1 uk.adu TIMER 0
- TR0 = 1; // TIMER 0 start
- ET0 = 1; // odblokowanie przerwa. od TIMER 0
- }
- void timer_isr (void) __interrupt (1) __using (0)
- {
- static int count=0;
- TH0 = TH0_RELOAD; // za.adowanie czasu odliczania
- TL0 = TL0_RELOAD;
- count++;
- if (count==TIK)
- {
- glob*=2;
- if(glob>8)
- {
- glob=1;
- }// dodatkowy licznik przerwa.
- count=0; // umo.liwiaj.cy uzyskanie dodatk.
- P2_7=!P2_7; // opo.nie.
- }
- }
- void main(void)
- {
- int a[4] = {0, 0, 0, 0};
- EA = 0; // zablokowanie przerwa.
- timer0_init(); // przygotowanie uk.adu Timer0
- EA = 1; // odblokowanie przerwa.
- P2=0xFF; // wygaszenie wszystkich diod
- while(1) {
- P2_6 = P3_6; // obs.uga przycisku i diody
- btn_current = P3_0;
- for( int i = 0; i<4 ; i++){
- if(state[i] == 0)
- {
- if(btn_before[i] != btn_current[i])
- {
- state[i]=1;
- btn_before[i] = btn_current[i];
- }
- }
- else if(state[i] == 1)
- {
- if(btn_before[i] == btn_current[i])
- {
- if(debounce_cnt[i] >= limit)
- {
- state[i]=2;
- a[i]++;
- if(a[i]>9)
- {
- a[i]=0;
- }
- }
- else
- debounce_cnt[i] = debounce_cnt[i] + 1;
- }
- else
- {
- state[i] = 0;
- btn_before[i] = btn_current[i];
- debounce_cnt[i] = 0;
- }
- }
- else if(state[i]==2)
- {
- if(btn_before[i] != btn_current[i])
- {
- state[i] = 0;
- btn_before[i] = btn_current[i];
- debounce_cnt[i] = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement