AVR单片机的串口查询设计

控制/MCU

1814人已加入

描述

* Code adapted from Atmel AVR ApplICation Note AVR306

* PolLEDmode driver forUART, this is the similar to the

* library default putchar() and getchar() in ICCAVR

*/

#include


 

#include

#include “uart.h”

/* initialize UART */

void InitUART( unsigned char baudrate )

{

UBRR = baudrate; /* set the baud rate */

UCR = BIT(RXEN) | BIT(TXEN); /* enable UART receiver and transmitter */

}

/* Read and write functions */

unsigned char ReceiveByte( void )

{

while ( !(USR & (1《; /* return the data */

return UDR;

}

void TransmitByte( unsigned char data )

{

while ( !(USR & (1《; /* wait for empty transmit buffer */

UDR = data; /* start transmittion */

}

#ifdef TEST

/* main - a simple test program*/

void main( void )

{

InitUART( 11 ); /* set the baudrate to 19,200 bps using a

3.6864MHzcrystal */

while ( 1 ) /* forever */

{

TransmitByte( ReceiveByte() ); /* echo the received character */

}

}

#endif

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分