From b5c1df30961369762e6c9ead8a11f8c9d0f5f8a3 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Tue, 23 Aug 2022 12:32:39 +0200 Subject: Added two timers and made them sync the 2 traffic lights as when one traffic light is green the other is red and vice versa. --- trafficlight.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 trafficlight.c (limited to 'trafficlight.c') diff --git a/trafficlight.c b/trafficlight.c new file mode 100644 index 0000000..a004d98 --- /dev/null +++ b/trafficlight.c @@ -0,0 +1,29 @@ +#include "trafficlight.h" + +void PortInit(uint32_t port, uint32_t clk) { + uint32_t pins = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; + SysCtlPeripheralEnable(clk); + while(!SysCtlPeripheralReady(clk)) {}; + GPIOUnlockPin(port, pins); + GPIOPinTypeGPIOInput(port, GPIO_PIN_0); + GPIOPinTypeGPIOOutput(port, pins); + GPIOPadConfigSet (port, GPIO_PIN_0 | GPIO_PIN_4 | GPIO_PIN_5, + GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); +} + + + +void TimerInit(uint32_t timer, void(*timer_handler)(), uint32_t clk, uint32_t delay) { + reset_color(); + SysCtlPeripheralEnable(clk); + while(!SysCtlPeripheralReady(clk)) {} + TimerDisable(timer, TIMER_BOTH); + TimerConfigure(timer, (TIMER_CFG_PERIODIC)); + TimerLoadSet(timer, TIMER_BOTH, delay); + TimerIntUnregister(timer, TIMER_BOTH); + TimerEnable(timer, TIMER_BOTH); + TimerIntRegister(timer, TIMER_BOTH, timer_handler); + TimerIntEnable(timer, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); +} + + -- cgit v1.2.3