#define uchar unsigned char
#define uint unsigned int
#define BUFFER_LENGTH 11
unsignedcharReceive_Calc=0;
unsignedcharUART_Receive_Buffer[11]={0};
unsignedcharUART_Send_Buffer[]={w,F,0,0,V,0,A,0,0,R,0};
//###########################################################
/*串口初始化函数*/
voidUart_Init(void)
{
UCSRA=(1<
UBRRH=0x00;// 设置波特率寄存器低位字节
UBRRL=95;//9600 (7.3728MHz) // 设置波特率寄存器高位字节
SREG_I=1;// 开总中断
DDRD_Bit1=1;// 配置TX 为输出(很重要)
}
//###########################################################
/*发送一个字符数据,查询方式*/
voidUart_Transmit_Char(unsignedchardata)
{
while(!(UCSRA&(1<
UDR=data;// 发送数据
}
//###########################################################
/*发送字符串*/
voidUart_Transmit_String(unsignedchar*ptr)
{
unsignedchari;
i=BUFFER_LENGTH;
while(i--)
{
Uart_Transmit_Char(*ptr++);
}
}
//###########################################################
/*中断接收*/
#pragma vector=USART_RXC_vect
__interruptvoidUSART_RXC_Server(void)
{
UART_Receive_Buffer[Receive_Calc++]=UDR;// 将收到的值赋值给变量
if(Receive_Calc>=11)
{
Receive_Calc=0;
}
}
//###########################################################
/*主函数*/
voidmain(void)
{
Uart_Init();
while(1)
{
Uart_Transmit_Char(0x0d);
Uart_Transmit_Char(0x0a);
}
}