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; }
void flash_main(void){ #else void main(void){ #endif BYTE buffer[30]; char inputBuffer[STRING_LENGTH]; INT8 pointer = 0; BOOL stop = FALSE; BOOL write = FALSE; char c; char *menuText[] = {(char*)" CPU write?", (char*)" DMA write?"}; BYTE command; BOOL unUsed; initFlash(); // Clearing buffers memset(buffer,0,sizeof(buffer)); memset(inputBuffer,0,sizeof(inputBuffer)); // Setting up UART UART_SETUP(0,57600,HIGH_STOP); UTX0IF = 1; // Set UART 0 TX interrupt flag while(getJoystickDirection() != CENTRED); //Displaying the stored flash message. lcdUpdateLine(LINE1,(char*)"Last written:"); if((unUsed = flashUnused((BYTE*)testData, STRING_LENGTH))) { lcdUpdateLine(LINE2,(char*)"Unused"); } else { scrollText((char*) testData, STRING_LENGTH); } while(getJoystickDirection() != CENTRED); while(getJoystickDirection() == CENTRED); while(getJoystickDirection() != CENTRED); // User decides whether to use CPU or DMA to write flash or to abort. command = lcdMenu(menuText,2); if(command == ABORT_MENU) { return; } // Uart communication lcdUpdate((char*)"Enter UART", (char*)"data"); printf((char*)"\n\nFlash Programming\n"); printf((char*)"Press a key\n\n"); uartGetkey (); // wait for a key to be pressed or the application to be ended if (stopApplication() ) return; else { inputBuffer[0] = U0DBUF; halWait(5); USART0_FLUSH(); inputBuffer[1] = U0DBUF; } // Printing the previously written data printf((char*)"\nLast written:\n"); if(unUsed) { printf((char*)"Unused\n"); } else { printf((char*)"%s\n",&testData); } //Aquiring new data: printf((char*)"\n\nType data to be written.\nWill be printed to the LCD next time."); printf((char*)"\n(ENTER: store in flash, ESC: abort)\n\n"); memset(inputBuffer,0,STRING_LENGTH); while(!stop) { c = getkey(); U0DBUF = c; switch (c){ case ENTER: inputBuffer[pointer] = 0; printf((char*)"\n\nTo write: %s\nENTER if OK.\n",inputBuffer); if(getkey() == ENTER) { // Write data to flash; stop = TRUE; write = TRUE; } else { // Reaquire data. printf((char*)"\nEnter text:\n"); pointer = 0; } break; case BACK_SPACE: // Erasing the last typed data. if (pointer > 0) { pointer--; inputBuffer[pointer] = ' '; } break; case ESC: // Abort Flash write. stop = TRUE; write = FALSE; break; default: // Add typed data to buffer. if (pointer < STRING_LENGTH-1) { inputBuffer[pointer] = c; pointer++; } break; } } INT_GLOBAL_ENABLE(INT_OFF); // Updating the flash if asked to. if(write == TRUE) { if(command == 0) { halFlashWritePage((BYTE*) &inputBuffer, buffer, PAGE_NUMBER); } else { writeFlashUsingDMA((BYTE*) &inputBuffer, STRING_LENGTH, PAGE_ADDRESS, TRUE); } printf((char*)"\nUpdated:"); printf((char*)" %s\n",(char __code*) (PAGE_NUMBER << 10)); lcdUpdateLine(LINE1,(char*)"Updated"); } else { printf((char*)"\nNot updated\n"); lcdUpdateLine(LINE1,(char*)"Not updated"); } lcdUpdateLine(LINE2,(char*)"LEFT to continue"); // Done haltApplicationWithLED(); return; }