1) Hardware Design
Generally, the serial port communication of a microcontroller needs to be converted by MAX232 for level conversion before data communication. Of course, the STC89C52RC microcontroller is no exception. The connection method in the figure is the simplest connection of the commonly used zero-modem method, that is, the 3-wire connection method: only the RXD, TXD and GND lines are used, as shown below.
STC89C52 serial port application example
Since the logic "0" level of RS232 is specified as +5~+15V, and the logic "1" level is specified as -15~-5V, it cannot be directly connected
to the TTL/CMOS circuit and must be converted.
Level conversion can be achieved using discrete devices such as transistors, or a dedicated level conversion chip, MAX232 is a typical
one. MAX232 can not only achieve level conversion, but also realize mutual conversion of logic, that is, positive logic to negative logic.
#include "stc.h" //Load "stc.h" header file
void Delay(void) //Define Delay function, delay 500ms
{
unsigned char i,j; //Declare variables i,j
for(i=0;i<255;i++) //Perform loop operation to achieve the delay effect
for(j=0;j<255;j++);
for(i=0;i<255;i++) //Perform loop operation to achieve the delay effect
for(j=0;j<255;j++); for(i=0;i<255;i++) //Perform loop operation to achieve the delay effect for(j=0;j<255;j++);
for(i=0;i<255;i++) //Perform loop operation to achieve the delay effect
for(j=0;j<140;j++);
}
void UARTInit(void) //Define serial port initialization function
{
SCON =0x40; //8-bit data bit
T2CON=0x34; //T/C2 is used as the baud rate generator
RCAP2L=0xD9; //The baud rate is 9600 The lower 8 bits of
RCAP2H=0xFF; //The higher 8 bits of the baud rate is 9600
}
void UARTSendByte(unsigned char byte)//Serial port sends a single byte function
{
SBUF=byte; //The buffer loads the byte to be sentwhile
(TI==0); //Wait for the sending to be completed, the TI flag will be set to 1
TI=0; //Clear the sending completion flag
}
void main(void) //Enter the Main function
{
unsigned char i=0; //Declare variable i
UARTInit(); //Serial port initializationwhile
(1) //Enter an infinite loop
{
UARTSendByte(i); //Serial port sends a single byte of dataDelay
(); //Delay 500ms
i++; //i adds 1
if(i>255)i=0; //If i>255,i=0
}
}
Previous article:STC51 MCU serial port sending program
Next article:The single chip microcomputer collects real-time temperature and uploads it to the computer display through serial communication
Recommended ReadingLatest update time:2024-11-16 22:55
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Traffic Light Control System Based on Fuzzy Control (Single-Chip Microcomputer Implementation)
- Principles and Applications of Single Chip Microcomputers (Second Edition) (Wanlong)
- MCU Principles and C51 Programming Tutorial (2nd Edition)
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
- MSP430F5529 IO port pin interrupt study notes
- Circuit-level electrostatic protection design techniques and ESD protection methods
- CC3200 Kit OURS-SDK-WFB_Exploration 4——FreeRTOS Run
- The microcontroller outputs PWM wave to control the load supply voltage 0-12V adjustable
- 【Insights】If you don’t plant flowers in your heart, weeds will grow
- [ESP32-Korvo Review] 1: ESP32-Korvo Audio Development Board Hardware Circuit Connection
- I would like to ask which manufacturers produce unipolar TMR tunneling effect switches. I only found MDT, and Magne does not have unipolar ones.
- Altium16.1 manufacturing output IPC-2581 and odb++ formats are not working
- Three Key Points to Successfully Solving FPGA Design Timing Problems
- [CY8CKIT-149 PSoC 4100S Review] + Software Installation and Program Download