//------------------------------------------------------------------------------------------------- // Public functions //------------------------------------------------------------------------------------------------- void main(void) { // Initialize leds (configure leds' pins as digital outputs) ansel.AN3 = 0; // RA4 trisa.RA4 = 0; trisa.RA5 = 0; trisb.RB7 = 0; // Indicate current temperature displaying PIN_LED_MAXIMUM_TEMPERATURE = 0; PIN_LED_CURRENT_TEMPERATURE = 1; PIN_LED_MINIMUM_TEMPERATURE = 0; // Initialize the button (configure the button pin as digital input) ansel.AN0 = 0; trisa.RA0 = 1; // Configure modules ScreenInitialize(); TemperatureInitialize(); // Enable interrupts intcon.PEIE = 1; intcon.GIE = 1; while (1) { // Wait for the button to be pressed while (!PIN_BUTTON); Current_State++; if (Current_State > STATE_SLEEP) Current_State = STATE_MAXIMUM_TEMPERATURE; switch (Current_State) { case STATE_MAXIMUM_TEMPERATURE: PIN_LED_MAXIMUM_TEMPERATURE = 1; PIN_LED_CURRENT_TEMPERATURE = 0; PIN_LED_MINIMUM_TEMPERATURE = 0; break; case STATE_CURRENT_TEMPERATURE: PIN_LED_MAXIMUM_TEMPERATURE = 0; PIN_LED_CURRENT_TEMPERATURE = 1; PIN_LED_MINIMUM_TEMPERATURE = 0; break; case STATE_MINIMUM_TEMPERATURE: PIN_LED_MAXIMUM_TEMPERATURE = 0; PIN_LED_CURRENT_TEMPERATURE = 0; PIN_LED_MINIMUM_TEMPERATURE = 1; break; case STATE_SLEEP: // Clear the leds PIN_LED_MAXIMUM_TEMPERATURE = 0; PIN_LED_CURRENT_TEMPERATURE = 0; PIN_LED_MINIMUM_TEMPERATURE = 0; // Put the maximum modules in low power mode ScreenSetLowPowerMode(1); // Clear the screen TemperatureSetLowPowerMode(1); // Debounce the button now to safely enable the button interrupt just after without spurious button press ButtonDebounceTimer(); // Enable the button interrupt to allow to wake up the system intcon.INT0IF = 0; // Clear interrupt flag as it was previously set when pushing the button intcon.INT0IE = 1; // Put the whole system in idle mode, only an interrupt can wake it ProcessorSetLowPowerMode(1); // The following code is executed when the processor wakes up // The button interrupt occured intcon.INT0IE = 0; // Disable the button interrupt // Reenable all modules TemperatureSetLowPowerMode(0); ScreenSetLowPowerMode(0); // Force the next state temperature displaying to avoid a glitch which can occur during when the screen is reenabled and the DisplayStateTemperature(STATE_MAXIMUM_TEMPERATURE); // Here the button is still pushed, so the state machine will be reentered and the next state will automatically be selected continue; } // Show the requested temperature TEMPERATURE_DISABLE_INTERRUPT(); // Use a "mutex" to avoid the sampling interrupt and this call changing both the display values in a random way DisplayStateTemperature(Current_State); TEMPERATURE_ENABLE_INTERRUPT(); ButtonDebounceTimer(); } }
/************************************************* Function:start() Description:游戏界面入口点 Calls:(none) Input:(none) Output:(none) Return:(int)状态正常0,不正常-1 Others: // 其它说明 *************************************************/ int start() { /* SDL初始化*/ if( SDL_Init( SDL_INIT_VIDEO|SDL_INIT_TIMER ) < 0 ) { printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); return 1; } //创建窗口对象 window = SDL_CreateWindow("F**k Bird", //标题 SDL_WINDOWPOS_CENTERED,//横向剧中 SDL_WINDOWPOS_CENTERED,//纵向居中 SCREEN_WIDTH,//窗口宽度 SCREEN_HEIGHT, //窗口高度 SDL_WINDOW_SHOWN );//窗口样式:创建后立即显示并全屏 if( window == NULL ) { printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); return 1; } //创建渲染器 screenRen = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED| SDL_RENDERER_PRESENTVSYNC); if( screenRen == NULL ) { printf( "Render could not be get! SDL_Error: %s\n", SDL_GetError() ); return 1; } ScreenInitialize(); MoveTimer = SDL_AddTimer(1,MainCallBack,NULL); //事件处理循环 while (1) { SDL_Event e; if (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { break; } else if ( e.type == SDL_KEYDOWN) { // printf("KeyDown"); KeyEventHandler(&(e.key)); } else if (e.type == SDL_MOUSEBUTTONDOWN) { MouseEventHandler(); } } } SDL_UpdateWindowSurface( window ); // SDL_Delay( 5000 ); SDL_DestroyWindow( window ); SDL_Quit(); return 0; }