Generally, microcontrollers only have one serial port, so one must be simulated.
/*
sbit TXD1 = P1^4; //define p14 as the analog transmit port
sbit RXD1 = P1^2; //define p12 as the analog recieve port
*/
#include "REG52.H"
#define uint unsigned int
#define uchar unsigned char
#include
void WaitTF0(void);
void TIMEINI(void) //counter initial
{
TMOD=0x02;
TH0=0xA0; , //9600 BPS
TL0=TH0;
TR0=1;
TF0=0;
}
void WByte(uchar input) // send function
{
uchar i=8;
TR0=1;
TXD1=0; //begin bit
WaitTF0();
//send the Byte
while(i--)
{
TXD1=input&0x01; //send Byte from low bit to high bit
WaitTF0();
input=input>>1; //right shift
}
TXD1=1; //stop bit
WaitTF0();
TR0=0; //stop the counter
}
uchar RByte() //the recieve function
{
uchar Output=0;
uchar i=8;
while(RXD1);
i=i;
i=i;
i=i;
i=i;
i=i;
i=i;
i=i;
TR0=1; //The counter starts working
WaitTF0();
while(i--) // Receive 8 bits of data
{
Output>>=1;
if(RXD1)Output=Output|0x80; //recieve from the high bit to low bit
WaitTF0();
}
TR0=0;
return Output;
}
void WaitTF0(void) //check the counter
{
while(!TF0);
TF0=0;
}
Previous article:Introduction to MCU IO port configuration mode
Next article:Design of a weighing device with CAN bus communication
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Common PCB Layout Pitfalls
- Take a look at the antique filter
- Fudan Micro offline programmer information and MCU application notes
- [GD32E503 Review] Part 9: Simple Oscilloscope
- Bring your girlfriend home to meet your parents
- [Fudan Micro FM33LG0 series development board review] Development board microcontroller printf Chinese and English printing test
- Control the state of multiple IOs through the serial port
- Mobile phone RF is moving towards integrated chips
- EEWORLD University ---- Make your home safer - Intelligent building security system
- TI 2022 exciting technical live replays are ready for you!