#include#include#define uchar unsigned char
#define uint unsigned int
uchar rdata;
uchar flag;
void usart_init(void)
{
UCSRC=0X86;
UBRRL=4;//12500BPS
UBRRH=0;
UCSRB=0X98;
SREG |=BIT(7);
}
void usart_send(uchar data)
{
while(!(UCSRA&BIT(5)));
UDR=data;
while(!(UCSRA&BIT(6)));
UCSRA |=BIT(6);
}
#pragma interrupt_handler usartrece:12
void usartrece(void)
{
SREG &=~BIT(7);
rdata=UDR;
flag=1;
SREG |=BIT(7);
}
void main(void)
{
uchar 1='h';
uart_init(9600);
// uart_send(i);
while(1)
{
if(flag)
{
flag=0;
uart_send(rdata);
}
}
}
网友评论