1. Overall design
1. Design requirements:
Serial communication is carried out between the two microcontrollers. The sending end sends 0~f loop to the receiving end, and it is displayed on the receiving end.
2. Design plan:
In this design, for two 89C51 chips, RS232 is used for dual-machine communication. The data of the sender is output from the TXD segment of the serial port, and the TTL level is converted to RS232 level output through the level conversion chip MAX232, and the signal is transmitted to the receiving end through the transmission line. The receiver also uses the MAX232 chip to convert the level, and the signal reaches the receiving end of the serial port of the receiver. After the receiver receives it, the received information is displayed on the digital tube. In order to improve the anti-interference ability, optical coupling can also be added to the input and output ends for photoelectric isolation.
In the software part, the communication protocol is used for sending and receiving. The host first sends AAH to the slave. When the slave receives AAH, it replies BBH to the host. After receiving BBH, the host sends 10 data in the digital table TAB[16] to the slave and sends a checksum. The slave receives 16 data and calculates the checksum of the received data, and compares it with the checksum sent by the host. If the checksum is the same, it sends 00H to the host; otherwise, it sends FFH to the host and receives it again. After receiving 16 correct data, the slave sends it to a digital tube for display.
2. Hardware Design
1.51 MCU serial communication function
The information exchange between a computer and the outside world is called communication. There are two common communication methods: parallel communication and serial communication. The 51 single-chip microcomputer uses four interfaces to input and output data with the outside world, which is parallel communication. The characteristics of parallel communication are fast signal transmission speed, but more signal lines are used, the cost is high, and the transmission distance is short. The characteristic of serial communication is that only two signal lines (one signal line and one ground line as a signal loop) can be used to complete the communication, which is low cost and has a long transmission distance.
The serial interface of the 51 microcontroller is a full-duplex interface. It can be used as a UART (universal asynchronous receiver and transmitter) or as a synchronous shift register. The structure of the 51 microcontroller serial interface is as follows:
(1) Data buffer (SBUF)
The data received or sent must first be sent to the SBUF buffer. There are two, one for buffering and the other for receiving, using the same direct address 99H. When sending, use the instruction to send the data to SBUF to start sending; when receiving, use the instruction to take the received data out of SBUF.
(2) Serial control register (PCON)
SCON is used for serial communication mode selection, receiving and sending control and status indication. The meanings of each bit are as follows:
SM0, SM1: Serial interface working mode selection bits, these two bits are combined into 00, 01, 10, 11 corresponding to working modes 0, 1, 2, 3. The characteristics of the serial interface working mode are shown in the table below
SM2: Multi-machine communication control bit.
REN: Receive enable control bit. Software sets it to 1 to enable reception; software sets it to 0 to disable reception.
TB8: In mode 2 or 3, TB8 is the 9th bit of data to be sent and is set to 1 or cleared to 0 by software as needed.
RB9: In mode 2 or 3, the 9th data bit received by RB8 is actually the 9th data bit TB8 sent by the host. The slave device uses this bit to determine whether the data sent by the host is a call address or data to be transmitted.
TI: Transmit interrupt flag. It is automatically set by hardware after a frame of data is sent, and an interrupt is requested. It must be cleared by software before it can continue to be sent.
RI: Receive interrupt flag. It is automatically set by hardware after receiving a frame of data and requests an interrupt. It must be cleared by software before continuing to receive.
(3) Input shift register
The received data first enters the input shift register serially, and after all 8 bits of data are shifted in, they are sent in parallel to the receive SBUF.
(4) Baud rate generator
The baud rate generator is used to control the data transmission rate of serial communication. The 51 series microcontroller uses timer T1 as the baud rate generator, and T1 is set in timing mode. The baud rate is a physical quantity used to indicate the speed of serial communication data transmission, which is defined as the number of data bits transmitted per second.
(5) Power control register PCON
The highest bit is SMOD.
(6) Baud rate calculation
When timer T1 works in timing mode, the overflow rate of timer T1 = (T1 count rate) / (machine cycles required to generate overflow). Because it is in timing mode, T1 count rate = fORC/12. The number of machine cycles required to generate overflow = modulo M-count initial value X.
2.MAX232 chip
When communicating with the 8051 serial interface, if the distance between two 8051 microcontrollers is very close (no more than 1.5m), you can directly connect the serial interfaces of the two 8051 microcontrollers and use their own TTL level (0-5V) to directly transmit data information. If the transmission distance is far (more than 1.5m), due to the impedance and distributed capacitance of the transmission line, level loss and waveform distortion will occur, so that the data cannot be detected or the data is wrong. At this time, the RS232 standard bus interface can be used to convert the TTL level output by the microcontroller into the RS232 standard level (logic 1 is -15--5V; logic 0 is +5--+15V). RS232 can increase the transmission distance to 15m. If you want to transmit over long distances, you can use RS422 or RS485.
The level conversion chip MAX232 is produced by MAXIM and is specially used for converting TTL level to RS232 level. MAX232 has an internal pump power supply that can increase the +5V power supply voltage inside the chip to the +10V or -10V level required by RS232 level.
Figure 2. Level conversion chip MAX232
3. Overall circuit design
The final design circuit is shown in Figure 3. The data of the sender is output from the TXD segment of the serial port. The level conversion chip MAX232 converts the TTL level to the RS232 level output, and transmits the signal to the receiving end through the transmission line. The receiver also uses the MAX232 chip to convert the level, and the signal reaches the receiving end of the serial port of the receiver. After the receiver receives it, it displays the received information on the digital tube through the P1 port.
Figure 3. Serial communication circuit
3. Software Design
The communication protocol is used for transmission and reception. The host first sends AAH to the slave. When the slave receives AAH, it replies BBH to the host. After receiving BBH, the host sends 10 data in the digital table TAB[16] to the slave and sends a checksum. The slave receives 16 data and calculates the checksum of the received data, and compares it with the checksum sent by the host. If the checksum is the same, it sends 00H to the host; otherwise, it sends FFH to the host and receives it again. After receiving 16 correct data, the slave sends it to a digital tube for display.
1. Serial communication software implementation
(1) The serial port operates in mode 1. Use timer 1 to generate a baud rate of 9600 bit/s and operate in mode 2.
(2) Function: Send the 16 numbers in the digital table TAB[16] in the local ROM to the slave and save them in the slave's internal ROM. After receiving these 16 data, the slave sends them to a digital tube for cyclic display.
(3) Communication protocol: The host first sends an acknowledgment signal (AAH), and after receiving it, the slave returns a acknowledgment signal (BBH) to indicate that the slave is ready to receive.
(4) The communication process uses the ninth bit to send the parity bit.
(5) After receiving a data, the slave immediately performs a parity check. If there is no error in the data, it returns 00H, otherwise it returns FFH.
(6) After the host sends a data, it waits for the slave to return data; if it is 00H, it continues to send the next data; if it is FFH, it resends the data.
2. Program flow chart
(1) Sending end program flow chart
(2) Receiver program flow chart
4. Joint debugging
Conduct simulation experiments on protues. First, use KeilC to compile the written program to generate a HEX file, burn the HEX file into two MCUs, and conduct simulation experiments. The results are shown in the figure below. It can be seen that the receiving end has completely displayed the received data.
Figure 4. Simulation diagram
5. Design Summary
After a busy and intense course design, I finally successfully completed the design task. Although every day was so busy during this period, I gained a lot in this busy process.
Through course design, in the process of consulting materials, I learned C language programming based on single-chip microcomputers and understood the basic knowledge of single-chip microcomputer serial communication, which will be of great benefit for future study and work.
During the learning process, I also encountered some difficulties. For example, at the beginning, the data could not be transmitted correctly because the communication protocol between the sender and the receiver was not done well. In the process of solving the problem, I gained a deep understanding of the implementation of the communication protocol.
Through this course design, I have exercised my ability to think independently.
1. Host sends program
#include #define uchar unsigned char // Macro definition of unsigned character type variable void init(); //Define initialization function void send(); //Define the sending function
Previous article:Design of 51 single chip ultrasonic water level controller
Next article:AT89C51 single-chip microcomputer water lamp C language program and detailed explanation (literacy tutorial)
Recommended ReadingLatest update time:2024-11-24 18:16
Recommended posts
- Single lead handheld ECG
- ProductIntroduction Thesingle-leadhandheldECGisaportable,handheldECGmonitoringdevice.ThroughECGwaveformdataacquisitiontechnologyandWIFItransmissiontechnology,theECGsignalistransmittedtothecloudplatformormobileph
- wuzfeng Medical Electronics
- AD20 Select PCB Components cannot be used?
- Afterselectingtheschematic,usingSelectPCBComponentsdoesnotjumptothePCBdiagramtoselectit.Thetwofilesarealsointhesamefolder.Whatistheproblem? Generally,whenyouswitchtoschematicmode,itwillbeavailableinthetoo
- Memory01 PCB Design
- The impact of common mode noise on EMI
- MostconductedEMIproblemsarecausedbycommon-modenoise.And,mostcommon-modenoiseproblemsarecausedbyparasiticcapacitanceinthepowersupply.ForPart1ofthisdiscussiontopic,wefocusonwhathappenswhenparasiticcapacitancei
- Aguilera Analogue and Mixed Signal
- 【XMC4800 Relax EtherCAT Kit Review】+ Hardware Interpretation
- MainhardwareofthemaincontrolboardTheoverallblockdiagramofthemaincontrolboardisasfollows1,ThemaincontrolchipusesXMC4800F144K2048,LQFP144package.ItcanbereplacedwithXMC4700.Thisfullcompatibilityisp
- anger0925 Industrial Control Electronics
- Can the differential pairs be wound with equal lengths like this?
- Canthedifferentialpairsbewoundwithequallengthslikethis? Theoretically,itisnotpossible,becausetheimpedancewillbediscontinuous.Butfromapracticalpointofview,itdependsonhowfastyoursignalis.Itdoesn'tmatterifthes
- asionl PCB Design
- [November 22 | Shanghai] You are invited to attend the High-Speed Interconnect Innovation Technology Seminar!
- Meetingtime:13:30-17:30,November22,2024 Meetingplace:ShanghaiBoyaHotel,BiboHallABonthefirstfloor Aboutthisactivity AsthescaleofAImodelscontinuestogrow,thenumberofinterconnect
- eric_wang Integrated technical exchanges
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- A strange problem, the result of comparing the size of a signed 32-bit number with an unsigned 32-bit number is wrong
- IC Operational Amplifier
- Analog Circuit Basics Tutorial
- Now even transformers are starting to go crazy
- How to develop with the MSP432P401R LaunchPad?
- High-Speed Serial I/O Made Easy (FPGA Application Designer's Guide)
- Developing videophone using ARM processor solution
- Development of intelligent telephone alarm
- DSP development based on dual-core chip of CCS
- How to distinguish between constant current charging and constant voltage charging circuits