MCU serial port programming problem

Publisher:HeavenlyCloudsLatest update time:2012-06-26 Source: 61icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I am working on dual-machine communication, but I have encountered a problem. The problem is this:
this works
while(TI==0);
TI=0;
……
……

This does not work. I cannot detect TI=1 using the following method. Why?
for(i=0;(i<10)&&(TI==0);i++);
TI=0;
if(i<10)
// Correct processing
else
// Error processing

There is no need to use the second method
It takes a certain amount of time for the serial port to send data. Assuming the baud rate is 9600bps, it takes more than 100 us per bit. If the data bit is 8 bits and the check bit is one, it takes more than one ms to send one byte of data. The error of the second method is that it is believed that sending does not take time or the time is very short. The author's original intention may be to make 10 judgments on TI. If TI is found to be 0 in all 10 judgments, that is, the sending is not completed, then it is considered that an error has occurred; otherwise, if TI is found to be 1 within 10 judgments, that is, the sending is completed, then it is considered that the sending is correct. The actual situation is that the time to execute 10 loops is much less than the time required for sending. Therefore, the loop has exited before the sending is completed, and a judgment of sending error is made. The correct handling is to add a delay program before the loop, and the delay time should be greater than the minimum time required for sending. I personally think that there is no need to use the second method. For the 51 single-chip microcomputer serial port, there are only the cases of sending completion and non-completion, and there is no concept of right and wrong. If the sending error is said, that is, after executing the sending instruction, the internal hardware circuit of 51 cannot correctly send the data or cannot set TI to 1, it means that the CPU is broken or the crystal oscillator has a problem. The so-called right and wrong should refer to whether the data received by the receiver is correct or wrong.
Keywords:MCU Reference address:MCU serial port programming problem

Previous article:A cheap single-chip AC power line interface solution
Next article:Powerful clock interrupt

Recommended ReadingLatest update time:2024-11-16 15:26

Design of PIC microcontroller in DC motor stepless speed regulation system
In modern industrial production, the motor is the main driving device. At present, the KZ-D drive system that uses thyristor (i.e., silicon controlled rectifier) ​​devices to power the motor has been widely used in DC motor drive systems, replacing the bulky F-D system of generator-motor. With the high development of
[Microcontroller]
Design of PIC microcontroller in DC motor stepless speed regulation system
Application of C8051F920 single chip microcomputer in the design of metal halide lamp controller
1. Introduction At present, most lighting equipment still uses traditional energy for lighting. Making full use of solar energy as the energy supply for lighting equipment is of great significance in terms of saving energy and protecting the environment. 2. Overall structure of controller
[Microcontroller]
Application of C8051F920 single chip microcomputer in the design of metal halide lamp controller
8051 MCU (STC89C52) eight LED lights flashing
#include STC89C5xRC.h void delay() {     int i,j;     for(i=0;i 200;i++)           for(j=0;j =200;j++)           {                  ;           } } int main() {     while(1)     {         P2 = 0xff; //Eight lights off         delay();            P2 = 0; //Eight lights on         delay();     } }
[Microcontroller]
C language programming of single chip microcomputer controlling multiple stepper motors
//Program description: Burn the program, connect the control lines (control lines I1-I4 of stepper motor 1 are connected to P2.0-P2.3, control lines I1-I4 of stepper motor 2 are connected to // To P2.4-P2.7. Press S19 to control the rotation stop, acceleration/deceleration, and forward/reverse rotation of stepper moto
[Microcontroller]
Stratospheric verification airship combined navigation system based on DSP+MCU
  The stratospheric airspace is between the highest-flying aircraft and the lowest-orbiting satellites. In addition, it has good electromagnetic properties and very stable meteorological conditions. Therefore, people continue to try to use stratospheric airships as long-term airborne platforms for communications, grou
[Microcontroller]
Stratospheric verification airship combined navigation system based on DSP+MCU
Design of control system for power compensation device based on 80C196KC single chip microcomputer
The power compensation device implements reactive power compensation for the power grid, improves the power factor of the power grid, makes the reactive power basically balanced on the spot, reduces line loss, improves voltage quality and increases the transmission capacity of lines and transformers. At present, the
[Microcontroller]
Design of control system for power compensation device based on 80C196KC single chip microcomputer
Design of high-precision electronic balance based on MSP430 single-chip microcomputer
  introduction   With the rapid development of modern electronic technology and microcomputer technology, electronic balances have been applied to the field of balances. Since the first electronic balance appeared in the world in the late 1970s, a series of electronic balances with various specifications and complet
[Microcontroller]
Design of high-precision electronic balance based on MSP430 single-chip microcomputer
Construct a real-time operating system for 51 microcontroller
At present, most product development is carried out based on some small-capacity microcontrollers. The 51 series of microcontrollers is one of the most commonly used microcontroller series in my country. It has a very broad application environment and prospects. The accumulation of resources over the years has made the
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号