/*---------------------------------------------------------------------------- * main: blink LED and check button state *----------------------------------------------------------------------------*/ int main (void) { int32_t max_num = LED_GetCount() - 1; int32_t num = 0; int32_t dir = 1; SystemCoreClockConfigure(); // configure HSI as System Clock SystemCoreClockUpdate(); LED_Initialize(); Buttons_Initialize(); SysTick_Config(SystemCoreClock / 1000); // SysTick 1 msec interrupts for (;;) { LED_On(num); // Turn specified LED on Delay(500); // Wait 500ms while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button LED_Off(num); // Turn specified LED off Delay(500); // Wait 500ms while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button num += dir; // Change LED number if (dir == 1 && num == max_num) { dir = -1; // Change direction to down } else if (num == 0) { dir = 1; // Change direction to up } } }
/*---------------------------------------------------------------------------- * main: blink LED and check button state *----------------------------------------------------------------------------*/ int main (void) { int32_t max_num = LED_GetCount(); int32_t num = 0; SystemCoreClockConfigure(); // configure HSI as System Clock SystemCoreClockUpdate(); LED_Initialize(); Buttons_Initialize(); SER_Initialize(); SysTick_Config(SystemCoreClock / 1000); // SysTick 1 msec interrupts for (;;) { LED_On(num); // Turn specified LED on // Delay(100); // Wait 500ms // while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button LED_Off(num); // Turn specified LED off // Delay(100); // Wait 500ms // while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button // num++; // Change LED number // if (num >= max_num) { // num = 0; // Restart with first LED // } // printf ("Hello World\n\r"); } }
/*---------------------------------------------------------------------------- * blinkLED: blink LED and check button state *----------------------------------------------------------------------------*/ void blinkLED(void const *argument) { int32_t max_num = LED_GetCount(); int32_t num = 0; for (;;) { LED_On(num); // Turn specified LED on osSignalWait(0x0001, osWaitForever); LED_Off(num); // Turn specified LED off osSignalWait(0x0001, osWaitForever); num++; // Change LED number if (num >= max_num) { num = 0; // Restart with first LED } } }
int main (void) { int32_t max_num = LED_GetCount() - 1; int32_t num = 0; int32_t dir = 1; uint32_t keyMsk, adcVal; int32_t key = -1; int32_t adc = -1; SystemCoreClockUpdate(); LED_Initialize(); /* LED Initialization */ ADC_Initialize(); /* A/D Converter Init */ Buttons_Initialize(); /* Button initialization */ GLCD_Initialize(); /* Initialize the GLCD */ SysTick_Config(SystemCoreClock/100); /* Generate interrupt each 10 ms */ GLCD_SetBackgroundColor (GLCD_COLOR_WHITE); GLCD_ClearScreen (); GLCD_SetBackgroundColor (GLCD_COLOR_BLUE); GLCD_SetForegroundColor (GLCD_COLOR_WHITE); GLCD_SetFont (&GLCD_Font_16x24); GLCD_DrawString (0*16, 0*24, " STM32303C-EVAL Demo"); GLCD_DrawString (0*16, 1*24, " Blinky Example "); GLCD_DrawString (0*16, 2*24, " www.keil.com "); GLCD_SetBackgroundColor (GLCD_COLOR_WHITE); GLCD_SetForegroundColor (GLCD_COLOR_BLUE); GLCD_DrawString (0*16, 5*24, "LEDs: "); GLCD_DrawString (0*16, 6*24, "AD value: "); GLCD_DrawString (0*16, 7*24, "Buttons : "); GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); GLCD_DrawString (9*16, 5*24, "0123"); while (1) { /* Force refresh */ key = -1; adc = -1; if (LEDOn) { LEDOn = 0; LED_On (num); /* Turn specified LED on */ GLCD_SetForegroundColor (GLCD_COLOR_RED); GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]); } if (LEDOff) { LEDOff = 0; LED_Off (num); /* Turn specified LED off */ GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]); num += dir; /* Change LED number */ if (dir == 1 && num == max_num) { dir = -1; /* Change direction to down */ } else if (num == 0) { dir = 1; /* Change direction to up */ } } keyMsk = Buttons_GetState(); /* Show buttons state */ if (key ^ keyMsk) { GLCD_SetForegroundColor (GLCD_COLOR_BLACK); if (keyMsk & KEY_USER ) { GLCD_DrawString (9*16, 7*24, "Key"); } GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); if (!(keyMsk & KEY_USER )) { GLCD_DrawString (9*16, 7*24, "Key"); } } ADC_StartConversion(); /* Show A/D conversion bargraph */ adcVal = ADC_GetValue(); if (adc ^ adcVal) { adc = adcVal; GLCD_SetForegroundColor (GLCD_COLOR_GREEN); GLCD_DrawBargraph (9*16, 6*24, 160, 20, (adcVal * 100) / ((1 << ADC_GetResolution()) - 1)); } } }