前两天做了一个AVR单片机串口发送,PC端串口调试软件接收小实验,串口寄存器初使化由ICCAVR生成:
#include "avr/io.h " //GCC
void uart0_init(void)
{
// Target : M88
// Crystal: 3.6864Mhz
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
// char size: 8 bit
// parity: Disabled
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x17; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x08;
}
void USART_Transmit(unsigned char data)
{
//等待发送缓冲器为空
while(!(UCSR0A&(1<<UDRE0)));
//将数据放入缓冲器,发送出据
UDR0=data;
}
int main()
{
uart0_init();
while(1)
{
USART_Transmit('w');
USART_Transmit('a');
USART_Transmit('n');
USART_Transmit('g');
USART_Transmit('q');
USART_Transmit('i');
USART_Transmit('s');
USART_Transmit('h');
USART_Transmit('a');
USART_Transmit('o');
USART_Transmit(0x0D);
USART_Transmit(0x0A);// 0x0D(回车)0x0A(换行)
USART_Transmit(0xCD);
USART_Transmit(0xF5);//王
USART_Transmit(32);//空格
USART_Transmit(0xC6);
USART_Transmit(0xE4);//其
USART_Transmit(0xC9);
USART_Transmit(0xD9);//少
USART_Transmit(0x0D);
USART_Transmit(0x0A);
USART_Transmit(0xB5);
USART_Transmit(0xE7);//电
USART_Transmit(0xD1);
USART_Transmit(0xB9);//压
USART_Transmit(0x0D);
USART_Transmit(0x0A);
}
}
文章评论(0条评论)
登录后参与讨论