[an error occurred while processing this directive]
|
// Target : M8
// Crystal: 3.6864Mhz
#include //TIMER0 initialize - prescale:1024 #pragma interrupt_handler timer0_ovf_isr:10 //call this routine to initialize all peripherals }
E-mail:
info@telesys.ru
#include
unsigned char ctr=0;
void port_init(void)
{
DDRB = 0xFF;
}
// desired value: 50Hz
// actual value: 50,704Hz (1,4%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x17; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0xB9; //set count
TCCR0 = 0x05; //start timer
}
void timer0_ovf_isr(void)
{
TCNT0 = 0xB9; //reload counter value
PORTB=0x00;
while(ctr<200)
{
ctr++; //
}
ctr=0;
PORTB=0xff;
TransmitByte(ReceiveByte());
}
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
unsigned char ReceiveByte( void )
{
while (!(UCSRA & (1<
return UDR;
}
}
void TransmitByte( unsigned char data )
{
while(!(UCSRA&(1<
UDR = data;//data; /* start transmittion */
}
void main(void)
{
init_devices();
while(1);
Ответы