The effect of this experiment is the same as the last one, which is to light each light in turn. If the effect is the same, why do we do so many experiments on lights? We do experiments not to develop products or require innovation, but mainly to learn knowledge. Although this experiment has the same effect as the last one, we did use different methods. In the last lesson, we controlled each bit of the P1 port one by one to make the LED flow. In this experiment, we send a number to the P1 port at the beginning of the program. This number itself makes P1.0 low first, and other bits high. Then, if we move this data to the high bit, wouldn’t we achieve the "flowing" effect? Indeed! Unfortunately, 8051 does not have instructions to move P1 data, but there are instructions to shift the data in the accumulator ACC left or right. ACC is a "register" in the arithmetic logic unit of the 8051 microcontroller (it is incorrect to call it a register here, but you can understand it this way first. ACC is often written as A in instructions). It plays an important role in data transmission and data processing. ACC is 8 bits. It can exchange data with all single-byte registers in the chip. In fact, P1 and other ports are also registers in the microcontroller. In this way, we can put the data to be moved into ACC first, let it move, and then transfer the data moved by ACC to P1 port, which can also achieve the "pipeline" effect. The procedure is as follows: star : ;Start mov acc,#0feh ;First load the data of LED1 turning off into ACC (that is, binary 1111 1110) mov p1,acc ;Send the data of ACC to P1 port acall delay mov r0,#7 ;Because the data sent to P1 port in the previous sentence has turned off one bit, ;so moving the data 7 more times will complete an 8-bit pipeline process loop : ;Data movement loop rl a ;Shift the data in ACC one bit to the left mov p1,a ;Send the data moved by ACC to P1 port for display acall delay ;Call delay djnz r0, loop ;If it has not moved 7 times, continue to move ljmp star ;After moving 7 times, jump to the beginning and start again to achieve a circular flow effect delay : ;The delay subroutine is the delay subroutine in the previous lesson mov r1,#50 del0: mov r2,#100 del1: mov r3,#100 djnz r3,$ djnz r2,del1 djnz r1,del0 ret ; The delay subroutine ends and returns to the next sentence of the call end ; This assembly program ends here Next, compile the above program and burn it into our experimental chip.
|