Hallo SprintSB,
ich habe jetzt einige Sachen verändert, ausgebessert, etc., aber rc5.code ist immer 0. Hat noch jemand eine Idee, was ich da falsch mache?
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
struct rc5_parts
{
volatile char s_bit;
volatile uint8_t addresse;
volatile uint8_t code;
volatile char rdy;
} rc5;
char mid;
volatile uint8_t bitnummer = 0;
void init_rc5()
{
MCUCR |= (1<<ISC11) | (1<<ISC10);
GICR |= (1<<INT1);
TCCR0 |= (1<<CS02);
}
//****************************************************USART******************************
void init_usart(void)
{
UBRRL |= 0b01100111;
UCSRB = (1<<TXEN) | (1<<RXEN);
UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
}
void send_char(unsigned char s)
{
while (!(UCSRA & (1<<UDRE)));
UDR = s;
}
void send_string(char *s)
{
while(*s != '\0')
{
send_char(*s);
s++;
}
}
//**********************************************************USART-ENDE********************
SIGNAL(SIG_OVERFLOW0)
{
bitnummer++;
TCNT0 = 145; //Timer soll nach 1.778ms Overflow haben
if(bitnummer == 12)
{
TIMSK &= ~(1<<TOIE0);
rc5.rdy = 1;
rc5.s_bit = 0;
bitnummer = 13;
}
if(bitnummer<6) //Wenn i<6, werden die ausgelesenen Bits zu Addresse hinzugefügr
{
if((PORTD & (1<<3)) == 1)
{
rc5.addresse |= (1<<(bitnummer-1));
}
else
{
rc5.addresse &= ~(1<<(bitnummer-1));
}
}
if((bitnummer>=6)&(bitnummer<=11)) //6 - 11 werden zu rc5.code hinzugefügt
{
if((PORTD & (1<<3)) == 1)
{
rc5.code = 0xff; //(1<<(bitnummer-6));
}
else
{
rc5.code = 0x00; //~(1<<(bitnummer-6));
char hello[15] = "111";
send_string(hello);
}
}
}
SIGNAL(SIG_INTERRUPT1)
{
if(rc5.s_bit<4)
{
rc5.s_bit++;
}
if(rc5.s_bit == 4)
{
TIMSK |= (1<<TOIE0); // Timer0 Interrupts enablen
TCNT0 |= 228; //Timer so vorladen, dass er zur Mitte des 2. Halbbits den ersten Timeroverflow hat
GICR &= ~(1<<INT1); //Int1 disablen
}
}
int main(void)
{
init_usart();
init_rc5();
char i = 1;
sei();
char result[10];
char hello[15] = "Hallo Martin";
send_string(hello);
for(;;)
{
if(rc5.rdy == 1)
{
itoa(rc5.code,result,10);
char hello2[15] = "RC5";
send_string(hello2);
send_string(result);
rc5.rdy = 0;
GICR |= (1<<INT1);
}
}
}
Lesezeichen