Question: Suppose we want to write a program that turns on the green light (LED) for Tgreen = 25 seconds, then turns off the green light
Suppose we want to write a program that turns on the green light (LED) for Tgreen = 25 seconds, then turns off the green light and turns on the yellow light for Tyellow = 3 seconds, and finally turns off the yellow light and turns on the red light for Tred = 18 seconds. Furthermore, we have a Global Positioning System (GPS) receiver that outputs a pulse (a rising edge) once every second and is connected to the TIMER0 clock input via I/O pin RA1. Assume fosc = 4MHz.
a) Write the code required to initialize the PORTs and TIMER0 for the setup described above.
b) What prescalar value must be chosen to support the generation of an interrupt for the given time intervals.
c) What initial values must be written to the TIMER0 (TMR0H | TMR0L) register so the timer sets the interrupt flag after Tgreen, Tyellow, and Tred seconds, respectively. Show your work!
d) Based on part (b), write the MAIN part of the program that uses polling of the TIMER0 interrupt flag to implement the above traffic light application. Note that the interrupt flag will be set regardless of the fact that interrupts are enabled or not. DO NOT USE TIMING LOOPS!
Tgreen yellow T, red Red Yellow RD1 GPS Receiver RA1 PIC16F18875 >Green Tgreen yellow T, red Red Yellow RD1 GPS Receiver RA1 PIC16F18875 >Green
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
