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 customize the pin of MCU to make UART serial port

2025-05-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces MCU how to customize the pin to do UART serial port, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

When the UART port of the chip is not enough, we can consider using other pins as UART.

There are two kinds of data protocols for serial port RS232. We take the asynchronous mode commonly used between PC and 8-bit / 32-bit single-chip microcomputer as an example.

The TXD pin of the single-chip microcomputer first sends a low level 0 to the other side, then sends 5-8 bits as data, and finally sends 1 bit parity and 1 bit high level 1 as stop bits.

The following example is a baud rate of 9600bp: 1 start bit, 8 data bits, 1 stop bit [10-bit data, no parity bit: 9600-8-N-1]

Baud rate: the number of bytes sent per second if baudrate=9600, that is, each bit sent takes 1000/9600=104uSec

/ * * using 51 chip timer to interrupt analog serial port message sending advantages: serial port pins can be customized. Can achieve multiple serial port format: 9600-8-N-1 function: analog serial port Send**/#include char g_nSendInx=0 Char MY_TXD P1Buffer0 / / Analog TXD pin void Timer0Init (void) / / 104 microseconds @ 11.0592MHz {/ / 1000ms/9600=104.166us / / using this scheme, due to accuracy problems, there will occasionally be several errors in long-term transmission & = 0xF0; / / set timer mode TMOD | = 0x02; / / set timer mode TL0 = 0xA0 / / set timing initial value TH0 = 0xA0; / set timing reload value TF0 = 0; / / clear TF0 flag TR0 = 1; / / timer 0 start timing ET0=1; EA=1 } / * * Custom Serial Port to send single character * * / void MyUart_Send (char ch) {groomnFlagger0; gSecretnBuffering; TR0=1; while (g_nFlag==0) } / * * Custom serial port sending string * * / void MyUart_String (char* str) {int iTun0; while (* (str+i)) {iTunes; gambinFlagger 0; gambinBuffered * (str+i); TR0=1; while (g_nFlag==0) }} / * timer 0 interrupts service * / void Timer0_ISP () interrupt 1 {gsignSendInx interrupt counter / send simulation bit if (g_nSendInx==1) {MY_TXD=0;// start bit lower} else if (g_nSendInx==10) / / format: 9600-8-N-1, complete 10 bytes {MY_TXD=1;// stop bit pulls up TR0=0; gendInx zero; g_nFlag=1 / / send completion flag bit} else {MY_TXD=g_nBuff&0x01;////sbuffer_data g_nBuff > > = 1 }} / * * interrupt analog serial port signal with Timer0 timing * * / void main (void) {Timer0Init (); / / timer initialization, period is 1000ms/9600=104us MyUart_String ("= = Welcome,My Uart===\ r\ n") MyUart_Send (0x61); MyUart_Send (0x62); MyUart_Send (0x63); while (1);} Thank you for reading this article carefully. I hope the article "how to customize MCU pins to make UART Serial Port" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Internet Technology

Wechat

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

12
Report