i just wanted to ask now the only part left is .the working of the leds.. so .besides interrupts is there another way .. and if there are interrupts ..so i have to initialise the interrupts and .. in the interrupt routine inclide the workign of the leds...
There have been extensive discussions on when to use and not use interrupts. The truth is that you can do it either way. If you revisit the modified code I earlier posted, I placed the servicing for the A/D and the PWM on the interrupts service routine and I put the traffic light LEDs on the regular polling loop.
I prefer to use interrupts only when absolutely necessary. I placed the A/D conversion on the timer2 interrupt service routine so that it is synchronized with the PWM chopping frequency. Here is a link to similar thread that explains that.
Regarding the LED traffic light, I had placed it on the regular polling loop. However if you use a software delay loop, the periodic interrupts to service the PWM will introduce an accumulating error in the delay time. A delay set for 5 sec might stretch to longer than that (e.g. 5.5 sec) depending upon the percentage of time spent on the ISR vs. polling loop.
That can be easily solved by a using a hardware timer (timer0 or timer1) which you can regularly poll. You can easily poll the hardware timer faster than once every 1 msec (equivalent to a 5000 instruction program loop). This will introduce a non-accumulating error of less than 1 msec in the 5 second delay.
Of course, you can also place the LED traffic light in the interrupt service as you suggested. If timer2 is used to trigger interrupts, it can be used as fixed time delay which you can count to generate an overall delay of a few seconds for your traffic light.