Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "8051.h" // zbior definiuj.cy rejestry procesora
- #define TH0_RELOAD 0xF1
- #define TL0_RELOAD 0x00
- #define TIK 1
- int limit = 20;
- int limit6 = 20;
- int glob=1;
- int state=0;
- int state1=0;
- int state2=0;
- int state3=0;
- int state6=0;
- char nad;
- char odb;
- char a,b,c,d;
- int btn_before=1;
- int btn_before1=1;
- int btn_before2=1;
- int btn_before3=1;
- int btn_before6=1;
- int btn_current;
- int btn_current1;
- int btn_current2;
- int btn_current3;
- int btn_current6;
- int debounce_cnt=0;
- int debounce_cnt1=0;
- int debounce_cnt2=0;
- int debounce_cnt3=0;
- int debounce_cnt6=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.
- }
- }
- void odbjur (void) __interrupt (4) __using (0)
- {
- if (RI==1)
- {
- // Tutaj nale.y umie.ci. obs.ug. odbioru
- odb=SBUF;
- d=odb&0x0F;
- c=(odb&0xF0)>>4;
- RI = 0;
- TI = 1;
- }
- }
- void serial_init(void)
- {
- SM0 = 1; // Ustawienie trybu pracy nr 2
- SM1 = 0;
- TI = 1; // Ustawienie bitu TI pozwalające
- // na rozpoczęcie nadawania w pętli głównej
- RI = 0;
- ES = 1; // Dopuszczenie przerwań od układu
- // transmisji szeregowej
- PCON = PCON & 0x7F;
- }
- void main(void)
- {
- int tab[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
- char a1=0, a2=0, a3=0, a4=0;
- EA = 0; // zablokowanie przerwa.
- timer0_init(); // przygotowanie uk.adu Timer0
- serial_init();
- EA = 1; // odblokowanie przerwa.
- REN = 1;
- P2=0xFF; // wygaszenie wszystkich diod
- while(1)
- {
- P2=0xFF; // wygaszenie wszystkich diod
- btn_current2 = P3_6;
- //przycisk b
- if(state2 == 0)
- {
- if(btn_before2 != btn_current2)
- {
- state2=1;
- btn_before2 = btn_current2;
- }
- }
- else if(state2 == 1)
- {
- if(btn_before2 == btn_current2)
- {
- if(debounce_cnt2 >= limit)
- {
- state2=2;
- a3++;
- if(a3>9)
- {
- a3=0;
- }
- }
- else
- debounce_cnt2 = debounce_cnt2 + 1;
- }
- else
- {
- state2 = 0;
- btn_before2 = btn_current2;
- debounce_cnt2 = 0;
- }
- }
- else if(state2==2)
- {
- if(btn_before2 != btn_current2)
- {
- state2 = 0;
- btn_before2 = btn_current2;
- debounce_cnt2 = 0;
- }
- }
- btn_current3 = P3_7;
- //przycisk do a
- if(state3 == 0)
- {
- if(btn_before3 != btn_current3)
- {
- state3=1;
- btn_before3 = btn_current3;
- }
- }
- else if(state3 == 1)
- {
- if(btn_before3 == btn_current3)
- {
- if(debounce_cnt3 >= limit)
- {
- state3=2;
- a4++;
- if(a4>9)
- {
- a4=0;
- }
- }
- else
- debounce_cnt3 = debounce_cnt3 + 1;
- }
- else
- {
- state3 = 0;
- btn_before3 = btn_current3;
- debounce_cnt3 = 0;
- }
- }
- else if(state3==2)
- {
- if(btn_before3 != btn_current3)
- {
- state3 = 0;
- btn_before3 = btn_current3;
- debounce_cnt3 = 0;
- }
- }
- btn_current6 = P3_3;
- if(P3_3==0){
- if(TI == 1)
- {
- nad = a4;
- nad = nad << 4;
- nad = nad|a3;
- SBUF=nad;
- TI=0;
- }
- }
- /*if(state6 == 0)
- {
- if(btn_before6 != btn_current6)
- {
- state6=6;
- btn_before6 = btn_current6;
- }
- }
- else if(state6 == 1)
- {
- if(btn_before6 == btn_current6)
- {
- if(debounce_cnt6 >= limit6)
- {
- state6=2;
- P2_3=!P2_3;
- if(TI == 1)
- {
- nad = a4;
- nad = nad << 4;
- nad = nad|a3;
- SBUF=nad;
- TI=0;
- }
- }
- else
- debounce_cnt6 = debounce_cnt6 + 1;
- }
- else
- {
- state6 = 2;
- btn_before6 = btn_current6;
- debounce_cnt6 = 0;
- }
- }
- else if(state6 == 2)
- {
- if(btn_before6 != btn_current6)
- {
- state6 = 0;
- btn_before6 = btn_current6;
- debounce_cnt6 = 0;
- }
- }
- */
- P1=glob;
- if(glob==8)
- {
- P0=tab[a4];
- }
- if (glob==4)
- {
- P0=tab[a3];
- }
- if(glob==2)
- {
- P0=tab[c];
- }
- if(glob==1)
- {
- P0=tab[d];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement