Microcontroller assembly language programming (online for answers)
<< < Question 1>>
Experiment purpose: preliminary understanding of the working principle of the microcontroller I / O port, to further master the assembly instructions of the 51 microcontroller.
Experiment content: programming the microcontroller I/O port with assembly instructions to control the 8 light-emitting diodes of the flow of water on and off.
Detailed program features:
Do a single light left to right, eight light-emitting diodes L0-L7 were connected to the microcontroller’s P1.0-P1.7 interface,
Output “0”, light-emitting When “0” is output, the light-emitting diode lights up, and at the beginning, P1.0→P1.1→P1.2→P1.3→…→P1.7→P1.6→…→P1.0 lights up, and the cycle is repeated.
MOVR2,#8;number of times of left shift
MOVA,#0FEH;Initial value of A, i.e., L0 of P1.0 is lit
RLCA;Left shift running lamp (left shift with rounding), i.e., the highlight moves to the high bit of P1 port
MOVR2,#8;Right shift count
LOOP1:RRCA;Right shift running lamp
DELAY:MOVR5,#10;delay subroutine,change the value of R5,R6,R7,you can change the time of the delay,so as to change the speed of the moving lamp
<< < Question 2>>
Experiment purpose: to master the principle of microcontroller lookup table, master MOVDPTR, # DATA16 instruction, MOVCA,@A + DPTR use
Experiment content: the use of MOVCA,@A + DPTR instruction, control 8 light-emitting diode running water bright and dark.
Detailed function of the program:
The use of the method of taking the table, so that the port P1 to do a single light change: 2 times to the left, 2 times to the right, blinking 2 times (the time of the delay of 0.2 seconds).
When programming with the table, the following instructions are to be used
(1). Use the instruction MOVDPTR, #DATA16 to make the data pointer register point to the beginning of the table.
(2). The instruction MOVCA,@A + DPTR is utilized to make the program counter PC point to the data to be taken out of the table based on the value of the accumulator plus the value of DPTR.
*Thus, as long as the control code is built into a table, and the MOVCA,@A + DPTR is used to do the operation of fetching the code,
*it can be convenient to deal with some complex control actions.
MOVDPTR,#TABLE;Fetch the address of DPTR, which is the starting address of the table
MOVCA,@A + DPTR,@A + DPTR,@A + DPTR].
MOVCA,@A+DPTR;check the table
CJNEA,#01H,LOOP1;determine whether to the end of the table, when A is equal to 01 when the program is executed down, otherwise jump to LOOP1
LJMPSTART;jump to the beginning of the program to execute the cycle
MOVP0,A;send the table data to P0
INCDPTR;add one to DPTR,i.e.point DPTR to the next table unit
DELAY:MOVR5,#10;delay subroutine, change the value of R5, R6, R7, you can change the delay time, so as to change the speed of the moving lights
;The following is the pattern table of the running lights, each data corresponds to the state of the LED under one moment
;The data of TABLE will be finally arranged by the compiler into the FLASH program storage area of the microcontroller, which can only be read but not modified when the CPU is running.
<< < Question 3>>
No more writing,,I’m tired!
Answers to Assembly Language Programming review questions for help, analysis questions! High marks, thanks!
41Answers are as follows:
SI is the source address register, DI is the destination address register, that is, the source address register [SI] to start the 64H bytes of the content, copied to the beginning of the address of [DI] space to go.CX is the counter, that is, to copy the content of the 64H bytes, MOVSB is the MOV to B as a unit!
MOVAX,[BX]; after this step, AX = [BX] = 15H
MOVB,AX; B = 15H
MOVAX,2[BX]; 2[BX] means [BX+2], so AX = 05H
ADDAX,. B; 15H+05H=1AH
MOVA,AX; finally 1AH
VI. Program to fill in the blanks
First blank 0FH
Second blank 4AH.
The basic idea of this question is to shift the BX cycle right by four bits, take BL, assign it to AL, with the upper 0FH,clear the high four bits to zero, get the low four bits, and then add 30H to judge whether it is more than A, because the ASCLL of A is not consecutive with the ASCLL code of 0-9. According to the judgment result and then add 07H,that’s it.
I was originally an assembly section representative! Haha
Assembly language programming topics, waiting for answers online!!!! Urgent!
ADB148;Write here: 0~255
BDB28;Write here: 0~255
SHRAX,1;divide by 2
DISP:;display in hex
After the program is run, it will display the average value 58H in hexadecimal.