Sei sulla pagina 1di 8

MICROCONTROLLER SYSTEMS LABORATORY Lab Report Shubham Mahajan (08EC3506) Vaibhav (08EC3501) Group: BT-09

Experiment 2 : TRAFFIC LIGHT CONTROLLER

Description of the problem :


Design a traffic light controller system that has four LEDs RED, YELLOW, GREEN, ADVANCE GREEN. The sequence in which the LEDs are turned on is as follows: RED for 1 min, YELLOW for 15 seconds, GREEN for 1 min, ADVANCE GREEN for the last 10 seconds of GREEN. Interface a lightdependent resistor (LDR) with it. Whenever the LDR is covered, the controller goes to manual mode and all lights start blinking. The system returns to its normal condition as soon as the LDR is uncovered.

Apparatus / Software used: Software Platform : Keil vision , Win51E Language : Assembly language for 8051 Hardware Platform : 8051 microcontroller kit Apparatus: LEDs, LDR, Resistors, Comparator IC -LM339

Methodology: Since the idea of the traffic light control is dependent on accurate timekeeping, a time delay of 5 seconds is created and is called a particular number of times to create the required time delays. The manual mode is incorporated by polling an input port for the LDR active condition. The basic essence of the algorithm is to use the external interrupt in the 8051 microcontroller to get the leds blinking as soon as LDR is covered. Once the LDR is cut out, the comparator output pulls down the input port and the manual mode is activated. The manual (blinking mode) also makes use of the delay quantum.

Hardware Design: The pins 1.2 to 1.5 are connected to the required sequence of LEDs P1.2 Red P1.3 Yellow P1.4 Green P1.5 Advanced Green (Blue) The off-light resistance of the LDR was found to be 2Mega Ohms while that in light was found to be 27K Ohms, so the LDR was interfaced using a 100KiloOhms resistor. Since the input port impedance was very high, the input never went below VL , therefore a comparator was used to act as a buffer. The circuit diagram of the connections is show in figure 1.

Figure.1

Software Design: We create a time quantum by running the code in a loop for a definite machine cycles for a fixed time delay, in our case we use 5s as the time quantum. The calculations for the generation of the machine cycles for 5 sec delay: Assuming crystal frequency to be 11.0592MHz, to generate 5s of delay: Delay = 242 *245* 234*4 (machine cycles)*90(nano seconds) = 4.99 seconds of delay The basic algorithm for implementing the traffic light control is as follows: 1) 2) 3) 4) 5) Enable external interrupt. Turn on red. Run time delay quantum routine (5s) 12 times for 1min delay. Turn on yellow. Run time delay routine (5s) 3 times for 15 sec delay. Turn on green. Run time delay routine (5s) 10 times for 50sec delay. Turn on green and advanced green. Run time delay routine (5s) 2times for 10 sec delay.

6) During this traffic light control if the external interrupt goes LOW (LDR is covered), the following interrupt service routine is processed: 7) 8) 9) Turn all lights off, run the delay_less routine (0.5s). Turn all lights on, run the delay_less routine (0.5s). Return to normal traffic light control.

Explanation: The basic essence of the algorithm is to use the external interrupt in the 8051 microcontroller to get the leds blinking as soon as LDR is covered To get the delay durations of the instructions are timed and run in a loop as shown in the calculations and a time quantum of 5 sec is generated. This quantum is repeated adequate number of times to obtain the right duration as given in the problem. Now, the input of the LDR is fed to External interrupt pin (INT1). The LDR circuitry is made in such a way, that if the LDR is exposed to light, we get HIGH as output, and if the LDR is covered, we get LOW as output. As soon as we get a LOW, we immediately jump to the blink routine, in which lights are off for 0.5s and on for 0.5s. After one cycle of the blinking, the code starts running again (& if the LDR is still covered again the blink routine will run and so on).

Assembly Language Code: // PIN 2 -P1.5 // PIN 4 -P1.4 // PIN 6 -P1.3 // PIN 8 -P1.2 BLUE GREEN YELLOW RED

