Traffic Light System using ARM 7

 

 Code : 

#include<lpc214x.h>                           // Include LPC2138 library.
void delay(unsigned int a);                   // Delay between 2 leds.
int main()                                               // Main function starts.
{
PINSEL0 = 0X00000000;                   // Port 0 is set to first config.
IODIR0 = 0X00000007;                     // Set P0.0 ,P0.1 & P0.2 in output config. 
IOSET0  = 0X00000007;                   // Set  P0.0 ,P0.1 & P0.2 to high. 
while(1)                                              // Infinite Loop
{
IOCLR0 = 0X00000001;                   // Red led turned on.
delay(4000);                                      // Wait.
IOSET0  = 0X00000001;                  // Red led turned off.
IOCLR0 =  0X00000002;                 // Yellow led turned on.

delay(2000);

IOSET0  = 0X00000002;                // Yellow led turned off.
IOCLR0 =  0X00000004;               // Green led turned on.
                    
delay(1000);                                   // Wait
                                                             
IOSET0  = 0X00000004;                // Green led turned off.

}
}
void delay(unsigned int a)                        // Delay function
{
unsigned int b;                                 // Assigning integer b. 
{
for(b=0;b<=1000*a;b++);        // For loop for delay
}
}


:  Circuit Diagram

 Leds are connected in sinking modes. Sinking mode is when cathode of  LED is connected to Port of 2138 and anode is connected to Vcc.

 

 3 leds are connected to represent 3 lights of signal ( Red , Green , Yellow ). 



Traffic Light  Result   : 

 Initially we make the ports(P0.0)(P0.1)(P0.2) high for the leds to turn off.

  As soon as port(P1.0) becomes low the red led forward biases and it turns on.

A delay function is used to provide an interval between 2 leds.

Once the delay time completes the port turns high the led switches off and now the 2nd port turns low and yellow light turns on.

This keeps on going because we have used a while infinite loop.

Comments