//This is my x_Ed program code
//we use it as the pc communicated with the mcu
//At the same time,we want to see the result by LCD;
STFLAG BIT 00H //Received start code flag, 1 for received start code
EDFLAG BIT 01H //Arrived end code flag, 1 for received end code
TMFLAG BIT 02H //Timing time arrived flag, 1 for timing time arrived
ORG 0000H
SJMP Initialize//Main program entry (initialization program)
ORG 000BH //Timer 0 entry
LJMP TIMER0 //Timer 0 interrupt
ORG 0023H //Entry address of serial port interrupt program
LJMP Transfer //Jump to accept interrupt entry
////////////////////////////////////////////////////////////////////
ORG 0050H
Initialize:
MOV SP,#70H //Set stack
MOV TMOD,#21H //T1 working mode 2 T0 working
MOV TH1,#0FDH //Baud rate 9600
MOV TL1,#0FDH //Baud rate 9600 automatic reload
MOV TH0,#3CH //Timing 50ms
MOV TL0,#0BH //Timing 50ms
MOV SCON,#50H //Serial port working mode 1
MOV R6,#00H //Timing times counter 20 one second
MOV R5,#00H //Received data length counter
MOV R4,#00H //Control output control register
MOV R0,#30H //Data storage address
MOV R1,#30H //Control output data cache
CLR STFLAG //Clear start flag
CLR EDFLAG //Clear end flag
CLR TMFLAG //Clear clock flag
SETB PS //Increase the priority of serial port interrupt
SETB TR1 //Turn on timer 1;
SETB ES //Turn on serial port interrupt enable bit
SETB ET0 //Timer 0 interrupt enable bit
SETB EA //Turn on global interrupt enable bit
//////////////////Wait for receiving command ////////////////////////
Main: JB STFLAG,NODE3 //Start bit has been received
SJMP Main //Not started, continue waiting
NODE3: JB EDFLAG,NODE4 //End bit has been received
SJMP Main //Not ended, continue waiting
NODE4: SETB TR0 //Turn on timer 0;
NODE5: JB TMFLAG,OUTPUT
SJMP NODE5
////////////////////Wait for host computer to transmit data and record it ////////
Transfer: CLR ES
MOV A,SBUF
CJNE A,#0A5H,NODE0 //Start bit detected
SETB STFLAG
SJMP JIEDIAN
NODE0: CJNE A,#05AH,NODE1 //Detect the end bit
SETB EDFLAG
MOV DPH,R5
MOV R4,DPH
clr ES //Open the serial port interrupt enable bit
SJMP ret00
NODE1: MOV @R0,A //Neither the start code nor the end code, it is data
INC R0
INC R5
MOV SBUF,#055H
JIEDIAN: CLR TI
CLR RI
SETB ES
ret00: RETI
TIMER0: CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
INC R6
CJNE R6,#20,RTN
SETB TMFLAG
MOV R6,#00H
RTN: SETB TR0
RETI
OUTPUT: CLR TR0
clr TMFLAG
MOV A,@R1
MOV P1,A
INC R1
DJNZ R4,NODE4
MOV R1,#30H
CLR TMFLAG
MOV DPH,R5
MOV R4,DPH
SJMP NODE4
RETI
END
Previous article:MCU Assembly Experiment 7: Scanning Keyboard and LCD Display Experiment
Next article:51 MCU clock assembly program
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
- [Electronic Basics] How to connect the ground wire to the earth? Do you understand these 3 key points?
- DSP has a problem with printf function running away in CCS environment
- USB transformation of ESP32-S2-Saola-1
- Is there any delay when directly connecting FPGA I/O pins?
- Eat mushrooms and see villains! It's the time of the year again when Yunnan people poison themselves
- Getting Started with Modelsim
- Crosstalk Elimination Technology in Altium Designer
- Evaluation Weekly Report 20220207: How many days are left to apply for Qinheng ch582 and Pingtouge Linux RISC-V kit
- About Modbus slave response packet address
- ESD resistance of capacitors