// traffic light
#include
const uint32_t led_mask[] = {1UL << 18, 1UL << 19, 1UL << 1};
// LED #0, #1 are port B, LED #2 is port D
void LED_Config(void);
void LED_Set(void);
void LED_Clear(void);
__INLINE static void LED_On (uint32_t led);
__INLINE static void LED_Off (uint32_t led);
void Delay(uint32_t nCount);
int main(void)
{
// VARIABLE DECLARATION IF REQUIRED
SystemCoreClockUpdate(); // Optional- Setup SystemCoreClock variable
// Configure LED outputs
LED_Config();
while(1){ // YOUR CODE HERE
};
}
void Delay(uint32_t nCount) // delay subroutine
{
while(nCount--)
{
}
}
/*----------------------------------------------------------------------------
LED pin config
*----------------------------------------------------------------------------*/
void LED_Config(void)
{
/* Enable Clock to Port B & D */
/* Pin PTB18 is GPIO */
/* Pin PTB19 is GPIO */
/* Pin PTD1 is GPIO */
/* switch Red/Green LED off */
/* enable PTB18/19 as Output */
/* switch Blue LED off */
/* enable PTD1 as Output */
return;
}
/*---------------------------------------------------------------------------
Switch on LEDs
*---------------------------------------------------------------------------*/
void LED_Set(void)
{
LED_On(0); // RED
LED_On(1); // GREEN
LED_On(2); // BLUE
return;
}
/*---------------------------------------------------------------------------
Switch off LEDs
*---------------------------------------------------------------------------*/
void LED_Clear(void)
{
LED_Off(0); // RED
LED_Off(1); // GREEN
LED_Off(2); // BLUE
return;
}
/*---------------------------------------------------------------------------
Switch on LED (just one)
*---------------------------------------------------------------------------*/
__INLINE static void LED_On (uint32_t led) {
if (led == 2) FPTD->PCOR = led_mask[led];
else FPTB->PCOR = led_mask[led];
}
/*—————————————————————————
Switch off LED (just one)
*—————————————————————————*/
__INLINE static void LED_Off (uint32_t led) {
if (led == 2) FPTD->PSOR = led_mask[led];
else FPTB->PSOR = led_mask[led];
}