9553 views|7 replies

1

Posts

0

Resources
The OP
 

1. Flashing lights [Copy link]

. Experimental tasks

As shown in Figure 4.1.1: Connect a light emitting diode L1 to the P1.0 port, so that L1 flashes on and off continuously, with a time interval of 0.2 seconds.

2.  Circuit diagram

Figure 4.1.1

3.  Hardware connection on the system board

Use a wire to connect the P1.0 port in the "MCU System" area to the L1 port in the "Eight-way LED Indicator Module" area.

4.  Programming content

(1) Design method of delay program

The execution time of the instructions of the microcontroller is very short, in microseconds. Therefore, the flashing time interval we require is 0.2 seconds, which is too different from microseconds. Therefore, when executing a certain instruction, we insert a delay program to meet our requirements. But how to design such a delay program? The following is a detailed introduction to its principle:

The quartz crystal shown in Figure 4.1.1 is 12MHz, so 1 machine cycle is 1 microsecond

Machine cycle microseconds

MOV R6,#20 2 2

D1: MOV R7,#248 2 2 2+2×248=498 20×

DJNZ R7, $2 2×248 (498

DJNZ R6,D1 2 2×20=40 10002

Therefore, the delay program time above is 10.002ms.

From the above, we can know that when R6=10、R7=248, the delay is 5ms, and when R6=20、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, and 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) Output control

As 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 is off; when the P1.0 port outputs a low level, that is, P1.0=0, the light-emitting diode L1 is on; we can use the SETB P1.0 instruction to make the P1.0 port output a high level, and use the CLR P1.0 instruction to make the P1.0 port output a low level.

5. Flowchart

   As shown in Figure 4.1.2

                 Figure 4.1.2

6. Assembly source program

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();

}

}

This post is from MCU

Latest reply

Come again///  Details Published on 2007-4-8 16:59
 

1284

Posts

0

Resources
2
 
Where is the source?
This post is from MCU
 
Personal signature呼呼...在校应届大四学生,代做电子类毕业设计(测量类、仪器类、控制类、无线通信类、电子产品类、界面设计类、纯论文类等等,一一俱全)。涉及各种单片机软硬件设计、电路模拟分析、FPGA、CPLD、ARM7/ARM9、LINUX、VB/VC++/QT界面等等。包过。。。欢迎咨询。Tel:13957160506。QQ:273437087
 

9

Posts

0

Resources
3
 
When compiling, the assembler program has no problem, but the C language program has a problem.
This post is from MCU
 
 
 

1284

Posts

0

Resources
4
 
funny...
This post is from MCU
 
Personal signature呼呼...在校应届大四学生,代做电子类毕业设计(测量类、仪器类、控制类、无线通信类、电子产品类、界面设计类、纯论文类等等,一一俱全)。涉及各种单片机软硬件设计、电路模拟分析、FPGA、CPLD、ARM7/ARM9、LINUX、VB/VC++/QT界面等等。包过。。。欢迎咨询。Tel:13957160506。QQ:273437087
 
 

7

Posts

0

Resources
5
 
I don't quite understand...
This post is from MCU
 
 
 

1759

Posts

0

Resources
6
 
The post of the host is missing some content. After modifying it, there will be no problem in compiling. 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(); } }
This post is from MCU
 
Personal signature南京璞晓电子   www.cpx0.com需要
msn:njlianjian@hotmail.com
 
 

43

Posts

0

Resources
7
 
I don't understand assembly language very well, but I can understand C language
This post is from MCU
 
 
 

1284

Posts

0

Resources
8
 
Come again///
This post is from MCU
 
Personal signature呼呼...在校应届大四学生,代做电子类毕业设计(测量类、仪器类、控制类、无线通信类、电子产品类、界面设计类、纯论文类等等,一一俱全)。涉及各种单片机软硬件设计、电路模拟分析、FPGA、CPLD、ARM7/ARM9、LINUX、VB/VC++/QT界面等等。包过。。。欢迎咨询。Tel:13957160506。QQ:273437087
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list