1. Experimental task:
Use the timer/counter T0 of AT89S51 to generate a 2-second timer. When the 2-second timer comes, the indicator light flashes. The frequency of each indicator flashing is 0.2 seconds. That is to say, the L1 indicator light flashes at a rate of 0.2 seconds at the beginning. When the 2-second timer comes, L2 starts to flash at a rate of 0.2 seconds, and so on. The 0.2-second flashing rate is also completed by the timer/counter T0.
2. Circuit schematic diagram
Figure 4.16.1
3. System board hardware connection
(1). Connect P1.0-P1.3 in the "single-chip microcomputer system" area to L1-L4 in the "eight-way light-emitting diode indicator module" area with wires
4. Program design content
(1). Since the interrupt method is used, the interrupt source must have its interrupt entry address. For the timer/counter T0, the interrupt entry address is 000BH, so a long jump instruction is added to the interrupt entry to execute the interrupt service program. The format of writing assembly source program is as follows:
ORG 00H
LJMP START
ORG 0BH; Timer/Counter T0 interrupt entry address
LJMP INT_T0
START: NOP; Main program starts
.
.
INT_T0: PUSH A CC ; Timer/Counter T0 interrupt service program
PUSH PSW
.
.
POP PSW
POP ACC
RETI; Interrupt service program returns
END
(2). Timing for 2 seconds, using 16-bit timing for 50ms, a total of 40 times of timing can reach 2 seconds, an interrupt is generated every 50ms, and the 40 times of timing are completed in the interrupt service program. Similarly, for a timing of 0.2 seconds, 4 times are required to reach 0.2 seconds. For the interrupt program, the interrupt must be disconnected in the main program.
(3). Since each time the 2-second timing is reached, L1-L4 will flash alternately. Use ID to identify. When ID=0, L1 is flashing, when ID=1, L2 is flashing; when ID=2, L3 is flashing; when ID=3, L4 is flashing
5. Program flowchart
T0 interrupt service program flowchart
Main program flowchart
Figure 4.16.2
6. Assembly source program
TCOUNT2S EQU 30H
TCNT02S EQU 31H
ID EQU 32H
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV TCOUNT2S,#00H
MOV TCNT02S,#00H
MOV ID,#00H
MOV TMOD,#01H
MOV TH0,#(65536-50 000) / 256
MOV TL0,#(65536-50000) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP $
INT_T0: MOV TH0,#(65536-50000) / 256
MOV TL0,#(65536-50000) MOD 256
INC TCOUNT2S
MOV A,TCOUNT2S
CJNE A,#40,NEXT
MOV TCOUNT2S,#00H
INC ID
MOV A,ID
CJNE A,#04H,NEXT
MOV ID,#00H
NEXT: INC TCNT02S
MOV A,TCNT02S
CJNE A,#4,DONE
MOV TCNT02S,#00H
MOV A,ID
CJNE A, #00H,SID1
CPL P1.0
SJMP DONE
SID1: CJNE A,#01H,SID2
CPL P1.1
SJMP DONE
SID2: CJNE A,#02H,SID3
CPL P1.2
SJMP DONE
SID3: CJNE A,#03H,SID4
CPL P1.3
SID4: SJMP DONE
DONE: RETI
END
7. C language source program
#include
unsigned char tcount2s;
unsigned char tcount02s;
unsigned char ID;
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
TR0= 1;
ET0=1;
EA=1;
while(1);
}
void t0(void) interrupt 1 using 0
{
tcount2s++;
if(tcount2s==40)
{
tcount2s=0;
ID++;
if(ID==4)
{
ID=0;
}
}
tcount02s++;
if(tcount02s==4)
{
tcount02s=0;
switch(ID)
{
case 0:
P1_0=~P1_0;
break;
case 1:
P1_1=~P1_1;
break;
case 2:
P1_2=~P1_2;
break;
case 3:
P1_3=~P1_3;
break;
}
}
Design of 99-second stopwatch based on 51 single-chip microcomputer
Previous article:51 MCU PWM control LED on and off
Next article:A complete guide to programming precise timing interrupts for C51 MCUs
- Popular Resources
- Popular amplifiers
- 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)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- [NXP Rapid IoT Review] + Rapid IOT Kit Review Summary
- Worried about switching from Class AB to Class D? No need to worry
- [ART-Pi Review] 4: Networking to synchronize time and automatically connect to WiFi
- 8-bit data latch 74HC573 application example
- IO port level conversion
- DSP C6000 Architecture
- Analysis of the three most commonly used communication protocols in single-chip microcomputer systems
- Switching power supply PCB layout considerations
- The most complete power supply circuit diagram
- DSP external device connection interface EMIF