Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the communication code between serial port and PC based on AVR

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Based on AVR serial port and PC communication code how to write, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

In order to continue to improve the function according to this code in the future, I specially put the code here and learn with you.

/ * *

AVR clock: 8.00MHz

* baud rate 9600 (51) 8-bit data, 1 bit stop, when baud rate is set to 19200, UBRR=25,4800=103

* Note: the baud rate setting of 9600 is the best, and other data are unstable. Reference manual for UBRR values corresponding to different baud rates.

* the PC sends a character to the development board, and the development board writes back its capital letters to the PC

* * /

# include

# include

Void USART_Init (unsigned int baud)

{

/ * set baud rate, check the value of baud data manual * /

UBRRH = (unsigned char) (baud > > 8)

UBRRL = (unsigned char) baud

/ * receiver and transmitter enable * /

UCSRB = (1)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report