当前位置:网站首页>Serial port programming
Serial port programming
2022-07-03 09:56:00 【Yiao】
Serial port programming
Before the serial port works , It should be initialized , It mainly sets the timer for generating baud rate 1、 Serial port control and interrupt control . The specific steps are as follows :
determine T1 How it works ( Programming TMOD register ) Calculation T1 Initial value of , load TH1、TL1;
start-up T1( Programming TCON Medium TR1 position ). Determine the serial port control ( Programming SCON register );
When the serial port works in interrupt mode , To set the interrupt ( Programmer Zheng E IP register ).
#include "reg52.h" // This file defines some special function registers of MCU
typedef unsigned int u16; // Declare and define data types
typedef unsigned char u8;
/******************************************************************************* * Function name :UsartInit() * The functionality : Set the serial port * Input : nothing * Output : nothing *******************************************************************************/
void UsartInit()
{
SCON=0X50; // Set to work 1
TMOD=0X20; // Set the working mode of the counter 2
PCON=0X80; // Double baud rate
TH1=0XF3; // The initial value of the counter is set , Note that the baud rate is 4800 Of
TL1=0XF3;
ES=1; // Turn on receive interrupt
EA=1; // Open total interrupt
TR1=1; // Turn on the counter
}
/******************************************************************************* * Letter Count name : main * The functionality : The main function * transport Enter into : nothing * transport Out : nothing *******************************************************************************/
void main()
{
UsartInit(); // Serial initialization
while(1);
}
/******************************************************************************* * Function name : Usart() interrupt 4 * The functionality : Serial communication interrupt function * Input : nothing * Output : nothing *******************************************************************************/
void Usart() interrupt 4
{
u8 receiveData;
receiveData=SBUF;// Go out and receive the data
RI = 0;// Clear the receive interrupt flag bit
SBUF=receiveData;// Put the received data into the transmit register
while(!TI); // Wait for the sending data to complete
TI=0; // Clear the transmission completion flag bit
}
边栏推荐
- Intelligent home design and development
- uniapp 实现微信小程序全局分享及自定义分享按钮样式
- [male nanny style] teach you to open the first wechat applet
- Successful graduation [3]- blog system update...
- SCM is now overwhelming, a wide variety, so that developers are overwhelmed
- Shell logic case
- 2021-09-26
- 嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
- [CSDN] C1 training problem analysis_ Part II_ Web Foundation
- STM32 external interrupt experiment
猜你喜欢
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
[22 graduation season] I'm a graduate yo~
当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
端午节快乐!—— canvas写的粽子~~~~~
STM32 port multiplexing and remapping
03 FastJson 解决循环引用
How MySQL modifies null to not null
随机推荐
el-table X轴方向(横向)滚动条默认滑到右边
CEF下载,编译工程
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
[CSDN]C1训练题解析_第二部分_Web基础
对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
The third paper of information system project manager in soft examination
Qt QComboBox QSS样式设置
一个可执行的二进制文件包含的不仅仅是机器指令
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
【順利畢業】[1]-遊覽 [學生管理信息系統]
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Development of fire power monitoring system
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
Nr--- Pusch I: sorting out the agreement process
01仿B站项目业务架构
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
Simple use of MySQL (addition, deletion, modification and query)
单片机学到什么程度能找到工作,这个标准不好量化