From c3f4417efaa489c41e5d5d44fb28ae01e65ff6bc Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Thu, 25 Aug 2022 02:24:01 +0200 Subject: Fixed a bug of the pedestrain traffic timer where it would restart from 5 to 1 again and Added comments for the whole project and added timers as a member of the Traffic struct to add more generlization of the --- trafficlight.h | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'trafficlight.h') diff --git a/trafficlight.h b/trafficlight.h index f1f94a9..c449609 100644 --- a/trafficlight.h +++ b/trafficlight.h @@ -1,25 +1,16 @@ #include #include -#include #include "tivaware.h" -#define TIVA_CLK 16e6 -#define GREEN_PERIOD TIVA_CLK * 5 -#define YELLOW_PERIOD TIVA_CLK * 2 -#define RED_PERIOD TIVA_CLK * 7 -#define RED 1 -#define YELLOW 2 -#define GREEN 3 +#define TIVA_CLK 16e6 //16MHz clock +#define GREEN_PERIOD TIVA_CLK * 5 // 5 seconds +#define YELLOW_PERIOD TIVA_CLK * 2 // 2 seconds +#define RED_PERIOD TIVA_CLK * 7 // 7 seconds +#define RED 1 +#define YELLOW 2 +#define GREEN 3 -typedef struct Traffic{ - uint8_t cur_color; - uint32_t port; - uint8_t red; - uint8_t yellow; - uint8_t green; -} Traffic; - typedef struct Bcd{ uint32_t port; uint8_t A; @@ -28,21 +19,33 @@ typedef struct Bcd{ uint8_t D; } Bcd; +typedef struct Traffic{ + uint8_t cur_color; + uint32_t port; + uint8_t red; + uint8_t yellow; + uint8_t green; + uint32_t timer; +} Traffic; + extern Traffic tf1; extern Traffic tf2; extern Traffic tf_ped; + extern Bcd bcd1; extern Bcd bcd2; extern Bcd bcd_ped; + extern bool switch_pressed; + + extern uint32_t period_1; extern uint32_t period_2; extern uint32_t period_3; void TrafficInit(); -void Traffic_Handler(Traffic *tf, uint32_t timer); +void Traffic_Handler(Traffic *tf); void set_tf_color(Traffic tf, uint8_t color); void PortInit(uint32_t port, uint32_t clk, uint32_t input, uint32_t output); void TimerInit(uint32_t timer, void(*timer_handler)(), uint32_t clk, uint32_t delay); void BcdWrite(Bcd bcd, uint32_t timer, bool ped); - -- cgit v1.2.3