In daily life, the use of traffic signals, so that traffic can be effectively managed, for the diversion of traffic flow, improve road capacity, reduce traffic accidents have obvious effects. Traffic light control system consists of 80C51 microcontroller, keyboard, LED display, traffic light delay. In addition to the basic traffic light function, the system also has time settings, LED information display function, the city traffic to achieve effective control.
Keywords: traffic lights; microcontroller; automatic control; LED
Abstract
In daily life, the use of traffic lights, so traffic can be managed effectively in smoothing traffic flow, increase road capacity and reduce traffic accidents have remarkable results. Traffic light control system consists of 80C51 Traffic light control system consists of 80C51 microcontroller, keypad, LED display, traffic light delay component. In addition to the traffic light system has the basic functions, but also with time In addition to the traffic light system has the basic functions, but also with time settings, LED information display function, achieving effective control of city traffic
Key Words: traffic lights; SCM; control; LED
Objects Record
1 Traffic Lights Mission, Functional Requirements Description and Overall Program Introduction ..................... ..................1
1.1 Traffic light task ...... .............................. .............................. .........1
1.2 Functional requirements description ............... .............................. ...........................1
1.3 Design Overall program introduction and working principle description ........................... ..................2
2 Design of traffic light hardware system ...... .............................. .............................. 4
2.1 Introduction of the functions of each module of the hardware system ........................ .............................. ...4
2.2 Circuit schematic diagram ..................... .............................. .....................5
2.3 Circuit PCB diagram ... .............................. .............................. .........5
2.4 Component Layout Diagram ............... .............................. ........................5
2.5 Component List .............................. .............................. ............5
3 Design of Traffic Light Software System ............ .............................. ........................7
3.1 Use of resources for microcontroller .............................. ...........................7
3.2 Software Introduction of module function ........................... .............................. ......8
3.3 Program flow chart .................. .............................. ........................8
3.4 Program listing .............................. .............................. ...............10
4 Design Summary ......... .............................. .............................. ...............11
4.1 Instructions for use ......... .............................. .............................. ......11
4.2 Error analysis .................. .............................. ...........................11
4.3 Design experience ........................... .............................. ..................11
4.4 Teaching suggestions ...... .............................. .............................. .........12
References .................. .............................. .............................. .........13
Acknowledgments .................. .............................. .............................. ............14
Appendix I Circuit Schematic ............ .............................. .............................. 15
Appendix II Circuit PCB Top Level Diagram ........................ .............................. ............16
Appendix III Circuit PCB Bottom Layer Diagram ............ .............................. ........................17
Appendix IV Component Layout Diagrams .............................. .............................. .........18
Appendix V Component List ............... .............................. ...........................19
Appendix VI Program list ........................... .............................. ..................20
1 Traffic Light Task, Functional Requirements Description and Overall Program Introduction
1.1 Traffic Light Task
Design an intersection traffic light with specific functions. The traffic light can automatically display the system prompt "P." after power-on or key reset, and enter the ready-to-work state. Press the start button to start working, and press the end button to return to the "P." state. Requirements for lane A and lane B two cross roads on the vehicle running alternately, lane A is the main lane, each time the traffic time is 60 seconds, lane B is the second lane, each time the traffic time is 30 seconds, the requirements of the yellow light for 3 seconds, and 1 second flashes once. Emergency vehicles appear, the red light is on, emergency vehicles through the time of 10 seconds, while prohibiting other vehicles through.
1.2 Functional Requirements Description
This course design in the hardware aspects of the connection is as follows: P2 port diode, P2.0, P2.1, P2.2 port line to control the east-west direction of the green, yellow and red lights; P2.3, P2.4, P2.5 port line to control the north-south direction of the red light, yellow and green lights, respectively.P0 port as a digital tube bit control (). The P0 port is used as the bit control of the digital tube (only P0.0 and P0.1 are used here), the P1 port is used as the segment control of the digital tube, and the P3 port is used as the input part (P3.0, P3.1 and P3.2 are used here) to control the display of the digital tube and the diode.
When the traffic light is powered on or key reset, it can automatically display the system prompt "P." and enter the ready-to-work state.
When the start button K1 is pressed and released, the digital tube display will start counting down from "60", every second minus 1, at this time, the north-south direction has been on the green light, the east-west direction has been on the red light until the display is "00", the digital tube will start counting down from "03", the digital tube will start counting down from "03", the digital tube will start counting down from "03" to "00". The digital tube will count down from "03", minus 1 every second, at this time the yellow light flashes every second in the north-south direction, and the red light stays on in the east-west direction until it shows "00", the digital tube will count down from "30", minus 1 every second, at this time the green light stays on in the north-south direction, and the red light stays on in the east-west direction until it shows "00". 30" start counting down, at this time the north-south direction has been bright red light, the east-west direction has been bright green light, until the display is "00", the digital tube will start counting down from "03", at this time the north-south direction has been bright red light, the east-west direction every second yellow light flashes once, the east-west direction has been bright red light, the north-south direction has been bright red light. The yellow light flashes every second in the east-west direction; when there is no other key pressed, the traffic light will keep on cycling like this.
When the end key K2 is pressed and released, the digital tube will display "P.", and no light is on in the east-west and north-south directions.
When the emergency key K3 is pressed and released, the digital tube will display "09", and every second will be reduced by 1,
All the red lights are on in the east-west, north-south and west-north directions.
The microcontroller adopts AT89S52, fosc=12MHZ, and its key functions are shown in Table 1.1.
Table 1.1 Key Functions
Key Key Name Function
P3.4 K1 Key Start Key
P3.7 K2 Key End Key
P3.6 K3 Key Emergency Key
1.3 Introduction to the Overall Program of the Design and Explanation of the Principle of Operation
1.3.1 Introduction to the Overall Program
The traffic light circuit consists of microcontroller AT98S52, keyboard interface circuit, display interface circuit, light-emitting diode control circuit, clock circuit and reset circuit, the schematic block diagram shown in Figure 1.1.
Figure 1.1 Block Diagram
(1) power supply
The use of independent regulated power supply, the advantages of this program is stable and reliable, and there are a variety of mature circuits available.
(2) Display
The digital tube display is completely used to display limited symbols and digital characters.
(3) Keyboard Input
The key switches are connected directly to the I/O port lines, and because the design has streamlined and optimized the circuitry, there are still more port resources left. We *** used four keys, respectively: K0, K1, K2, K3.
1.3.2 principle of operation
First of all, the clock circuit generates the clock signal needed for the microcontroller to work, which is the premise of the microcontroller can work properly, and the microcontroller has a timing basis as well as the timing of the time, which still need to be determined by our human. I am using 10ms delay program to repeatedly call to timing, in our hardware circuit, the key function of the key program in the interrupt service, under normal circumstances will continue to run the main program, when a key is pressed, the CPU to go to the execution of the interrupt program, and the interrupt program can be performed three kinds of key functions: the first one is a ten-second countdown emergency red light; the second one is the end of the countdown, displaying the P.; the third one is the countdown to restart. restart the countdown. The principle is INTO = P3.4 & P3.6 & P3.7, when a key is pressed, the external interrupt 0 port line will become low, through the key scanning program to determine exactly which key is pressed, the CPU will go to the implementation of the interrupt inside the key function. 12 light-emitting diodes are controlled by the P0 port, the P0 port and the diode between the diode in series a current-limiting resistor so that the diode is not easy to burn out. The diode is not easy to burn out, using the send low level effective.
2 Traffic Light Hardware System Design
2.1 Hardware System Module Functions
2.1.1 Display Circuit
In the design of this course, we use a four-bit ****yang digital tube. The display driver of this design is using triode as the driver. And, a resistor is connected in series either on the bit control line or on the segment control line to increase its output power, 220 ohm female resistor is used here.
2.1.2 Indicator Control Circuit
This course design uses the P3 port to control the light-emitting diode, the port line to send a low level effective, the specific design is as follows: P3.2 control the green light in the east-west direction, P3.4 port control the yellow light in the east-west direction, P3.5 control the red light in the east-west direction, P3.1 control the red light in the north-south direction, P3.7 control the yellow light in the north-south direction's yellow light, P3.0 controls the north-south direction's green light.
2.1.3 Keyboard Control Circuit
The keyboard is the most commonly used input device, and it is the link that realizes man-machine dialogue. According to its structural form can be divided into non-coding keyboard and coding keyboard.
The coding keyboard uses hardware methods to generate key codes. Each key is pressed, the keyboard can automatically generate the key code, the number of keys is more, and has a de-jitter function. This keyboard is easy to use, but the hardware is more complex. Non-coding keyboard only provides key switch operating state, its key code determined by the software, this keyboard key less, simple hardware, widely used in a variety of microcontroller application system, in the microcontroller control circuit, the microcontroller can be used in the keyboard can be divided into two types of independent and matrix type. Independent is actually a group of independent keys, these keys can be directly connected to the microcontroller's I / O port, that is, each key is exclusive of a port line, this connection is simple. Matrix keyboard, also known as row and column keyboard, because the number of keys is more, so the keys are arranged in rows and columns to form a matrix. In this design, the number of keyboards is small, and for the convenience of installation, so in this design using independent connection.
Pressing a key from a key to the key function is performed should include two main tasks: one is the key recognition, that is, in the keyboard to find out which key is pressed, the other is the realization of the key function. The first task is realized using the interface circuitry, while the second is accomplished by executing an interrupt service program. Specifically, the keyboard interface should perform the following operational functions:
(1) Keyboard scanning to determine if a key has been pressed (called "key closure").
(2) Key recognition to determine where the rows and columns of closed keys are located.
(3) Key code generation for the closed key.
(4) Troubleshooting multiple keys, strings (compound keys) and de-jittering.
The above is usually done in a combination of hardware and software, i.e., in conjunction with software by the interface circuitry. But what is done by the hardware and what is done by the software depends on the interface circuitry. The general principle is that the hardware is complex software is simple, simple hardware software has to be more complex.
2.1.4 Clock circuit
The clock circuit is used to generate the clock signal required for microcontroller operation, the microcontroller itself is a complex synchronous timing circuit, in order to ensure the realization of the synchronous mode of operation, the circuit should be under the control of the only clock signal to work strictly in accordance with the timing. By connecting a crystal oscillator and a trimmer capacitor across the two external XTAL1 and XTAL2 pins of the chip to form a feedback circuit, a stable self-excited oscillation circuit is formed. The clock circuit generates clock pulse sequences for the microcontroller, and the crystal frequency used in this design is 12MHz with a capacitance of 33pF.
2.1.5 Reset Circuit
The reset circuit is used to generate a reset signal, which is fed to the microcontroller through the RST pin. The status word PSW is cleared to 0, the program counter PC is assigned to 0000H, etc. In addition to the normal initialization of the system, when the system is in deadlock due to a program running error or operational error, the reset key needs to be installed to restart in order to get rid of the situation.RST pin is the input of the reset signal, the reset signal is high level active, and it takes 24 state cycles to complete the reset operation***. After the reset is finished, the microcontroller starts executing the program from the address 0000H unit, SP is 07H, and most of the other registers are set to 00H. This design uses a crystal oscillator with a frequency of 12MHz, so the duration of the reset signal should be more than 2μs to complete the reset operation. Reset circuit is divided into power-on reset, key reset, key pulse reset three, this course design is used in the key reset.
2.1.6 MCU minimum system
It uses a microcontroller AT89S52 chip, which can realize the basic I/O port experiments, timer counter experiments and so on. With a microcontroller parallel port input, output function characteristics.
2.2 Circuit schematic
The circuit schematic is shown in Appendix I.
2.3 Circuit PCB Diagram
The circuit PCB top layer diagram is shown in Appendix II;
The circuit PCB top layer diagram is shown in Appendix III.
2.4 Component Layout Diagram
The component layout diagram is shown in Appendix IV.
2.5 Component List
The component list is shown in Appendix V.
3 Design of the Traffic Light Software System
3.1 Resources Used by the MCU
3.1.1 Description of Hardware Resource Usage
The P0 port is the diode's console The P1 port is used as an address/data bus The P2 port is used as an address/data bus The P3.4, P3.6, and P3.7 port lines are used as the Keyboard input INTO external interrupt is usedBoth in the AT89S52 P0 port used to connect the cathode of the twelve light-emitting diodes, control its light and off, P1 port and P2 port is connected to the external display consisting of two LED digital tubes (LED1, LED0), the P2 port for the segment code output port of the LEDs (P2.0 ~ P2.7 corresponds to the LEDs of the a The P1 port is used as the LED segment code output port (P2.0~P2.7 corresponds to the LED's a~dp), and the P1 port is used as the LED's bit-control output line (P1.1, P1.0 corresponds to the LED1, LED0, respectively), which is used as the display driver for two transistors externally connected to the serial port of the P1, and the display is shown as the dynamic display of the two digital tubes (LED0~LED1).The P3 port is connected to the three external buttons, K1, K2, and K3 (corresponds to the P3.4, P3.7, and P3.6 ports, respectively), P3.6 port) is used to adjust the display interface circuit.
3.1.2 Traffic light distribution table
The traffic light port line distribution as shown in Table 3.1, "1" means send high level, "0" means send low level.
Table 3.1 Traffic Light Assignment Table
P0.2 East-West Green 1 1 0 1
P0.3 East-West Yellow 1 1 1 0
P0.4 East-West Red 0 0 1 1
P0.5 North-South Red 1 1 1 0 0
P0.6 South-North Yellow 1 0 1 1
P0.7 South-North Green 0 1 1 1
P0.7 North-South Green 0 1 1 1
Control Code 6FH AFH DBH D7H
Status Description North-South Release, East-West Prohibit North-South Warning, East-West Prohibit North-South Prohibit, East-West Prohibit North-South Prohibit, East-West Release North-South Prohibit, East-West Prohibit
3.2 Introduction of Software Module Functions
The main task of the main program module is the initialization of the program displaying the "P...". .", when there is no key pressed, the display module will remain unchanged, the traffic lights are all off, when the K0 key is pressed and released to start counting down,
Which in the process of the time display to determine whether there is a K0, K1 and K2 key is pressed, when the K0 is pressed again, the display will re-start the countdown, if it is the K1 is pressed, the display will show "P.", and the light-emitting diodes are all extinguished, if K2 is pressed, the digital tube will start a ten-second countdown, and the east, west, south, north and south all lit up red.
3.3 Program Flowchart
The flowchart of the main program is shown in Figure 3.1, and the flowchart of the key judgment program is shown in Figure 3.2
Figure 3.1 Flowchart of the Main Program
Figure 3.2 Flowchart of the Key Judgment Program
3.4 Program List
Please refer to Appendix VI for details of the program list.
4 Design Summary
4.1 Instructions for use
This experiment is mainly composed of the use of microcontroller AT89S52, digital tubes and light-emitting diodes, the entire structure of the circuit is relatively simple, it can achieve the following functions:
Time display. The red, yellow and green lights glow and go out.Specific operational instructions are as follows: When the traffic light power or key reset can automatically display the system prompt "P.", enter the ready-to-work state. When pressing the start button K1 and release, the digital tube display will start counting down from "60", every second minus 1, at this time, the north-south direction has been bright green, east-west direction has been bright red until the display is "00", the digital tube will start counting down from "03", the digital tube will start counting down from "03", the digital tube will start counting down from "03", the digital tube will start counting down from "03" to "03". When the display is "03", the digital tube will count down from "30" to "30", the yellow light will flash once every second in the north-south direction, and the red light will be on in the east-west direction until the display is "00". "At this time, the north-south direction is always on red light, the east-west direction is always on green light, until the display is "00", the digital tube will start counting down from "03", at this time the north-south direction is always on red light, the east-west direction is always on yellow light every second, and the east-west direction is always on red light. At this time, the red light is always on in the north-south direction, and the yellow light flashes once every second in the east-west direction; when there is no other key pressed, the traffic light will keep cycling in this way. When the end key K2 is pressed and released, the digital tube will display "P.", no lights in the east, west, south, north and south directions, when there are other keys pressed, it will be withdrawn to perform the key function of the key. When pressing the emergency key K3 and release, the digital tube will display "10", and every second will be reduced by 1, the east-west and north-south direction of all the red lights on, when not bright to display "00" on the other keys pressed, it will exit, the implementation of the key's function, when the display is to When the display to "00", it will automatically exit the interrupt to continue to complete the main program.
4.2 Error Analysis
The error of this course design lies in the display time, I used to call the delay program to let the display on the digital **** display for one second, and the cycle of a time is not only the time of the 2 times to call the delay program, during which the CPU also performs other instructions, for example, say the contents of the buffer area to the accumulator A, look up the table instruction, the segment of the Control code to the P2 port and so on, because they are microseconds, while the delay program is milliseconds, so in the process of calculating can be omitted, each cycle in addition to the two calls to the delay program, the time used for 22 microseconds, while the display of a second **** cycle of 50 times, so in the display only need to show 1 second figures, in fact, more than 1100 microseconds, the error rate = 1.1%.
4.3 Design Experience
After more than a week, the course design was finally completed. During this period, other students gave a lot of valuable advice, so that this design is finally complete and successful.
I think as an automation student, the course design of microcontroller is very meaningful. What is more important is how to apply what you usually learn in practice. Although I do not know much about this course, a lot of basic things have not been well mastered, think it is difficult, there is no very effective way to understand through their own, but by this more than a week of "learning", in the help of students and explain, gradually gradually on this course gradually produced a little interest, they began to take the initiative to learn! I started to learn it on my own initiative, and gradually started to understand it from the basics. I think this harvest should be said to be quite big.
After this course design, it makes me realize the importance of learning microcontroller more y. Today's microcontroller penetrates into all areas of our lives, such as from the missile's navigation device, aircraft control of a variety of instruments, computer network communication and data transmission, automation field of robotics, intelligent instrumentation, medical equipment, industrial automation process of real-time control and data processing, etc. to our lives in contact with a variety of intelligent IC cards, civilian limousine safety and security systems, video recorders, Camera, automatic washing machine control and program-controlled toys, electronic pets and so on, these are inseparable from the microcontroller. It is mainly used as the core component of the control part. Therefore, the study and development of microcontroller is very important in all walks of life. In the future, I will work harder to learn to consolidate the microcontroller, for the future work to lay a solid foundation.
4.4 Teaching Suggestions
Under the strict requirements and patient guidance of Mr. Wang Ren, after one semester's study of this course on microcontroller technology, I have gained a certain understanding of the application of microcontroller as a technology and have developed a strong interest in the study of microcontrollers.
Through the design of this microcontroller-controlled traffic lights, combined with my learning process and personal experience to the teacher to put forward the following teaching views: I hope that the teacher will be able to teach this class at the beginning of the class when the whole class is divided into small groups, so that those who are more familiar with the microcontroller to help students with poorer foundations, so that you can improve the efficiency of learning and enthusiasm; in addition, Ms. Wang can introduce more information related to the microcontroller, so that you can learn more about the microcontroller. In addition, Mr. Wang can introduce more information books related to microcontrollers to students, to train students to consult information books; the last point is that Mr. Wang does not have to explain the expansion of microcontrollers is too detailed, focusing on guiding the idea of the formation of microcontrollers as a whole framework structure.
Appendix I Circuit Schematic Diagram
Appendix II PCB Top Layer Diagram
Appendix III PCB Bottom Layer Diagram
Appendix IV Component Layout Diagram
Appendix V Traffic Lights Component List
Components and Materials Name Specification Number Remarks
AT89S52 Plus Base 1
Quadruple ****yang digital tube with base 2 0.5 inch
Crystal 12MHz 1 triple crystal
Light-emitting diode large 9
Single row plug 40 pins 1
Triode 9012 9
Buzzer 1 5V
Small buttons 9 6 * 6 * 4.3mm
Download port holder ten core 1 FC-10P
18b20 Temperature Sensor 1
Six-Pin Keyswitch 1 6*6*4.3mm
Usb Power Cord Plus Interface 1 USB Cable Plus USB Interface
Resistor 200 1
Resistor 4.7K 1
Resistor 1K 3
Resistor 470 24
Electrolytic Capacitor 22uf 1Ceramic Chip Capacitor 33pf 2
Array Resistor 10k 2
Short Circuit Cap 3
DuPont Cable 8P 1
PCB Board 150mm*200mm 1
Power Supply White Socket 1
Appendix VI List of Programs
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP LOOP1
ORG 0030H
MAIN: MOV PSW, #00H; Initialize
MOV SP, #7FH
MOV TMOD, #10H.
MOV TH1, #3CH;
MOV TL1, #0B0H;
MOV TH0, #0FCH;
MOV TL0, #18H;
MOV 78H, #11H;
MOV 79H, #10H;
MOV 7AH, #10H;
MOV 7AH, #10H;
MOV TMOD, #10H. #10H;
MOV 7BH, #10H;
MOV 7CH, #10H;
MOV 7DH, #10H;
MOV 7EH, #10H;
MOV 7FH, #10H;
MOV R7, #0FAH;
MOV R6, #32H;
MOV R5, #05H;
MOV R4, #39H;
MOV R1, #20;
SETB EA;
SETB ET1;
PP: LCALL DIR;
START: LCALL KEY ;
JB 20H.0, K0;
LJMP PP;
K0: MOV R4, #39H;
MOV R1, #20;
SETB TR1;
MOV 78H, #07H;
MOV 79H, #05H;
MOV 7AH, #10H;
MOV 7BH, #10H;
MOV 7CH, #10H;
MOV 7DH, #10H;
MOV 7EH, #10H;
MOV 7FH, #10H;
LCALL DIR;
MOV 79H, #00H;
CYCLE1: MOV P3, #0DFH;
JB 20H.2, OUT;
JB 20H.1, JINJI;
CJNE R1, #10, CYCLE1;
CYCLE2. MOV P3, #0DDH;
JB 20H.2, OUT;
JB 20H.1, JINJI;
CJNE R1, #20, CYCLE2;
CJNE R4, #00H, CYCLE1;
MOV R4, #1EH;
MOV 78H, #07H;
MOV 79H, #02H;
CYCLE3: MOV P3, #0F3H;main red, vice green
JB 20H.2, OUT;
JB 20H.1, JINJI;
CJNE R4, #00, CYCLE3;delay 30 seconds
MOV R4, #03H;
MOV 78H, #03H;
MOV 79H, #00H;
CYCLE4: MOV P3, #0DFH;
JB 20H.2, OUT;
JB 20H.1, JINJI;
CJNE R1, #10, CYCLE4;
CYCLE5: MOV P3, #0DDH;
JB 20H.2, OUT;
JB 20H.1, JINJI;
CJNE R1, #20, CYCLE5;
CJNE R4, #00H. CYCLE4;
MOV R4, #39H;
LJMP K0;
JINJI: MOV R4, #10;Emergency Vehicle Button
CYCLE6: MOV P3, #0DBH
CJNE R4, #00, CYCLE6;
LJMP K0;
OUT: MOV P3, #0FFH;
MOV 78H, #11H;
MOV 79H, #10H;
MOV 7AH, #10H;
MOV 7BH, #10H;
MOV 7CH, #10H;
MOV 7DH, #10H;
MOV 7EH, #10H;
MOV 7FH, #10H;
MOV R7, #0FAH;
LJMP PP;
DIR: PUSH DPH; display subroutine
PUSH DPL;
PUSH ACC;
PUSH PSW;
SETB RS0;
CLR RS1;
MOV R0, #78H;
MOV R3, #0FEH;
MOV A, R3;
LD0: MOV P2, A;
MOV DPTR, #TABLE;
MOV A, @R0;
MOVC A, @A+DPTR;
MOV P0, A;
LCALL DELAY;
INC R0;
MOV A, R3;
JB ACC.7, #LD1;
MOV A, R2;
LD1. LD1;
RL A;
MOV R3, A;
LJMP LD0;
LD1: CLR RS0; Restore the current general-purpose register group number
CLR RS1;
POP PSW;
POP ACC; Restore the field
POP DPL;
POP DPH;
RET;
TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H; 0--6
DB 0F8H,80H,90H,88H,83H,0C6H,0A1H; 7--D
DB 86H,8EH,0FFH,0CH; E--F,extinguish,P.
KEY: LCALL KEYCHULI;key sweep program
JZ EXIT;
LCALL XX0;
LCALL KEYCHULI
JZ EXIT;
MOV B, 20H,80H,90H,88H,83H,0C6H,0A1H; 7--D
. p>MOV B, 20H;KEYSF: LCALL KEYCHULI;
JZ KEY1;
LCALL XX0;
LJMP KEYSF;
KEY1: MOV 20H, B;
EXIT: RET;
KEYCHULI: MOV P1, #0FFH;
MOV A, P1;
CPL A;
ANL A, #0FH;
MOV 20H, A;
RET;
DELAY: DJNZ R7, DELAY;display delay subroutine
<MOV R7, #0FAH;
DJNZ R5, DELAY;
MOV R5, #05H;
RET;
; Timer 1 sec interrupt program:
LOOP1:
MOV TH1, #3CH;Timer 0 is assigned to the initial value, timing 50ms
MOV TL1, #0FAH.
MOV TL1, #0B0H;
LCALL DIR;
LCALL KEY;
DJNZ R1, RETURN;
DEC R4;
MOV R1, #20;
MOV R0, #79H;
LCALL DADD1;
RETURN: RETI;
; De-jitter delay subroutine:
XX0: DJNZ R7, XX0;
MOV R7, #0FAH;
DJNZ R6, XX0;
MOV R6, #32H;
RET;<
Subtract one subroutine:
DADD1: MOV A, @R0;
DEC R0;
SWAP A;
ORL A, @R0;
SUBB A, #01H;
DA A;
MOV R2, A;
ANL A, #0FH;
MOV @R0, A;
MOV A, R2;
INC R0;
ANL A, #0F0H;
SWAP A;
MOV @R0, A;
RET;
END