Serial port asynchronous communication microcontroller programming example

Publisher:pengbinyyyLatest update time:2017-10-14 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

org 0000H 

AJMP START 

ORG 30H 

START: 

mov SP,#5fh ; 

mov TMOD,#20h ;T1: work mode 2 

mov PCON,#80h ;SMOD=1 

mov TH1,#0FDH ;Initialize baud rate (see table) 

mov SCON,#50h ;Standard UART settings 

MOV R0,#0AAH ;Prepare to send data 

SETB REN ;Enable receiving 

SETB TR1 ;T1 starts working 

WAIT: 

MOV A,R0 

CPL A 

MOV R0,A 

MOV SBUF,A 

LCALL DELAY 

JBC TI,WAIT1 ;If TI is 1, clear TI and go to WAIT1 

AJMP WAIT 

WAIT1: JBC RI,READ ;If RI is 1, clear RI and go to READ 

AJMP WAIT1 

READ: 

MOV A,SBUF ;Send the obtained number to port P1 

MOV P1,A 

LJMP WAIT 

DELAY: ;Delay subroutine 

MOV R7,#0ffH 

DJNZ R7,$ 

RET 

END 

Compile the program, write it into the chip, insert it into the experimental board, and use the through-read cable to connect the experimental board to the serial port of the host to conduct the experiment. The function of the above program is very simple, which is to send 55H and AAH to the host in turn at regular intervals, and send the number sent by the host to port P1. You can use the serial port wizard on the PC to do experiments. The serial port wizard is available for download on my homepage. After running the serial port wizard, press the "Set Parameters" button on the main interface to enter the "Set Parameters" dialog box and set the parameters according to the following parameters. Note that my machine uses serial port 2. If you are not using serial port 2, please change the serial port settings yourself. 

Click here to view the image in a new window


After setting, press OK to return to the main interface. Note that there is a drop-down list on the right, and "According to Hexadecimal" should be selected. Then press "Start Sending" and "Start Receiving". According to this setting, two lights should be on and six lights should be off on the experimental board. You can change the sending characters in the setting parameters such as 55, 00, FF, etc., observe the lights on and off, and analyze the reasons. You can also change the "According to Hexadecimal" in the drop-down list on the main interface to "According to Decimal" or "According to ASCII Characters" to observe the phenomenon and analyze it carefully. This is also very helpful for everyone to understand hexadecimal, decimal, and ASCII characters. The program itself is very simple and has comments, so I won't explain it in detail here.


Reference address:Serial port asynchronous communication microcontroller programming example

Previous article:Serial port asynchronous communication microcontroller programming example (implemented by interrupt method)
Next article:51 MCU serial port communication program design example

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号