int main() { SysTick_Config(SystemCoreClock/100); magazyn = malloc(sizeof(Element)*1200); Timer3Conf(); Joystick_Initialize(); Buttons_Initialize(); initDisplay(); lcdClean(); Timer3Disable(); Timer1Conf(); lcdMenu(); while(1) { while(tickCounter<10); tickCounter=0; switch(Buttons_GetState()) { case BUTTON_INT0: //lcdClean(); initSnake(); game = 1; while(game == 1) { //while(tickCounter<10); //tickCounter=0; inputControl = 0; switch(Joystick_GetState()) { case JOYSTICK_UP: inputControl = 1; break; case JOYSTICK_LEFT: inputControl = 2; break; case JOYSTICK_DOWN: inputControl = 4; break; case JOYSTICK_RIGHT: inputControl = 8; break; default: inputControl = oldControl; } if(inputControl == forbidden) inputControl = oldControl; if(reactCount > 0) { game = react(inputControl); --reactCount; } } lcdString(250, 150, "Koniec gry"); while(1); break; case BUTTON_KEY1: lcdString(250, 150, "Opcja 2"); while(1); break; case BUTTON_KEY2: lcdString(250, 150, "Opcja 3"); while(1); break; } } return 0; }
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)); } } }