?lang_form?
?lang_select?
?lang_submit?
?lang_endform?
{HEADER END}
{FILE START}
library
?curdirlinks? - Rev 12
?prevdifflink? - Blame - ?getfile?
/****************************************
***** RC5 Protocol Counter **************
***** with special recognition RC5 ******
***** AT90S2313 4MHz ********************
***** 08/2005****************************
****************************************/
#include <90s2313.h>
void PortInit(void);
void Delay(unsigned long int time);
const unsigned char ir=64; //PD.6 je vstup IR signalu
const unsigned char timer=46; // 0,25 * bit = 0,4193325ms
/*merenim sem stanovil periodu jednoho bitu na 1,67733ms*/
unsigned char flag=1; //priznak prijmu signalu RC5
unsigned char ct=0; //pomocny citac
unsigned char s[3]={0,0,0}; //vzorky start bitu pro presne urceni ramce rc5
unsigned char adr=0; //adresa prijimanych dat
unsigned char data=0; //data
unsigned char togg=0; //toggle bit
void main (void){
PortInit();
SREG|=128; //vsechna prerus
TIMSK|=2; //prerus overflow ct0
TCNT0=timer;
for(;;){
while((PIND&ir)==ir){} //cekej na spadovou hranu - 1 start bit
TCCR0|=2; //zap ct0 + ck/8
ct=0; flag=1;
while(flag){} //cekej na konec prijmu
TCCR0=0; //vyp ct0
TCNT0=timer; //znova nastavi dany interval
Delay(1000);
if((s[0]==0)&(s[1]==1)&(s[2]==0)){PORTB=data;} //splnena startovaci podminka RC5
}
}
//***** Preruseni CT0 ****************************************************************
//prijem signalu
interrupt [TIM0_OVF] void timer0_overflow(void){
TCNT0=timer;
switch (ct++) {
case 0: if((PIND&ir)==ir){s[0]=1;}else{s[0]=0;} break; // 3/4 1.start bitu = 0
case 2: if((PIND&ir)==ir){s[1]=1;}else{s[1]=0;} break; // 1/4 2.start bitu = 1
case 4: if((PIND&ir)==ir){s[2]=1;}else{s[2]=0;} break; // 3/4 2.start bitu = 0
/*case 6: if((PIND&ir)==ir){togg=1;}else{togg=0;} break;
case 10: if((PIND&ir)==ir){adr|=16;}else{adr&=255-16;} break;
case 14: if((PIND&ir)==ir){adr|=8;}else{adr&=255-8;} break;
case 18: if((PIND&ir)==ir){adr|=4;}else{adr&=255-4;} break;
case 22: if((PIND&ir)==ir){adr|=2;}else{adr&=255-2;} break;
case 26: if((PIND&ir)==ir){adr|=1;}else{adr&=255-1;} break; */
case 30: if((PIND&ir)==ir){data|=32;}else{data&=255-32;} break;
case 34: if((PIND&ir)==ir){data|=16;}else{data&=255-16;} break;
case 38: if((PIND&ir)==ir){data|=8;}else{data&=255-8;} break;
case 42: if((PIND&ir)==ir){data|=4;}else{data&=255-4;} break;
case 46: if((PIND&ir)==ir){data|=2;}else{data&=255-2;} break;
case 50: if((PIND&ir)==ir){data|=1;}else{data&=255-1;} flag=0; break;
// co 4 preruseni je teprve cely bit
}
}
//***** Zpozdovaci procedura *********************************************************
void Delay(unsigned long int time) {
unsigned int j=0;
for (j=0;j<time;++j) {};
}
//***** Nastaveni portu **************************************************************
void PortInit(void){
DDRB=255; PORTB=0; //vystup + log0
DDRD=0; PORTD=ir; //vstupy + na ir pullup
} |
{FILE END}
{FOOTER START}
Powered by WebSVN v2.8.3