Kod: Markera allt
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#define FOSC 1000000 //clock
#define BAUD 4800 //baudrate
#define MYUBRR ((FOSC/16)/BAUD-1)
volatile double time= 0xff;
void USART_init (unsigned int ubrr){
/*set uart budrate*/
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/*Enable receiver and transmitter uart*/
UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXEN) | _BV(TXCIE);
/*set frameformat : 8 databits 1 stop bits (is default)*/
//UCSRC = (1<<URSEL) |(1<<USBS) | (3<<UCSZ0);
}
SIGNAL (SIG_USART_RECV)
{
time = UDR;
}
int main (void){
USART_init (MYUBRR);
sei();
for (;;){
_delay_ms(time);
UDR = time;
_delay_ms(time);
}
}