w mainie w funkcji while(1), sprawdzam tylko warunek if(bit_is_clear(PIND,PD2)) rc5decode(); <-- TAK DZIAŁA !
jak wywołać tą funkcję w przerwaniu SIGNAL(SIG_INTERRUPT0) {}, ?
probowałem tak:
w mainie:
w przerwaniu od INTO:
ale nie działa.
kod programu:
jak wywołać tą funkcję w przerwaniu SIGNAL(SIG_INTERRUPT0) {}, ?
probowałem tak:
w mainie:
GICR |=1<<INT0;w przerwaniu od INTO:
SIGNAL(SIG_INTERRUPT0) {
GICR &= ~BV(INT0);
rc5decode(); //wywołanie porządanej funkcji
GICR |= _BV(INT0);
}kod programu:
SIGNAL(SIG_OVERFLOW0) // przerwanie od przepelnienia timer0
{
timer_flag = 1; // ustawienie 1 jako flagi globalnej
TCNT0 = TIMER_0_CNT; // resetowanie timera, aby przerwanie wywolalo sie znowu
}
void rc5decode( void ) // decoded RC5 data is returned, or 0x0000 if RC5 data not recognized
{
rc5data=0;
unsigned char timer, i;
// init timer/Counter0
TCCR0 = _BV(CS01); // use CLK/8 prescale
TCNT0 = TIMER_0_CNT; // set timer T/16 = 111us
TIMSK = _BV(TOIE0); // enable TCNT0 overflow interrupt
// measure startbit
timer_flag = 0; timer = 0;
while ( RC5BitLow() && (timer < RC5BITREF2) )
{
{ while ( timer_flag == 0); timer_flag = 0; }
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 ) {
{ while ( timer_flag == 0); timer_flag = 0; }
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) ) {
{ while ( timer_flag == 0); timer_flag = 0; }
timer++;
}
}else{
rc5data &= ~0x00001;
// wait max T/2 for L->H transition (middle of next bit)
timer = 0;
while ( RC5BitLow() && (timer < 16) ) {
{ while ( timer_flag == 0); timer_flag = 0; }
timer++;
}
}
if ( timer == 16 ) {
rc5data = 0x0000; // error, next bit not found
break;
}
// wait 3/4 T: await next bit
for ( timer=0; timer < 12 ; timer++) { while ( timer_flag == 0); timer_flag = 0; }
}
}else {
rc5data = 0x0000; // error, invalid RC-5 code
}
TCCR0 = 0; // stop timer0
if ( rc5data & 0x3000 )
{
komenda = rc5data & 0x3F;
adres = rc5data & 0x7C0;
adres >>= 6;
toggle = (rc5data & 0x800);
toggle >>= 11;
sprintf(bufor,"adres:%u komenda:%u toggle:%u \n\r",adres,komenda,toggle);
send_string(bufor);
}
}
int main(void)
{
DDRB = 0xff; // use all pins on port B for output
PORTB = 0xff;
DDRC = 0xff;
PORTC = 0x00;
USART_Init(UART_CONST); // inicjalizacja rs'a
sei(); //globalne zezwolenie na przerwania
while(1)
{
//while ( RC5BitHigh() ); // wait until RC5 code received
if(RC5BitLow())
rc5decode();
}
}