znalazłem na forum bibliotekę c służącą do odbioru rc5(co prawa była pisana na At8 ale myślę że na At16 nie powinno być problemów)
ale jednak nie mogę uruchomić programu, w ogóle nie ma reakcji na pilot(uniwersalny ustawiony na RC5)
w pętli głównej programu wpisałem
w bibliotece zmieniłem ustawienia Timera0 wg opisu dla kwarcu 4Mhz
oto ta biblioteka
ale jednak nie mogę uruchomić programu, w ogóle nie ma reakcji na pilot(uniwersalny ustawiony na RC5)
w pętli głównej programu wpisałem
while(1)
{
if(rc5data)
{
PORTB=0x00;
}
}w bibliotece zmieniłem ustawienia Timera0 wg opisu dla kwarcu 4Mhz
oto ta biblioteka
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#define RC5BitHigh() (bit_is_set(PIND,PD3))
#define RC5BitLow() (bit_is_clear(PIND,PD3))
#define WAITFORTIMER() { while ( timerflag == 0); timerflag = 0; }
#define TIMER_0_CNT 0x22 // 111us with CLK/8 prescale kwarc 16mhz 0x22 /4mhz 0xc9
#define RC5BITREF1 6
#define RC5BITREF2 11
#define RC5BITREF3 14
#define IR_int_enable GIFR|=(1<<INT1);GICR|=(1<<INT1)
#define IR_int_disable GICR&=~(1<<INT1)
volatile uint8_t timerflag; //must be volatile because modified by interrupt handler
volatile unsigned int rc5data;
void rc5_init()
{
DDRD &= ~(1<<PD3); // konfiguracja PD3 jako wejście
PORTD |= (1<<PD3); // enable internal pull-up resistors
MCUCR|=_BV(ISC11); // ext. int. activated by falling edge
MCUCR&=~_BV(ISC10);
GIFR = (1<<INTF1); // clear ext. int. flag
GICR|=_BV(INT1); // enable ext. int.
}
SIGNAL(SIG_OVERFLOW0) //przepelneinie timera2
{
timerflag = 1; // set global variable
TCNT0 = TIMER_0_CNT; // reset counter to get this interrupt again
}
SIGNAL(SIG_INTERRUPT1)
{
IR_int_disable; //wylaczenie przerwan zewnetrznych
sei();
unsigned char timer, i;
// init timer/Counter2
TCCR0 = 0x02; // use CLK/8 prescale
TCNT0 = TIMER_0_CNT; // set timer T/16 = 111us
TIMSK |= (1<<TOIE0); // enable TCNT0 overflow interrupt
TIMSK &=~(1<<TOIE2); // disable TCNT2 overflow interrupt
// measure startbit
timerflag = 0; timer = 0;
while ( RC5BitLow() && (timer < RC5BITREF2) ) {
WAITFORTIMER();
timer++;
}
if ( (timer > RC5BITREF1) && (timer < RC5BITREF2) ) {
// startbit ok, decode
// wait T/4: synchronize in the middle of first half of second bit
while ( timer < RC5BITREF3 ) {
WAITFORTIMER();
timer++;
}
// read the remaining bits
rc5data = 1;
for (i=0; i<13; i++) {
rc5data <<= 1;
if ( RC5BitHigh() ) {
rc5data |= 0x0001;
// wait max T/2 for H->L transition (middle of next bit)
timer = 0;
while ( RC5BitHigh() && (timer < 16) ) {
WAITFORTIMER();
timer++;
}
}else{
rc5data &= ~0x00001;
// wait max T/2 for L->H transition (middle of next bit)
timer = 0;
while ( RC5BitLow() && (timer < 16) ) {
WAITFORTIMER();
timer++;
}
}
if ( timer == 16 ) {
rc5data = 0x0000; // error, next bit not found
return;
}
// wait 3/4 T: await next bit
for ( timer=0; timer < 12 ; timer++) WAITFORTIMER();
}
}else {
rc5data = 0x0000; // error, invalid RC-5 code
}
TCCR0=0;
TIMSK &=~(1<<TOIE0); // disable TCNT0 overflow interrupt
TIMSK |= (1<<TOIE2); // enable TCNT2 overflow interrupt
IR_int_enable;
}//rc5decode