// INT1 IS USED for generating Interrupt ORG 0FFF3H LJMP LDR ORG 8000H LDR: MOV P1, #00111100B ACALL QSDELAY_LESS MOV P1, #00000000B ACALL QSDELAY_LESS RETI ORG 8100H MOV IE, #10000100B LOOP: MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY MOV P1, #00000100B ACALL QSDELAY

// Interrupt Routine address

//Start address of main program //LED blinking, when LDR covered (Interrupt) //All leds on //All leds off

//Main program

//Red led for 1 min //Each delay of 5sec, called 12 times

MOV P1, #00001000B ACALL QSDELAY MOV P1, #00001000B ACALL QSDELAY MOV P1, #00001000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B ACALL QSDELAY MOV P1, #00010000B MOV P1, #00110000B ACALL QSDELAY MOV P1, #00110000B ACALL QSDELAY LJMP LOOP

//Yellow led for 15 secs //Each delay of 5sec, called 3 times

//Green led for 50 secs //Each delay of 5sec, called 10 times

//Advanced Green (Blue) + Green led for for last 10secs //Each delay of 5sec, called 2 times

QSDELAY: MOV R5, #37 H3: MOV R4, #248 H2: MOV R3, #255 H1: DJNZ R3, H1 DJNZ R4, H2 DJNZ R5, H3 RET

//5 sec delay // These values differ from the above calculated // values due to diference in crystal frequency

QSDELAY_LESS: //Delay of 0.5ecs MOV R4, #248 H2_LESS: MOV R3, #255 H1_LESS: DJNZ R3,H1_LESS DJNZ R4,H2_LESS RET END

Discussion:

Shubham Mahajan (08EC3506)

In this experiment, we learnt basics of controlling the external interrupt and delay generation in the program execution. As soon as the interrupt is activated (LDR is covered) the PC goes to the specified location of INT1 (address 0013H), there the instruction present is LJMP 0FFF3H. Therefore, the interrupt service routine should be written at 0FFF3H. To get the delay durations, the instructions are timed and run in a loop as shown in the calculations and a time quantum of 5 sec is generated. This 5sec quantum is used to generate other delays. The external interrupt gets activated when LOW, therefore the LDR has to be connected accordingly. The resistance of the resistor to be connected in series with LDR can be calculated as approximately half of the resistance when on lighting conditions and the covered conditions. The output of the LDR is to be passed through comparator to get the required digital output.

Discussion:

Vaibhav (08EC3501)

In this experiment, we designed a Traffic Light Controller in which we got familiarized with the port programming in 8051 and learnt how to perform specific tasks with the help of interrupts. The LEDs are made to glow by providing them suitable signal using one of the ports of the 8051. The 8051 has four 8bit I/O ports. The ports are used as default output ports for our purpose. We used port P1. It is to be ensured that the LEDs are connected via suitable resistors to avoid any damage to them. When the LDR is covered, the interrupt gets activated with the help of a voltage-divider followed by a comparator circuit that makes the INT1 pin HIGH and LOW accordingly, as LDR is covered or uncovered. The LDR circuit has to be connected in such a way that the external interrupt is activated when LDR is covered. The value the resistance to be connected in series with LDR can be taken around the mean of the resistance when it is covered and exposed, so that we get a suitable variation of voltage levels which can be fed to a comparator to generate digital HIGH and LOW signals. When the interrupt service routine for INT1 is called, the PC goes to a specified memory location- 0013H, which has the instruction - LJMP 0FFF3H. Therefore, we should write the interrupt service routine at location 0FFF3H. The specified time delays for each of the LEDs are created with the help of a time quantum of 5 second (and 0.5 sec) that is generated by running instructions in a loop a particular number of times as shown in the calculations. The quantum is called multiple number of times as needed and the instruction is implemented to glow the particular LED.

Potrebbero piacerti anche