Flashing light controlled by single chip microcomputer

1 . The experimental task is shown in the figure: Connect a light-emitting diode L1 to the P1.0 port, so that L1 keeps on and off, and the interval between on and off is 0.2 seconds.
2 . Circuit schematic
3 . The hardware connection on the system board connects the P1.0 port in the "SCM system" area to the L1 port in the "Eight-way LED indicator module" area with wires.
4 . Programming content (1). The design method of the delay program as the execution time of the instruction of the single-chip microcomputer is very short, and the number is in the order of microseconds. Therefore, the blinking time interval we require is 0.2 seconds. Compared with microseconds, the difference is too large, so we are in When a certain instruction is executed, a delay program is inserted to meet our requirements, but how is such a delay program designed? The principle is specifically described below:
The quartz crystal as shown in Figure 4.1.1 is 12MHz, therefore, 1 machine cycle is 1 microsecond Machine cycle microsecond
MOV R6, # 20 2 pcs 2
D1: MOV R7, # 248 2 2 2 + 2 & TImes; 248 = 498 20 & TImes;
DJNZ R7, $ 2 2 & TImes; 248 (498
DJNZ R6, D1 2 2 & TImes; 20 = 40 10002
Therefore, the above delay program time is 10.002ms.
It can be seen from the above that when R6 = 10 and R7 = 248, the delay is 5ms, and when R6 = 20 and R7 = 248, the delay is 10ms, which is the basic timing unit. If this experiment requires 0.2 seconds = 200ms, 10ms × R5 = 200ms, then R5 = 20, the delay subroutine is as follows:
DELAY: MOV R5, # 20
D1: MOV R6, # 20
D2: MOV R7, # 248
DJNZ R7, $
DJNZ R6, D2
DJNZ R5, D1
RET
(2). The output control is shown in Figure 1. When the P1.0 port outputs a high level, that is, P1.0 = 1, according to the unidirectional conductivity of the light-emitting diode, the light-emitting diode L1 goes out; when the P1.0 port output is low When the level is P1.0 = 0, the LED L1 is on; we can use the SETB P1.0 command to make the P1.0 port output high level, and use the CLR P1.0 command to make the P1.0 port output low level.
5 .   Block diagram ( omitted )

6 . Assembly source ORG 0
START: CLR P1.0
LCALL DELAY
SETB P1.0
LCALL DELAY
LJMP START
DELAY: MOV R5, # 20; Delay subroutine, delay 0.2 seconds
D1: MOV R6, # 20
D2: MOV R7, # 248
DJNZ R7, $
DJNZ R6, D2
DJNZ R5, D1
RET
END
7 . C language source program
#include
sbit L1 = P1 ^ 0;
void delay02s (void) // Delay 0.2 seconds subroutine
{
unsigned char i, j, k;
for (i = 20; i> 0; i--)
for (j = 20; j> 0; j--)
for (k = 248; k> 0; k--);
}
void main (void)
{
while (1)
{
L1 = 0;
delay02s ();
L1 = 1;
delay02s ();
}
}

Table Gas Cooker

Table Gas Cooker,Gas Stoves,Gas Cookers,Tabletop Stoves

Xunda Science & Technology Group Co.ltd , https://www.xundatec.com

This entry was posted in on