The 51 microcontroller has a full-duplex serial communication port, so serial communication can be easily performed between the microcontroller and the computer. Certain conditions must be met when performing serial communication. For example, the serial port of the computer is RS232 level, while the serial port of the microcontroller is TTL level. There must be a level conversion circuit between the two. We use a dedicated chip MAX232 for conversion. Although several transistors can also be used for analog conversion, it is still simpler and more reliable to use a dedicated chip. We use a three-wire connection serial port, that is, only three of the wires are connected to the 9-pin serial port of the computer: GND on the 5th pin, RXD on the 2nd pin, and TXD on the 3rd pin. This is the simplest connection method, but it is enough for us. The circuit is shown in the figure below. The 10th pin of MAX232 is connected to the 11th pin of the microcontroller, the 9th pin is connected to the 10th pin of the microcontroller, and the 15th pin is connected to the 20th pin of the microcontroller.
The hardware circuit of serial communication is shown in the figure above.
Before making the circuit, let's take a look at the MAX232 to be used. We will not discuss it in detail here. Just know that it is a chip that converts TTL and RS232 levels and has basic pin wiring functions. Usually I will use two low-power transistors and a small amount of circuit to replace MAX232, which can save a little and the effect is also good (if you are interested, you can check the relevant information on the website http://www.cdle.net). The figure below is the basic wiring diagram of MAX232.
Just add MAX232 according to Figure 7-3. Soldering with a soldering iron in this hot day is really hot: P The serial port socket uses a DB9 female connector, so you can use the purchased PC serial port extension cable to connect to the computer, or you can directly connect it to the computer com port.
In order to see the data sent by the microcontroller on the computer, we must use a WINDOWS software to observe it. Here we use a free computer serial port debugging software. [page]
Click here to download and run the serial port debugging software. This is a green software. You don't need to install it. You can run it directly at the current location. The software interface is as shown above. We must first set the parameters of the serial port communication, adjust the baud rate to 4800, and check the hexadecimal display. Select COM1 as the serial port. Of course, the serial port of the 51 single-chip microcomputer experiment board provided by the website should also be connected to the COM1 of the computer. Insert the single-chip microcomputer with the following program burned into the universal socket of the single-chip microcomputer experiment board, and turn on the power of the 51 single-chip microcomputer experiment board.
The source program of the serial port experiment is as follows:
;This is a demonstration program for the S51 single-chip microcomputer experimental development board to send data AF to the serial port of the PC in one direction
;The MAX232 dedicated chip is used for RS232/TTL level conversion.
;The communication baud rate is 4800KBPS. As long as K1 is pressed once (that is, the P3.6 pin becomes a low level)
, a hexadecimal AF character will be sent
ORG 0000H
MOV SCON,#50H;Set to serial port 1 mode
MOV TMOD,#20H;Baud rate generator T1 works in mode 2
MOV PCON,#80H;The baud rate is doubled to 2400x2=4800BPS
MOV TH1,#0F3H;Preset initial value (preset initial value according to the baud rate 2400BPS)
MOV TL1,#0F3H;Preset initial value (preset initial value according to the baud rate 2400BPS)
SETB TR1;Start timer T1
;The above completes the communication initialization setting
WRIT:JB P3.6,$;Judge whether K1 is pressed, if not, wait
ACALL DELAY10;Delay 10 milliseconds to eliminate contact jitter
JB P3.6,WRIT;Remove interference signal
JNB P3.6,$;Wait for the button to be released
MOV A,#0AFH;Send the hexadecimal character AF to the serial port
MOV SBUF,A;Send AF through the serial port
AJMP WRIT
;10 millisecond delay subroutine
DELAY10:MOV R4,#20
D2:MOV R5,#248
DJNZ R5,$
DJNZ R4,D2
RET
END
;=============Two-machine serial port communication program (host)====================
;
; Function: Use serial interrupt to receive data and display
; Hardware environment: Homemade single-chip microcomputer experiment board
; Software environment: Weifu V3.20
; Create date: 2004_07_26
; First Modify: 2004_07_26
; second Modify:
; Last Modify: 2004_07_26
; Author: Sujiande
;
;===========Predefined=====================
LED0 EQU 40H ;Predefined digital tube
LED1 EQU 41H ;Predefined digital tube
LED2 EQU 42H ;Predefined digital tube
LED3 EQU 43H ;Predefined digital tube
LED4 EQU 44H ;Predefined digital tube
LED5 EQU 45H ;Predefined digital tube
LED6 EQU 46H ;Predefined digital tube
LED7 EQU 47H ;Predefined digital tube
SDA BIT P0.1 ; Define data line pin definition
SCL BIT P0.0 ; Define the clock line pin definition
;---------------------------
ORG 0000H ; Main program entry
AJMP MAIN ; Jump to the main program
ORG 0100H ; Main program storage location in ROM
;================Main program======================
MAIN:
MOV LED0,#00H ; Assign initial value
MOV LED1,#00H
MOV LED2,#16 ; Assign initial value to 16, the digital tube display code is: off
MOV LED3,#16
MOV LED4,#16
MOV LED5,#16
MOV LED6,#16
MOV LED7,#16
;--------------------
;MOV DPTR,#TABLE ; Assign the display code first address
MOV R1,#00H ; Assign initial value 00H to R1
ACALL DISPLAY ; Call display subroutine
MOV SP, #30H ; Assign initial value to stack pointer
;--------------------------
; Use timer 1 as baud rate generator, set baud rate = 9600,
; Timer initial value: FAH
; Serial controller settings: SM0=0, SM1=1, SM2=0, REN=1, TB8=0,
; RB8=0, TI=0, RI=0 i.e. 0101 0000B
; Double the baud rate
;-----------------------------
MOV TMOD, #20H ; Set timer 1, working mode 2
MOV TH1, #0FAh ; Assign initial value: FA
MOV TL1, #0FAh ; Assign initial value: FA
MOV SCON, #50h ; Set serial port control register
MOV PCON, #80h ; Set power control register, double the baud rate (2X)
SETB TR1 ;Start timing
;*****************Main program ends************************
LP8: MOV A,R1 ;Load the data of R1 into A
;-----------------------
MOV SBUF,A ;Send the data of A to the buffer
JNB TI,$ ;Wait for the data to be sent
CLR TI ;Clear the send interrupt flag
;-----------------------
INC R1
CJNE R1,#99,LP3
MOV R1,#00H
LP3: ACALL SEPERATE ;Call split program
ACALL DISPLAY ;Call display subroutine
ACALL DELAY_1S ;Call delay subroutine
AJMP LP8
;=================Split program====================
SEPERATE: ANL A,#0Fh ;AND operation to get the unit digit data
MOV LED0,A ;Send the unit digit to LED0
MOV A,R1
ANL A,#0F0H ;AND operation to get the ten-digit dataSWAP
A
MOV LED1,A ;Send the ten-digit to LED1
RET
;================Display subroutine======================
DISPLAY:
MOV DPTR,#TABLE ; Assign the first address of the display code
MOV A,LED0 ;Send the table lookup data to A
MOVC A,@A+DPTR ;Look up the table and get the display codeACALL
SHIFT ;Call the shift subroutine
MOV A,LED1
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED2
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED3
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED4
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED5
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED6
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED7
MOVC A,@A+DPTR
ACALL SHIFT
RET[page]
;---------Display code table---------
TABLE: DB 11H,0D7H,32H,92H,0D4H,98H,18H,0D3H,10H,90H ;0,1,2,3,4,5,6,7,8,9,
DB 50H,1CH,39H,16H,38H,78H, 0FFH,0FEH,0EFH ;10,11,12,13,14,15,extinguish,-
;===============Shift subroutine============================
SHIFT: PUSH A ; Push the value of A into the stack
MOV R0,#8 ; Loop 8 times
CLR C ; Clear carry flag
CLR SCL ; Clock line, clamp to 0 first
LP2: RLC A
MOV SDA,C
NOP
NOP
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
DJNZ R0,LP2
POP A ; Pop the stack to restore the value of A
RET
;=============Delay subroutine===============
DELAY_1S:
MOV R7,#0ffH
LOOP7: MOV R6,#0ffH
LOOP6: NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R6,LOOP6
DJNZ R7,LOOP7
RET
;------------------------------
END
;==============Two-machine serial port communication program (slave)=====================
;
; Function: Use serial interrupt to receive data and display it
; Hardware environment: Homemade MCU experiment board
; Software environment: WeiFu V3.20
; Create date: 2004_07_26
; First Modify: 2004_07_26
; second Modify:
; Last Modify: 2004_07_26
; Author: Sujiande
;
;===========Predefined===================
LED0 EQU 40H ;Predefine digital tube
LED1 EQU 41H ;Predefine digital tube
LED2 EQU 42H ;Predefine digital tube
LED3 EQU 43H ;Predefine digital tube LED4
EQU 44H ;Predefine digital tube
LED5 EQU 45H ;Predefine digital tube
LED6 EQU 46H ;Predefine digital tube
LED7 EQU 47H ;Predefine digital tube
SDA BIT P0.1 ;Define data line pin definition
SCL BIT P0.0 ;Define clock line pin definition
;---------------------------
ORG 0000H ;Main program entry
AJMP MAIN ;Jump to main program
ORG 0023H ;Interrupt entry address
AJMP S_INT ;Jump to interrupt program
ORG 0100H ;The storage location of the main program in ROM
;==============Main program========================
MAIN:
MOV LED0,#00H ;Assign initial value
MOV LED1,#00H
MOV LED2,#16 ;Assign initial value to 16, the digital tube display code is: off
MOV LED3,#16
MOV LED4,#16
MOV LED5,#16
MOV LED6,#16
MOV LED7,#16
;------------------------------
MOV DPTR,#TABLE ; Assign the display code first address
ACALL DISPLAY ; Call the display subroutine
MOV SP, #30H ; Assign initial value to the stack pointer
;--------------------------------------------
; Use timer 1 as the baud rate generator, set the baud rate = 9600,
; The initial value of the timer is: FAH
; Serial controller settings: SM0=0, SM1=1, SM2=0, REN=1, TB8=0,
; RB8=0, TI=0, RI=0 i.e. 0101 0000B
; Double the baud rate
;---------------------------------------------
MOV TMOD,#20H ; Set timer 1, working mode 2
MOV TH1,#0FAh ; Assign initial value: FA
MOV TL1,#0FAh ; Assign initial value: FA MOV
SCON, #50h ; Set serial port control register
MOV PCON, #80h ; Set power control register, double the baud rate (2X)
;---------------------------------------
SETB EA ; Start general interrupt
SETB ES ; Start serial interrupt
SETB TR1 ; Start timing
AJMP $ ; Wait for interrupt
;********************Main program ends****************************
;===============Interrupt service program===========================
S_INT:
MOV R1, SBUF ;Send the data in the buffer to R1
ACALL SEPERATE ;Call the splitting program
ACALL DISPLAY ;Call the display subroutine
CLR RI ;Clear the receive interrupt flag
RETI ;Interrupt return
;=================Split program====================
SEPERATE: MOV A,R1
ANL A,#0Fh ;AND operation to get the ones digit dataMOV
LED0,A ;Send the ones digit to LED0
MOV A,R1
ANL A,#0F0H ;AND operation to get the tens digit dataSWAP
A ;
MOV LED1,A ;Send the tens digit to LED1
RET
;===============Display subroutine=====================
DISPLAY:
MOV A,LED0 ;Send table data to A
MOVC A,@A+DPTR ;Look up the table and get the display code
ACALL SHIFT ;Call the shift subroutine
MOV A,LED1
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED2
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED3
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED4
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED5
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED6
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED7
MOVC A,@A+DPTR
ACALL SHIFT
RET
;---------Show code table---------
TABLE: DB 11H,0D7H,32H,92H,0D4H,98H,18H,0D3H,10H,90H ;0,1,2,3,4,5,6,7,8,9,
DB 50H,1CH,39H,16H,38H,78H, 0FFH,0FEH,0EFH ;10,11,12,13,14,15,extinguish,-
;===============Shift subroutine============================
SHIFT: PUSH A ; Push the value of A into the stack
MOV R0,#8 ; Loop 8 times
CLR C ; Clear the carry flag
CLR SCL ; Clock line, clamp to 0 first
LP2: RLC A
MOV SDA,C
NOP
NOP
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
DJNZ R0,LP2
POP A ; Pop the stack to restore A value
RET
;=============Delay subroutine==============
DELAY_1S:
MOV R7,#0ffH
LOOP7: MOV R6,#0ffH
LOOP6: NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R6,LOOP6
DJNZ R7,LOOP7
RET
;------------------------------
END
Keywords:MCU
Reference address:Serial communication test between single chip microcomputer and PC
The hardware circuit of serial communication is shown in the figure above.
Before making the circuit, let's take a look at the MAX232 to be used. We will not discuss it in detail here. Just know that it is a chip that converts TTL and RS232 levels and has basic pin wiring functions. Usually I will use two low-power transistors and a small amount of circuit to replace MAX232, which can save a little and the effect is also good (if you are interested, you can check the relevant information on the website http://www.cdle.net). The figure below is the basic wiring diagram of MAX232.
Just add MAX232 according to Figure 7-3. Soldering with a soldering iron in this hot day is really hot: P The serial port socket uses a DB9 female connector, so you can use the purchased PC serial port extension cable to connect to the computer, or you can directly connect it to the computer com port.
In order to see the data sent by the microcontroller on the computer, we must use a WINDOWS software to observe it. Here we use a free computer serial port debugging software. [page]
Click here to download and run the serial port debugging software. This is a green software. You don't need to install it. You can run it directly at the current location. The software interface is as shown above. We must first set the parameters of the serial port communication, adjust the baud rate to 4800, and check the hexadecimal display. Select COM1 as the serial port. Of course, the serial port of the 51 single-chip microcomputer experiment board provided by the website should also be connected to the COM1 of the computer. Insert the single-chip microcomputer with the following program burned into the universal socket of the single-chip microcomputer experiment board, and turn on the power of the 51 single-chip microcomputer experiment board.
The source program of the serial port experiment is as follows:
;This is a demonstration program for the S51 single-chip microcomputer experimental development board to send data AF to the serial port of the PC in one direction
;The MAX232 dedicated chip is used for RS232/TTL level conversion.
;The communication baud rate is 4800KBPS. As long as K1 is pressed once (that is, the P3.6 pin becomes a low level)
, a hexadecimal AF character will be sent
ORG 0000H
MOV SCON,#50H;Set to serial port 1 mode
MOV TMOD,#20H;Baud rate generator T1 works in mode 2
MOV PCON,#80H;The baud rate is doubled to 2400x2=4800BPS
MOV TH1,#0F3H;Preset initial value (preset initial value according to the baud rate 2400BPS)
MOV TL1,#0F3H;Preset initial value (preset initial value according to the baud rate 2400BPS)
SETB TR1;Start timer T1
;The above completes the communication initialization setting
WRIT:JB P3.6,$;Judge whether K1 is pressed, if not, wait
ACALL DELAY10;Delay 10 milliseconds to eliminate contact jitter
JB P3.6,WRIT;Remove interference signal
JNB P3.6,$;Wait for the button to be released
MOV A,#0AFH;Send the hexadecimal character AF to the serial port
MOV SBUF,A;Send AF through the serial port
AJMP WRIT
;10 millisecond delay subroutine
DELAY10:MOV R4,#20
D2:MOV R5,#248
DJNZ R5,$
DJNZ R4,D2
RET
END
;=============Two-machine serial port communication program (host)====================
;
; Function: Use serial interrupt to receive data and display
; Hardware environment: Homemade single-chip microcomputer experiment board
; Software environment: Weifu V3.20
; Create date: 2004_07_26
; First Modify: 2004_07_26
; second Modify:
; Last Modify: 2004_07_26
; Author: Sujiande
;
;===========Predefined=====================
LED0 EQU 40H ;Predefined digital tube
LED1 EQU 41H ;Predefined digital tube
LED2 EQU 42H ;Predefined digital tube
LED3 EQU 43H ;Predefined digital tube
LED4 EQU 44H ;Predefined digital tube
LED5 EQU 45H ;Predefined digital tube
LED6 EQU 46H ;Predefined digital tube
LED7 EQU 47H ;Predefined digital tube
SDA BIT P0.1 ; Define data line pin definition
SCL BIT P0.0 ; Define the clock line pin definition
;---------------------------
ORG 0000H ; Main program entry
AJMP MAIN ; Jump to the main program
ORG 0100H ; Main program storage location in ROM
;================Main program======================
MAIN:
MOV LED0,#00H ; Assign initial value
MOV LED1,#00H
MOV LED2,#16 ; Assign initial value to 16, the digital tube display code is: off
MOV LED3,#16
MOV LED4,#16
MOV LED5,#16
MOV LED6,#16
MOV LED7,#16
;--------------------
;MOV DPTR,#TABLE ; Assign the display code first address
MOV R1,#00H ; Assign initial value 00H to R1
ACALL DISPLAY ; Call display subroutine
MOV SP, #30H ; Assign initial value to stack pointer
;--------------------------
; Use timer 1 as baud rate generator, set baud rate = 9600,
; Timer initial value: FAH
; Serial controller settings: SM0=0, SM1=1, SM2=0, REN=1, TB8=0,
; RB8=0, TI=0, RI=0 i.e. 0101 0000B
; Double the baud rate
;-----------------------------
MOV TMOD, #20H ; Set timer 1, working mode 2
MOV TH1, #0FAh ; Assign initial value: FA
MOV TL1, #0FAh ; Assign initial value: FA
MOV SCON, #50h ; Set serial port control register
MOV PCON, #80h ; Set power control register, double the baud rate (2X)
SETB TR1 ;Start timing
;*****************Main program ends************************
LP8: MOV A,R1 ;Load the data of R1 into A
;-----------------------
MOV SBUF,A ;Send the data of A to the buffer
JNB TI,$ ;Wait for the data to be sent
CLR TI ;Clear the send interrupt flag
;-----------------------
INC R1
CJNE R1,#99,LP3
MOV R1,#00H
LP3: ACALL SEPERATE ;Call split program
ACALL DISPLAY ;Call display subroutine
ACALL DELAY_1S ;Call delay subroutine
AJMP LP8
;=================Split program====================
SEPERATE: ANL A,#0Fh ;AND operation to get the unit digit data
MOV LED0,A ;Send the unit digit to LED0
MOV A,R1
ANL A,#0F0H ;AND operation to get the ten-digit dataSWAP
A
MOV LED1,A ;Send the ten-digit to LED1
RET
;================Display subroutine======================
DISPLAY:
MOV DPTR,#TABLE ; Assign the first address of the display code
MOV A,LED0 ;Send the table lookup data to A
MOVC A,@A+DPTR ;Look up the table and get the display codeACALL
SHIFT ;Call the shift subroutine
MOV A,LED1
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED2
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED3
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED4
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED5
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED6
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED7
MOVC A,@A+DPTR
ACALL SHIFT
RET[page]
;---------Display code table---------
TABLE: DB 11H,0D7H,32H,92H,0D4H,98H,18H,0D3H,10H,90H ;0,1,2,3,4,5,6,7,8,9,
DB 50H,1CH,39H,16H,38H,78H, 0FFH,0FEH,0EFH ;10,11,12,13,14,15,extinguish,-
;===============Shift subroutine============================
SHIFT: PUSH A ; Push the value of A into the stack
MOV R0,#8 ; Loop 8 times
CLR C ; Clear carry flag
CLR SCL ; Clock line, clamp to 0 first
LP2: RLC A
MOV SDA,C
NOP
NOP
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
DJNZ R0,LP2
POP A ; Pop the stack to restore the value of A
RET
;=============Delay subroutine===============
DELAY_1S:
MOV R7,#0ffH
LOOP7: MOV R6,#0ffH
LOOP6: NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R6,LOOP6
DJNZ R7,LOOP7
RET
;------------------------------
END
;==============Two-machine serial port communication program (slave)=====================
;
; Function: Use serial interrupt to receive data and display it
; Hardware environment: Homemade MCU experiment board
; Software environment: WeiFu V3.20
; Create date: 2004_07_26
; First Modify: 2004_07_26
; second Modify:
; Last Modify: 2004_07_26
; Author: Sujiande
;
;===========Predefined===================
LED0 EQU 40H ;Predefine digital tube
LED1 EQU 41H ;Predefine digital tube
LED2 EQU 42H ;Predefine digital tube
LED3 EQU 43H ;Predefine digital tube LED4
EQU 44H ;Predefine digital tube
LED5 EQU 45H ;Predefine digital tube
LED6 EQU 46H ;Predefine digital tube
LED7 EQU 47H ;Predefine digital tube
SDA BIT P0.1 ;Define data line pin definition
SCL BIT P0.0 ;Define clock line pin definition
;---------------------------
ORG 0000H ;Main program entry
AJMP MAIN ;Jump to main program
ORG 0023H ;Interrupt entry address
AJMP S_INT ;Jump to interrupt program
ORG 0100H ;The storage location of the main program in ROM
;==============Main program========================
MAIN:
MOV LED0,#00H ;Assign initial value
MOV LED1,#00H
MOV LED2,#16 ;Assign initial value to 16, the digital tube display code is: off
MOV LED3,#16
MOV LED4,#16
MOV LED5,#16
MOV LED6,#16
MOV LED7,#16
;------------------------------
MOV DPTR,#TABLE ; Assign the display code first address
ACALL DISPLAY ; Call the display subroutine
MOV SP, #30H ; Assign initial value to the stack pointer
;--------------------------------------------
; Use timer 1 as the baud rate generator, set the baud rate = 9600,
; The initial value of the timer is: FAH
; Serial controller settings: SM0=0, SM1=1, SM2=0, REN=1, TB8=0,
; RB8=0, TI=0, RI=0 i.e. 0101 0000B
; Double the baud rate
;---------------------------------------------
MOV TMOD,#20H ; Set timer 1, working mode 2
MOV TH1,#0FAh ; Assign initial value: FA
MOV TL1,#0FAh ; Assign initial value: FA MOV
SCON, #50h ; Set serial port control register
MOV PCON, #80h ; Set power control register, double the baud rate (2X)
;---------------------------------------
SETB EA ; Start general interrupt
SETB ES ; Start serial interrupt
SETB TR1 ; Start timing
AJMP $ ; Wait for interrupt
;********************Main program ends****************************
;===============Interrupt service program===========================
S_INT:
MOV R1, SBUF ;Send the data in the buffer to R1
ACALL SEPERATE ;Call the splitting program
ACALL DISPLAY ;Call the display subroutine
CLR RI ;Clear the receive interrupt flag
RETI ;Interrupt return
;=================Split program====================
SEPERATE: MOV A,R1
ANL A,#0Fh ;AND operation to get the ones digit dataMOV
LED0,A ;Send the ones digit to LED0
MOV A,R1
ANL A,#0F0H ;AND operation to get the tens digit dataSWAP
A ;
MOV LED1,A ;Send the tens digit to LED1
RET
;===============Display subroutine=====================
DISPLAY:
MOV A,LED0 ;Send table data to A
MOVC A,@A+DPTR ;Look up the table and get the display code
ACALL SHIFT ;Call the shift subroutine
MOV A,LED1
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED2
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED3
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED4
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED5
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED6
MOVC A,@A+DPTR
ACALL SHIFT
MOV A,LED7
MOVC A,@A+DPTR
ACALL SHIFT
RET
;---------Show code table---------
TABLE: DB 11H,0D7H,32H,92H,0D4H,98H,18H,0D3H,10H,90H ;0,1,2,3,4,5,6,7,8,9,
DB 50H,1CH,39H,16H,38H,78H, 0FFH,0FEH,0EFH ;10,11,12,13,14,15,extinguish,-
;===============Shift subroutine============================
SHIFT: PUSH A ; Push the value of A into the stack
MOV R0,#8 ; Loop 8 times
CLR C ; Clear the carry flag
CLR SCL ; Clock line, clamp to 0 first
LP2: RLC A
MOV SDA,C
NOP
NOP
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
DJNZ R0,LP2
POP A ; Pop the stack to restore A value
RET
;=============Delay subroutine==============
DELAY_1S:
MOV R7,#0ffH
LOOP7: MOV R6,#0ffH
LOOP6: NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R6,LOOP6
DJNZ R7,LOOP7
RET
;------------------------------
END
Previous article:How to make Keil software compatible with both 51 MCU and ARM MCU
Next article:Design of a three-bus conversion device based on AT89C51
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Guess you like
- I have some doubts about SensorTile.box
- A novice needs help. When drawing PCB manual wiring in AD13.4, why can't I see the trace of the wiring before the wiring is completed?
- What are the important techniques for PCB wiring?
- Naming of Cadence Allegro 17.2 built-in pads
- A precision rectification experiment
- Video: Talking about TI CC2650
- How stable is RT-Thread?
- How to improve the hardware and software architecture of embedded minimum systems?
- Among domestic chips, which ones are suitable for smart homes?
- STM32CubeMX is driving me crazy, experts please help!