Line No. | Rev | Author | Line |
---|---|---|---|
1 | 12 | kaklik | /**************************************** |
2 | ***** RC5 Protocol Counter ************** |
||
3 | ***** with special recognition RC5 ****** |
||
4 | ***** AT90S2313 4MHz ******************** |
||
5 | ***** 08/2005**************************** |
||
6 | ****************************************/ |
||
7 | |||
8 | #include <90s2313.h> |
||
9 | |||
10 | void PortInit(void); |
||
11 | void Delay(unsigned long int time); |
||
12 | |||
13 | const unsigned char ir=64; //PD.6 je vstup IR signalu |
||
14 | |||
15 | const unsigned char timer=46; // 0,25 * bit = 0,4193325ms |
||
16 | |||
17 | /*merenim sem stanovil periodu jednoho bitu na 1,67733ms*/ |
||
18 | |||
19 | unsigned char flag=1; //priznak prijmu signalu RC5 |
||
20 | unsigned char ct=0; //pomocny citac |
||
21 | unsigned char s[3]={0,0,0}; //vzorky start bitu pro presne urceni ramce rc5 |
||
22 | unsigned char adr=0; //adresa prijimanych dat |
||
23 | unsigned char data=0; //data |
||
24 | unsigned char togg=0; //toggle bit |
||
25 | |||
26 | void main (void){ |
||
27 | PortInit(); |
||
28 | SREG|=128; //vsechna prerus |
||
29 | TIMSK|=2; //prerus overflow ct0 |
||
30 | TCNT0=timer; |
||
31 | |||
32 | for(;;){ |
||
33 | |||
34 | while((PIND&ir)==ir){} //cekej na spadovou hranu - 1 start bit |
||
35 | |||
36 | TCCR0|=2; //zap ct0 + ck/8 |
||
37 | ct=0; flag=1; |
||
38 | while(flag){} //cekej na konec prijmu |
||
39 | TCCR0=0; //vyp ct0 |
||
40 | TCNT0=timer; //znova nastavi dany interval |
||
41 | Delay(1000); |
||
42 | |||
43 | if((s[0]==0)&(s[1]==1)&(s[2]==0)){PORTB=data;} //splnena startovaci podminka RC5 |
||
44 | |||
45 | } |
||
46 | } |
||
47 | //***** Preruseni CT0 **************************************************************** |
||
48 | //prijem signalu |
||
49 | interrupt [TIM0_OVF] void timer0_overflow(void){ |
||
50 | TCNT0=timer; |
||
51 | |||
52 | switch (ct++) { |
||
53 | case 0: if((PIND&ir)==ir){s[0]=1;}else{s[0]=0;} break; // 3/4 1.start bitu = 0 |
||
54 | case 2: if((PIND&ir)==ir){s[1]=1;}else{s[1]=0;} break; // 1/4 2.start bitu = 1 |
||
55 | case 4: if((PIND&ir)==ir){s[2]=1;}else{s[2]=0;} break; // 3/4 2.start bitu = 0 |
||
56 | |||
57 | /*case 6: if((PIND&ir)==ir){togg=1;}else{togg=0;} break; |
||
58 | |||
59 | case 10: if((PIND&ir)==ir){adr|=16;}else{adr&=255-16;} break; |
||
60 | case 14: if((PIND&ir)==ir){adr|=8;}else{adr&=255-8;} break; |
||
61 | case 18: if((PIND&ir)==ir){adr|=4;}else{adr&=255-4;} break; |
||
62 | case 22: if((PIND&ir)==ir){adr|=2;}else{adr&=255-2;} break; |
||
63 | case 26: if((PIND&ir)==ir){adr|=1;}else{adr&=255-1;} break; */ |
||
64 | |||
65 | case 30: if((PIND&ir)==ir){data|=32;}else{data&=255-32;} break; |
||
66 | case 34: if((PIND&ir)==ir){data|=16;}else{data&=255-16;} break; |
||
67 | case 38: if((PIND&ir)==ir){data|=8;}else{data&=255-8;} break; |
||
68 | case 42: if((PIND&ir)==ir){data|=4;}else{data&=255-4;} break; |
||
69 | case 46: if((PIND&ir)==ir){data|=2;}else{data&=255-2;} break; |
||
70 | case 50: if((PIND&ir)==ir){data|=1;}else{data&=255-1;} flag=0; break; |
||
71 | // co 4 preruseni je teprve cely bit |
||
72 | } |
||
73 | } |
||
74 | //***** Zpozdovaci procedura ********************************************************* |
||
75 | void Delay(unsigned long int time) { |
||
76 | unsigned int j=0; |
||
77 | for (j=0;j<time;++j) {}; |
||
78 | } |
||
79 | //***** Nastaveni portu ************************************************************** |
||
80 | void PortInit(void){ |
||
81 | DDRB=255; PORTB=0; //vystup + log0 |
||
82 | DDRD=0; PORTD=ir; //vstupy + na ir pullup |
||
83 | } |
Powered by WebSVN v2.8.3