当前位置:网站首页>51 serial communication (on)
51 serial communication (on)
2022-08-09 05:38:00 【Fate gathering 654】
51 can realize the communication between the single-chip microcomputer and the computer, that is, control the single-chip microcomputer to realize some functions through the data transmission between the two
There is already a small tool called Serial Assistant in stc to help us realize serial communication
The receiving area is used to receive the data sent by the single-chip microcomputer to the computer, and the sending area is used for the computer to send the data to the single-chip computer.
The following is the related knowledge of serial port. For the specific content, you can watch the teaching video of Jiangxi Association for Automation 51 MCU at station B to understand
void UART_SendByte(unsigned char Byte);
void UART_Init();
Here we need to write two functions to realize the initialization of the serial port and the function of the computer to receive the data sent by the microcontroller
void UART_SendByte(unsigned char Byte){SBUF=Byte;while(TI==0){TI=0;}}void UART_Init(){SCON=0x40;PCON=0x80;TMOD &= 0x0F;TMOD |= 0x20;TL1=0xF4;TH1=0xF4;TF0=0;TR1=1;ET1=0;EA=1;PT0=0;}
Main function
unsigned char Sec;void main(){UART_Init();while(1){UART_SendByte(Sec);Sec++;Delay(1000);}}
This process is actually still sent by the computer to the microcontroller and then sent back to the computer by the microcontroller, so the effect of the operation is that the computer receives the binary number returned by the microcontroller and increases from 00
Then the computer sends data to the microcontroller and I will explain it next time
边栏推荐
猜你喜欢
随机推荐
一天学习一家上市公司:索菲亚
Shell 文本三剑客 (grep、sed、awk)
二分搜索篇
MATLAB图像处理入门
【零基础玩转BLDC系列】无刷直流电机闭环控制与软件架构
条件编译
STM32定时器输入捕获频率(cube)
快速上手Shell,看这一篇就够了
JDBC_PreparedStatement预编译对象
51串口通信(上)
Lock wait timeout exceeded; try restarting transaction 更新数据量范围太大,导致锁表惨案
cglib获取不到接口注解
p67 mixin 混入/混合:两个组件共享一个配置
屏:全贴合工艺之GF、GF2、G1F1、GG、TOL
如何一键进行Win11系统的重装?
【基于富瀚6630使用/dev/fb0显示设备和TDE模块渲染bmp图像】
could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarExcept
数组 冒泡排序
IDEA05:线程管理
使用Redis zset做消息队列