Automatic Traffic-Light Control: P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P2.3 P2.2 P2.1 P2.0
Automatic Traffic-Light Control: P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P2.3 P2.2 P2.1 P2.0
The project we have chosen for the microcontroller lab is of an automatic traffic light controller. The approach we have used is quite simple. We would be handling the lights one by one. The delay is provided by the internal timer of 8051 microcontroller. In this example we have used timer 1 in mode 1. Now let us have a look at the color of LEDs attached to various ports.
P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P2.3 P2.2 P2.1 P2.0
RED YELLOW GREEN RED YELLOW GREEN RED YELLOW GREEN RED YELLOW GREEN
The device works in accordance with the following algorithm: 1. All the red lights are on. 2. Switch off one red light and turn on the corresponding green light. This is done for 10 seconds. 3. Switch off the green light and turn on the corresponding yellow light. This is done for 5 seconds. 4. Switch off the yellow light and once again turn on the red light. 5. Repeat these steps for all the 4 red lights in a cyclic manner. 6. Keep on following these steps for infinite number of times.
On the next page we have shown the code that we have written for this purpose.
PROGRAM
ORG 00H MOV P0,#OFFH MOV P2,#0FFH CPL P0.0 CPL P0.3 CPL P0.6 CPL P2.2 LCALL DELAY HERE: CPL P0.0 CPL P0.2 LCALL DELAY LCALL DELAY CPL P0.2 CPL P0.1 LCALL DELAY CPL P0.1 CPL P0.0 CPL P0.3 CPL P0.5 LCALL DELAY LCALL DELAY CPL P0.5 CPL P0.4 LCALL DELAY
CPL P0.4 CPL P0.3 CPL P0.6 CPL P2.3 LCALL DELAY LCALL DELAY CPL P2.3 CPL P0.7 LCALL DELAY CPL P0.7 CPL P0.6 CPL P2.2 CPL P2.0 LCALL DELAY LCALL DELAY CPL P2.0 CPL P2.6 LCALL DELAY CPL P2.6 CPL P2.2 LJMP HERE DELAY: MOV TMOD,#10H MOV R0,#71 J1: MOV TL1,#00H MOV TH1,#00H
The code uses the concept of the internal times to generate the delay. On the next page we have described the circuit diagram for our project. The dark lines indicate the connections made for the application whereas the light lines indicate the basic circuit. We have also provided t long lines, one on top and another on the bottom. The upper one will act as a source for +5 V and the lower one will act as ground.