//////////////////////////////////////////////////////////////////////////////////////// //初始化串口控制器 //sysclk:系统时钟(Mhz) void usmart_init(u8 sysclk) { #if USMART_ENTIMX_SCAN==1 Timer2_Init(1000,(u32)sysclk*100-1);//分频,时钟为10K ,100ms中断一次,注意,计数频率必须为10Khz,以和runtime单位(0.1ms)同步. #endif usmart_dev.sptype=1; //十六进制显示参数 }
//////////////////////////////////////////////////////////////////////////////////////// //初始化串口控制器 void usmart_init(u8 sysclk) { #if USMART_ENTIM2_SCAN==1 Timer2_Init(1000,(u32)sysclk*100-1);//分频,时钟为10K ,100ms中断一次 #endif usmart_dev.sptype=1; //十六进制显示参数 }
//////////////////////////////////////////////////////////////////////////////////////// //初始化串口控制器 void usmart_init(u8 sysclk,u32 bound) { NVIC_InitTypeDef NVIC_InitStructure; #if USMART_ENTIM2_SCAN==1 Timer2_Init(1000,(u32)sysclk*100-1);//分频,时钟为10K ,100ms中断一次 #endif #ifdef USEING_USMART #if USEING_USMART==1 uart_init(bound); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启中断 #endif #if USEING_USMART==2 uart2_init(bound); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启中断 #endif #endif usmart_dev.sptype=1; //十六进制显示参数 }
// Initialization function for device, // Call Init_Device() from your main program void Init_Device(void) {Oscillator_Init(); Timer_Init(); // UART_Init(); // ADC_Init(); Port_IO_Init(); SPI_Init(); Timer2_Init(); Interrupts_Init(); one = 0; two = 0; msek = 0; TR2 = 1; // Timer0 enabled // reset reset = 1; while (!one); // 100ucek 1 reset = 0; while (!two); // 5 mcek 0 _nop_(); TR2 = 0; }
int main(void) { Stm32_Clock_Init(9); //system clock init always init first IO_Init(); delay_init(72); //delay init uart_init(72,115200); //uart init PWM4_Init(150,18000); // ultra ping sig // PWM2_2Init(100,1800); //count to 100, freq/1800 //IR aqusition pulse Timer3_Init(65535,256); //time refrence for echo/ultrasonic // setup 5 for motors? Timer2_Init(65535,10); // motor try1 motor_Init(); EXTIX_Init(); // Adc_Init(); // LED0_PWM_VAL2_2=0x44; // LED0_PWM_VAL2_1=0x34; LED0_PWM_VAL4=0x34; IRO=0;//turn on IR LEDs while(1) { printf("adcx1\tadcx2\tadcx3\tadcx4\tGyro\tBatt\techo\n"); printf("%u\t%u\t%u\t%u\t%u\t%u\t%u",adcx1,adcx2,adcx3,adcx4,Gyro_raw,Batt,echo); printf("\n"); // USART1->DR=echo/0xff; // while((USART1->SR&0X40)==0);//wait for transfer to compleate LED0=!LED0; delay_us(100000);//wait for the end of transmission } }
int main(void){unsigned short score; PLL_Init(); // Set the clocking to run at 80MHz from the PLL. LCD_Init(); // Initialize LCD LCD_Goto(0,0); score =0; long v2; LCD_SetTextColor(255,0,0); // yellow= red+green, no blue printf("score: %d", score); LCD_DrawLine(10,16,310,16,BURNTORANGE); Timer2_Init(4000000); // 20 times a second Timer3_Init(7256); // 11.025 KHz InitEnemy(); InitBunker(); InitPlayer(); InitMissile(); InitLaser(); Random_Init(1); EnableInterrupts(); Fireflag=1; while(1){ if(Semaphore){ DrawBuffer1(); Semaphore = 0; } } }
int main(void){ DisableInterrupts(); TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); PF1Init(); //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer ADC0_Init(); Game_Init(); SwitchLed_Init(); Sound_Init(); Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256 GameOverFlag = 0; EnableInterrupts(); while(1){ while(Semaphore==0){}; Semaphore = 0; if(GameOverFlag){ State_GameOver(); } else{ Draw_GameFrame(); // update the LCD } if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over Delay100ms(2);//Delay 200ms GameOverFlag = Check_GameOver(); //SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed } } }
//******** OS_Launch *************** // start the scheduler, enable interrupts // Inputs: number of 12.5ns clock cycles for each time slice // you may select the units of this parameter // Outputs: none (does not return) // In Lab 2, you can ignore the theTimeSlice field // In Lab 3, you should implement the user-defined TimeSlice field // It is ok to limit the range of theTimeSlice to match the 24-bit SysTick void OS_Launch(unsigned long theTimeSlice){ Timer2_Init(80); Timer1A_Init(40000); RunPt = SchedulerPt; //make the first thread active NVIC_ST_RELOAD_R = theTimeSlice - 1; //timeslice is given in clock cycles NVIC_ST_CTRL_R = 0x07; //enable systick StartOS(); while(1); }
int main(void){ TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz DisableInterrupts(); Random_Init(1); Nokia5110_Init(); Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); SysTick_Init(); // initialize Timer2 after Nokia5110_Init because of // error-prone registers operations (old and new registers // are not working good together) // 80MHz/11,025 cycles, which is about 7256 Timer2_Init(7256); Ports_Init(); InitSprites(NumberOfEnemies); RestartGame(); // Countdown, after which all interrupts are enabled! // print 3 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print 2 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print 1 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print GO Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); EnableInterrupts(); while(1){ if (Flag == 1) { Nokia5110_DisplayBuffer(); Flag = 0; } } }
static void prvSetupHardware( void ) { LEDS_Init(); LEDS_Off(RED); LEDS_Off(BLUE); LEDS_Off(ORANGE); LEDS_Off(GREEN); LEDS_Off(RED2); LEDS_Off(GREEN2); Timer2_Init(); return; }
int main() { MCU_Init(); Timer1_Init(); Timer2_Init(); IO_Init(); ADC_Init(); Timer1_ON; //start 16 bit timer1 Timer2_ON; //start 16 bit timer2 ADC_ON; //turns on ADC module while(1) { ADC_Convert(); } }
int main(void){ int AnyLife = 1; int i; TExaS_Init(NoLCD_NoScope); // set system clock to 80 MHz // you cannot use both the Scope and the virtual Nokia (both need UART0) Random_Init(1); Nokia5110_Init(); EnableInterrupts(); // virtual Nokia uses UART0 interrupts Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0); Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0); Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_DisplayBuffer(); // draw buffer Delay100ms(50); // delay 5 sec at 80 MHz Init(); Timer2_Init(80000000/30); // 30 Hz while(AnyLife){ while(Semaphore == 0){}; Semaphore = 0; // runs at 30 Hz AnyLife = 0; for(i=0; i<4 ; i++){ AnyLife |= Enemy[i].life; } Draw(); } Nokia5110_Clear(); Nokia5110_SetCursor(1, 1); Nokia5110_OutString("GAME OVER"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Nice try,"); Nokia5110_SetCursor(1, 3); Nokia5110_OutString("Earthling!"); Nokia5110_SetCursor(2, 4); Nokia5110_OutUDec(1234); Nokia5110_SetCursor(0, 0); // renders screen while(1){ } }
int main() { Timer2_Init(); //Initialize Timer2 USART0_Init(9600); //Initialize USART0 with baud rate of 9600 USART1_Init(9600); //Initialize USART1 with baud rate of 9600 _delay_ms(500); //delay 500 milisecond sei();//Enable Gloabal Interrupt while(1)//dead loop { } return 0; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ u32 i = 0; IWDG_Init(); EN_GPIO_Init(); Relay_Status_No_Init(); Signal_Relay_OFF(); LED_OFF(LED_A_1_G_Group ,LED_A_1_G ); LED_OFF(LED_B_1_G_Group ,LED_B_1_G ); LED_OFF(LED_B_2_G_Group ,LED_B_2_G ); LED_OFF(LED_A_2_G_Group ,LED_A_2_G ); LED_OFF(LED_A_1_R_Group ,LED_A_1_R ); LED_OFF(LED_B_1_R_Group ,LED_B_1_R ); LED_OFF(LED_B_2_R_Group ,LED_B_2_R ); LED_OFF(LED_A_2_R_Group ,LED_A_2_R ); LED_OFF(LED_NS_Group ,LED_NS ); LED_OFF(LED_ER_Group ,LED_ER ); Timer2_Init(); ADC1_Init(); uart_init(115200); IWDG_ReloadCounter(); while (1) { IWDG_ReloadCounter(); Power12V_Check(); Voltage_Check(); Status_Process(); if( t1s_SW_counter < 500 ) { t1s_SW_counter = 501; IWDG_ReloadCounter(); SW_Status_Check(); } } }
//***************Timer3A_Handler**************** //Plays the Tetris Sound onces at the beginning of each round //Then it deactivates itself until the next round begins //Input: none //Output: none void Timer3A_Handler(void){ TIMER3_ICR_R = 0x01; TIMER3_CTL_R = 0x0000000; //disable TIMER0 // TIMER1_CTL_R = 0x0000000; //disable TIMER1 // TIMER2_CTL_R = 0x0000000; //disable TIMER2 for(int num =0; num < 133; num++){//133 if(TETRIS[num] == Z1) i=5;else i =150; //check if Z1 change the period to 5 Sound_Play2(TETRIS[num]); //play the note Delay10ms(i); //delay after each note usign the value of i } NVIC_ST_CTRL_R =0; //disable SysTick after the song has been played // TIMER0_CTL_R = 0x0000001; //enable TIMER0 // TIMER2_CTL_R = 0x0000001; //enable TIMER2 DisableInterrupts(); Timer0_Init(70000000); //1000000 Timer1_Init(7255); Timer2_Init(30000000); EnableInterrupts(); TIMER3_CTL_R = 0x0000000; //disable TIMER1A }
/************************************************************************************* * 函数名称:main() * 参数 :void * 返回值 :void * 描述 :程序主入口main函数 *************************************************************************************/ int main(void) { u16 i,j; u16 t=0; /*****************************初始化****************************************/ //初始化系统时钟,设置时钟为168Mhz // LED_Init(); SysTick_Init(168); TIM4_Init(); // TIM3_init();//pwm TIM5_PWM_Init(); TIM5_PWM_OUTPUT(40,20,10,50); COM6_Init(115200);//串口6初始化 bsp_InitDAC();//这样初始化adc和dac不会出问题 bsp_InitADC(); bsp_InitDAC(); TFTLCD_Init(); Touch_Init(); //EXTI_Configuration(); GUI_Init(); //GUI 初始化 GUI_Clear(); Timer2_Init(20); //初始化LED的GPIO配置 WaveTaskCreat(); while(1) { if(Wave_updat == 1) { Get_Signal(); //Clculate_Signal(); } Updata_signal(); GUI_Exec(); } }
// ******** OS_Init ************ // initialize operating system, disable interrupts until OS_Launch // initialize OS controlled I/O: serial, ADC, systick, LaunchPad I/O and timers // input: none // output: none void OS_Init() { uint8_t counter = 0; Timer2_Init(80000000); //timer2 keeps track oftime OS_DisableInterrupts(); PLL_Init(Bus80MHz); //ADC_Init(0); UART_Init(); // initialize UART //construct linked list for (counter = 0; counter<NUMBEROFTHREADS - 1; counter++) { threadPool[counter].nextTCB = &threadPool[(counter + 1)]; //address of next TCB } threadPool[NUMBEROFTHREADS - 1].nextTCB = '\0'; //lab3 linked list for periodic threads for (counter = 0; counter<NUMBEROFPERIODICTHREADS - 1; counter++) { periodicPool[counter].nextPeriodicThread = &periodicPool[(counter + 1)]; //address of next TCB } periodicPool[NUMBEROFPERIODICTHREADS - 1].nextPeriodicThread = '\0'; DeadPt = &threadPool[0]; //point to first element of not active threads DeadPeriodicPt = &periodicPool[0]; deadCount = NUMBEROFTHREADS; deadPeriodicCount = NUMBEROFPERIODICTHREADS; RunPt = '\0'; SchedulerPt = '\0'; SleepPt = '\0'; PeriodPt = '\0'; //Timer2_Init(20000); //1 ms period for taking time!!!!!! NVIC_ST_CTRL_R = 0; // disable SysTick during setup NVIC_ST_CURRENT_R = 0; // any write to current clears it NVIC_SYS_PRI3_R =(NVIC_SYS_PRI3_R&0x00FFFFFF)|0xE0000000; // priority 7 on systick NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R & 0xFF1FFFFF) | 0x00E00000; //priority 7 on pendsv }
int main(void){ PLL_Init(Bus80MHz); // 80 MHz SYSCTL_RCGCGPIO_R |= 0x20; // activate port F //ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating GPIO_PORTF_DIR_R |= 0x06; // make PF2, PF1 out (built-in LED) GPIO_PORTF_AFSEL_R &= ~0x06; // disable alt funct on PF2, PF1 GPIO_PORTF_DEN_R |= 0x06; // enable digital I/O on PF2, PF1 // configure PF2 as GPIO GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF PF2 = 0; // turn off LED DisableInterrupts(); Timer0A_Init60HzInt(); //updates time every second Timer1_Init(); //sound Timer2_Init(); //Switch_Init(); //interrupts on switch press ST7735_InitR(INITR_REDTAB); ST7735_PlotClear(0,160); play = 0; TIMER1_CTL_R = 0x00000000; EnableInterrupts(); ST7735_Circle(ST7735_BLACK); //drawClockHands(hour, minute, 1); drawDigTime(hour, minute, AMPM); ST7735_SetCursor(2, 14); printf("<"); ST7735_SetCursor(18, 14); printf(">"); drawClockHands(2,30,1); play = 1; TIMER1_CTL_R = 0x00000001; while(1){ } }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { bit restart = 0; unsigned int randnum = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator. PORT_INIT(); // Configure the Crossbar and GPIO. UART0_INIT(); // Initialize UART0. SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. IT1 = 1; // INT1 falling-edge-triggered SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled. EX1 = 1; // Enable External Interrupt 2 SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. Timer0_Init(); //enable timer0 TR0 = 1; Timer2_Init(); TR2 = 1; //enable timer2 // printf("I am running :D \n\r"); while (1) playGame(); }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { bit restart = 0; unsigned int randnum = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator. PORT_INIT(); // Configure the Crossbar and GPIO. UART0_INIT(); // Initialize UART0. SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled. SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. Timer2_Init(); TR2 = 1; //enable timer2 printf("I am running :D \n\r"); while (1) { if (printTime) //if 1 second, print. { printf("Time = %d\n\r", time); printTime = 0; } } }
//////////////////////////////////////////////////////////////////////////***START OF PROGRAM***////////////////////////////////////////////////////////////////////////////////////////////// int main(void){ //Initialization PLL_Init(); // Set the clocking to run at 80MHz from the PLL. LCD_Init(); // Initialize LCD LCD_Goto(10,0); LCD_SetTextColor(255,255,0); // yellow= red+green, no blue printf("Lab 10"); LCD_DrawLine(10,16,310,16,BURNTORANGE); ADC_Initialize(); Timer2_Init(7256); Timer2A_Stop(); SysTick_Init(); ///////////////////////////////////////////////////////////////////////////Set Up Waves/////////////////////////////////////////////////////////////////////////////////////////////// while(1){ //set up for the wave 1 (11 means wave needs to be setup, 10 means wave is set up) if (wave==11) { wavesize=5; enemycount=0; LCD_SetCursor(140,120); LCD_SetTextColor(255,0,0); LCD_PrintString("WAVE ONE"); LCD_SetTextColor(0,0,0); LCD_PrintString("WAVE ONE"); enemy[0].x=50; enemy[1].x=90; enemy[2].x=130; enemy[3].x=170; enemy[4].x=210; for (k=0;k<5;k++) { enemy[k].y=40; enemy[k].s=1; enemy[k].e=0; enemy[k].c=0; enemy[k].b=0; wave=10; } } //set up for wave 2 (22 means wave needs to be setup, 20 means wave is set up) //e: so we don't print eraser more than once //s: so we know the state of the sprite //c; so we don't count the death of a sprite more than once if (wave==21) { wavesize=15; enemycount=0; LCD_SetCursor(140,120); LCD_SetTextColor(255,0,0); LCD_PrintString("WAVE TWO"); LCD_SetTextColor(0,0,0); LCD_PrintString("WAVE TWO"); enemy[0].x=50; enemy[1].x=90; enemy[2].x=130; enemy[3].x=170; enemy[4].x=210; for (k=0;k<5;k++) { enemy[k].y=40; enemy[k].s=1; enemy[k].e=0; enemy[k].c=0; enemy[k].b=0; } for (k=5;k<10;k++) { enemy[k].s=4; //set newer coming enemies to 4, so they don't get counted as dead when they don't arrive yet (count happens after printing) enemy[k].e=0; enemy[k].y=40; enemy[k].x=50; enemy[k].c=0; enemy[k].b=0; } for (k=10;k<15;k++) { enemy[k].s=4; enemy[k].s=4; //set newer coming enemies to 4, so they don't get counted as dead when they don't arrive yet (count happens after printing) enemy[k].e=0; enemy[k].y=64; enemy[k].x=296; enemy[k].c=0; enemy[k].b=0; } wave=20; } //set up for wave 3 //set up for wave 3 if(wave==31) { wavesize=1; enemycount=0; LCD_SetCursor(140,30); LCD_SetTextColor(255,0,0); LCD_PrintString("Time For Ziping"); for(k=0;k<10;k++) {enemy[k].x=0;enemy[k].y=0;enemy[k].s=0;;enemy[k].e=0;} enemy[0].s=1; enemy[0].x=100; enemy[0].y=40; enemy[0].b=0; enemy[0].e=0; wave=30; } ////////////////////////////////////////////////////////////////////////////Update and Print User Ship///////////////////////////////////////////////////////////////////////////////////////// if(Semaphore){ //wait for SysTick Semaphore = 0; //"acknowledge" SysTick ADCData = ADC_In(); Position=(ADCData*.4053751277)+157.0113976; //position 0-2000 xShip = ((Position)*.14)+20; //x pixel coordinate of center of ship (.14 = 280/2000) LCD_DrawBMP(UshipErase,xShipTrail,200); //erase previous image LCD_DrawBMP(userShip,xShip,200); xShipTrail = xShip; ////////////////////////////////////////////////////////////////////////////////////Update Enemies///////////////////////////////////////////////////////////////////////////////////////////// //enemy ship update coordinates for wave 1 (s=1 means alive, s=0 means just dead, s=2 means the moment of death) if (wave==10) { for (k=0;k<5;k++){ if (enemy[k].s == 1) { enemy[k].y = enemy[k].y +1; trainWreckL = xShip-enemy[k].x; //enemy within left boundary of ship trainWreckR = enemy[k].x - xShip; //enemy within right boundary of ship if( (enemy[k].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[k].s = 2; DEATH(); userDeath++; } if (enemy[k].y>=210) {enemy[k].s=0;} } } } //enemy ship update coordinates for wave 2 //enemy ship update coordinates for wave 2 else if (wave==20) { for (k=0;k<5;k++) { if(enemy[k].s==1) { //updates only if object is alive (s==1) if (countx<=92 && wave2==0) { enemy[k].x = enemy[k].x +1; } countx++; if (countx >92 && wave2==0) {wave2=1; countx=0;} if (wave2==1) { for (j=0;j<5;j++) { enemy[j].y=enemy[j].y+1; } wave2=2; countx=0; county++; } if (countx <=92 && wave2==2) { enemy[k].x= enemy[k].x-1; } countx++; if (countx >= 92 && wave2==2 ) {wave2=3; countx=0;} if (wave2==3) { for (j=0;j<5;j++) { enemy[j].y=enemy[j].y+1; } wave2=0; county++; } trainWreckL = xShip-enemy[j].x; //enemy within left boundary of ship trainWreckR = enemy[j].x - xShip; //enemy within right boundary of ship if( (enemy[j].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[j].s = 2; DEATH(); userDeath++; } if (enemy[k].y>=210) {enemy[k].s=0;} } } //fleet 2 if (county==24 || enemycount==10) {enemy[5].s=1; wave3=1;} //activate the bigger ships once there is room vertically, e.i. check if y coordinate has been met if (countx2==24) {enemy[6].s=1;} if (countx2==48 ) {enemy[7].s=1;} if (countx2==72) {enemy[8].s=1;} if (countx2==96) {enemy[9].s=1;} //if (enemy[5].x>=196) {wave2big=1;} //once the enemies get to the edge of the screen, set a flag (wave big) to one if (countx2>=146) {wave2big=1;} for (k=5;k<10;k++) { if(wave3==1 && k==5) {countx2++;} if(enemy[k].s==1 && wave2big==0) { //update coordinates for new ships for wave 2 only if they become active (due to above code) and if max x coordinate hasn't been set enemy[k].x=enemy[k].x+1; } if(enemy[k].y>=210) {enemy[k].s=0;} //enemy dead if off the screen vertically, we don't care if horizontally if(enemy[k].s==1 && wave2big==1) { if(k==5 || k==6) {enemy[k].x=enemy[k].x-1; enemy[k].y=enemy[k].y+1;} if(k==8 || k==9) {enemy[k].x=enemy[k].x+1; enemy[k].y=enemy[k].y+1;} if(k==7 && enemy[k].y<=100) {enemy[k].y=enemy[k].y+1;} } } //fleet 3 if (county==48 || enemycount==10) {enemy[10].s=1; wave4=1;} //activate the bigger ships once there is room vertically, e.i. check if y coordinate has been met if (countx3==24) {enemy[11].s=1;} if (countx3==48 ) {enemy[12].s=1;} if (countx3==72) {enemy[13].s=1;} if (countx3==96) {enemy[14].s=1;} if (countx3>=146) {wave3big=1;} for (k=10;k<15;k++) { if(wave4==1 && k==10) {countx3++;} if(enemy[k].s==1 && wave3big==0) { //update coordinates for new ships for wave 2 only if they become active (due to above code) and if max x coordinate hasn't been set enemy[k].x=enemy[k].x-1; } if(enemy[k].y>=210) {enemy[k].s=0;} //enemy dead if off the screen vertically, we don't care if horizontally if(enemy[k].s==1 && wave3big==1) { if(k==10) {if(enemy[k].y<120 && enemy[k].x==50) {enemy[k].y=enemy[k].y+1;} if(enemy[k].y==120 && enemy[k].x<130) {enemy[k].x=enemy[k].x+1;} if(enemy[k].y>64 && enemy[k].x==130) {enemy[k].y=enemy[k].y-1;} if(enemy[k].y==64 && enemy[k].x>50) {enemy[k].x=enemy[k].x-1;}} if(k==14) {if(enemy[k].y<120 && enemy[k].x==246) {enemy[k].y=enemy[k].y+1;} if(enemy[k].y==120 && enemy[k].x>166) {enemy[k].x=enemy[k].x-1;} if(enemy[k].y>64 && enemy[k].x==166) {enemy[k].y=enemy[k].y-1;} if(enemy[k].y==64 && enemy[k].x<246) {enemy[k].x=enemy[k].x+1;}} if(k==11 || k==13 || k==12) {enemy[k].y=enemy[k].y+1;} } } } ///////////////////////////////////////////////////////////////////////Update User missiles//////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(missile[i].s){ missile[i].y = missile[i].y - 2; //if missile is active, move up the screen if(missile[i].y < 18 ){ missile[i].s = 0; //if the missile has moved off the screen, deactivate it LCD_DrawBMP(UmissileErase,missile[i].x,missile[i].y); //cover up with black } //////////////////////////////////////////////////////////////////Test for Enemy-Missile Collisions (small aliens)/////////////////////////////////////////////////////////////////////////////////////// for(k=0;k<wavesize;k++){ //(missile:11x15, enemy: 24x24) crashTestY = ((enemy[k].y + 24) - missile[i].y); //difference in y-coordinates crashTestXR = (missile[i].x - enemy[k].x); //distance of missile from right border of alien crashTestXL = (enemy[k].x - missile[i].x); //distance of missile from left border of alien if ( ( (crashTestY <5) && (crashTestY > 0) ) && ( ( (crashTestXR < 24) && (crashTestXR > 0 ) ) || ( (crashTestXL < 11)&&(crashTestXL > 0) ) ) ){ enemy[k].s = 2; } } } } /////////////////////////////////////////////////////////////////////Test for Enemy-User Collisions/////////////////////////////////////////////////////////////////////////////////////////////////// /* for(k=0;k<5;k++){ trainWreckL = xShip-enemy[k].x; //enemy within left boundary of ship trainWreckR = enemy[k].x - xShip; //enemy within right boundary of ship if( (enemy[k].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[k].s = 2; DEATH(); userDeath++; } */ //////////////////////////////////////////////////////////////////////////Activate New Missile///////////////////////////////////////////////////////////////////////////////////////////// if(newMissile==3){ while(missile[notActiveSlot].s == 1){ //find a non-active missile in the array if(notActiveSlot == 99){notActiveSlot = 0;} //wrap around if at end of array notActiveSlot++; //check next slot } missile[notActiveSlot].x = xShip + 10; //missile(11x15) aligned to center of ship missile[notActiveSlot].y = 185; //missile firing out 200 - 15 missile[notActiveSlot].s = 1; //activate Timer2A_Start(); //arm sound newMissile=0; //reset button count tester++; } ///////////////////////////////////////////////////////Update Enemy Missiles///////////////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(emissile[i].s==1){ emissile[i].y = emissile[i].y + 2; if(emissile[i].y > 210){ emissile[i].s = 0; LCD_DrawBMP(UmissileErase,emissile[i].x,emissile[i].y); } } } ///////////////////////////////////////////////////////////////////////Test for User Missile Collisions//////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if((emissile[i].s ==1)&&(emissile[i].y >= 185)&& ((((emissile[i].x - xShip)<30)&&((emissile[i].x - xShip)>0))|| (((xShip- emissile[i].x)<11)&&((xShip-emissile[i].x)>0)))){ emissile[i].s = 0; DEATH(); userDeath++; } } ////////////////////////////////////////////////////////////////////////New Enemy Missiles//////////////////////////////////////////////////////////////////////////////////////////////////// //activate new enemy missiles for(k=0;k<wavesize;k++){ if((enemy[k].s)&&(enemy[k].wait == 1)){ //alive and finished (.wait == 1 means countdown done) while(emissile[notActiveSlotE].s == 1){ //find a non-active enemy missile slot in array if(notActiveSlotE == 99){notActiveSlotE = 0;} //wrap around if at end of array else notActiveSlotE++; //check next slot } emissile[notActiveSlotE].x = enemy[k].x + (enemy[k].w / 2); //center horizontal positioning of missile on enemy emissile[notActiveSlotE].y = enemy[k].y + enemy[k].h; //get correct vertical positioning for missile emissile[notActiveSlotE].s = 1; //activate missile enemy[k].wait = 0; //signifying missile fired, reaady for new wait time } } //loading enemies that just fired with new wait times for(k=0;k<wavesize;k++){ if((enemy[k].s)&&(enemy[k].wait == 0)){ //alive and not currently waiting to fire (.wait == 0 means need new time) j = (Random()%60); //get random number from 0-30 if(j < 20){j=20;} //minimum # 20 (3 shots per second max firing) enemy[k].wait = j; } } /////////////////////////////////////////////////////////////////////enemy missile printing////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(emissile[i].s == 1){ LCD_DrawBMP(enemyMissile,emissile[i].x,emissile[i].y);}} /*else if ((emissile[i].s == 0)&&(emissile[i].b==0)){ LCD_DrawBMP(UmissileErase,emissile[i].x,emissile[i].y);} emissile[i].b = 1; }*/ //////////////////////////////////////////////////////////////////////////////missile printing/////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(missile[i].s){ LCD_DrawBMP(userMissile,missile[i].x,missile[i].y); //print if missile is active } } ///////////////////////////////////////////////////////////////////////////enemy ship printing/////////////////////////////////////////////////////////////////////////////////////// /////////////ship printing for wave 1 if(wave==10) { for (k=0;k<5;k++) { if (enemy[k].s ==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 &&enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1, enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e ==0) { LCD_DrawBMP(ExplosionBlack, enemy[k].x,(enemy[k].y)); enemy[k].e=1;} } for (k=0;k<5;k++) { if(enemy[k].s==0 && enemy[k].c==0) {enemycount++; enemy[k].c=1;} //count enemies if s=0 and c=0 } if (enemycount==5) {wave=21;} //new wave is all five enemies are "dead" } /////////////Ship printing for wave 2 if(wave==20) { for (k=0;k<5;k++) { if (enemy[k].s ==1) { LCD_DrawBMP(AlienEnemySmall, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x,(enemy[k].y)); enemy[k].e=1;} } for(k=5;k<10;k++) { if(enemy[k].s==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x, enemy[k].y); enemy[k].e=1;}} for (k=0;k<10;k++) { if(enemy[k].s==0 && enemy[k].c==0) {enemycount++; enemy[k].c=1;} //count enemy if s=0 and c=0 } if (enemycount==20) {wave=31;} //new wave if all ten enemies are "dead" for(k=10;k<15;k++) { if(enemy[k].s==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x, enemy[k].y); enemy[k].e=1;}} } } //close semaphore } //close while loop } //close main
//GAME int main(void){unsigned long i=64,j=0; PLL_Init(); // Set the clocking to run at 80MHz from the PLL. LCD_Init(); // Initialize LCD Piano_Init(); Sound_Init(); ADC_Init(); //initialize ADC ADC_SetChannel(1); //PE2 Missile_Init(); Enemy1_Init(); LCD_Goto(10,0); LCD_SetTextColor(255,0,0); // yellow= red+green, no blue printf("Welcome to Pokemon Capture!"); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); while((GPIO_PORTE_DATA_R&0x01)==0){ LCD_Goto(10,0); printf("Press any button to begin..."); delay_blink(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_blink(); } delay_short(); LCD_SetTextColor(255,255,0); LCD_Goto(0,0); printf("Tragedy has struck Pallet Town! Four Pokemon have escaped from their Pokeballs, and it's your job to put them back where they belong."); delay_long(); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("Use the slider to aim, and when you think you have a shot, press the button to throw your Pokeball."); delay_long(); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_blink(); LCD_Goto(0,0); printf("You only have so many Pokeballs, so be smart where you throw them!"); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("Good luck!"); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_SetTextColor(255,0,0); LCD_Goto(0,0); printf("Captured:"); LCD_SetTextColor(0,255,0); LCD_Goto(14,0); printf("Pokeballs Left:"); LCD_SetTextColor(0,0,255); LCD_Goto(35,0); printf("Accuracy:"); LCD_DrawLine(10,16,310,16,BURNTORANGE); Timer2_Init(7256); // 11kHz SysTick_Init(2666667); //30 Hz EnableInterrupts(); Pokeballs = 25; while(1){ if((25-(hits+misses))==0){ if(kill!=4){ DisableInterrupts(); LCD_SetTextColor(255,0,0); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("Sorry, you were not able to catch all the Pokemon."); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("Try again."); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); while(1){ LCD_Goto(0,0); printf("Press RESET to play again."); delay_blink(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_blink(); } } } if(kill==4){ DisableInterrupts(); LCD_SetTextColor(0,255,255); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("Congratulations! You have captured all the Pokemon!"); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); LCD_Goto(0,0); printf("You are now a Pokemon Master!"); delay_long(); delay_long(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_short(); while(1){ LCD_Goto(0,0); printf("Press RESET to play again."); delay_blink(); LCD_DrawFilledRect(0,0,320,80,0x00); delay_blink(); } } if(Semaphore){ LCD_SetTextColor(255,0,0); LCD_Goto(10,0); LCD_PrintInteger(kill); LCD_SetTextColor(0,255,0); LCD_Goto(30,0); LCD_PrintInteger(25-(hits+misses)); if((25-(hits+misses))<10){ LCD_Goto(31,0); printf(" "); } LCD_SetTextColor(0,0,255); LCD_Goto(45,0); LCD_PrintInteger(hits/(hits+misses)); //draw ship if(Ship_Position>288){ Ship_Position=288; } LCD_DrawBMP(PlayerShip,Ship_Position,220); LCD_DrawFilledRect(0,220,Ship_Position,9,0x00); LCD_DrawFilledRect(Ship_Position+32,220,320-(Ship_Position+32),9,0x00); for(j=0;j<1;j++){ if(Missile[j].life==1){ LCD_DrawBMP(Missile[j].image, Missile[j].x, Missile[j].y); } else{ LCD_DrawFilledRect(Missile[j].x,Missile[j].y,16,18,0x00); } if(Missile[j].y<=18){ LCD_DrawFilledRect(Missile[j].x,Missile[j].y,16,18,0x00); Missile[j].life=0; misses++; } } for(i=0;i<4;i++){ if(Enemy1[i].life!=0){ LCD_DrawBMP(Enemy1[i].image,Enemy1[i].x,Enemy1[i].y); } else{ LCD_DrawFilledRect(Enemy1[i].x,Enemy1[i].y,32,32,0x00); } } LCD_DrawFilledRect(0,17,320,4,0x00); Semaphore = 0; } } }
/******************************************************* * MAIN function, just setup some inits and loops * "soft" real-time event handlers, defined hereafter ********************************************************/ int main(void) { // configuro l'oscillatore interno che mi fornisce Tcy // Fosc = Fin (M/(N1*N2)) // FCY = Fosc/2 PLLFBD = 39; // M = 40 CLKDIVbits.PLLPOST=0; // N2 = 2 CLKDIVbits.PLLPRE=0; // N1 = 2 RCONbits.SWDTEN = 0; //disabilito il watchdog DataEEInit(); //Init Peripheral Pin Selection (QEI and UART) PPS_Init(); control_flags.first_scan = 1; slow_ticks_limit = SLOW_RATE * (FCY_PWM / 1000) - 1 ; medium_ticks_limit = MEDIUM_RATE * (FCY_PWM / 1000) - 1; mposition1 = zero_pos1;//parto dalla posizione iniziale 90 90 90 mposition2 = zero_pos2; mposition3 = zero_pos3; /*mtheta1 = 0; mtheta2 = 0; mtheta3 = 0; x_cart = 0; y_cart = 0; z_cart = 0;*/ coordinates_actual.x = 0; coordinates_actual.y = 0; coordinates_actual.z = 0; coordinates_temp.x = 0; coordinates_temp.y = 0; coordinates_temp.z = 0; angleJoints_actual.theta1 = 0; angleJoints_actual.theta2 = 0; angleJoints_actual.theta3 = 0; angleJoints_temp.theta1 = 0; angleJoints_temp.theta2 = 0; angleJoints_temp.theta3 = 0; update_params(); direction_flags_prev = direction_flags.word; // UARTs init // no need to set TRISx, they are "Module controlled" UART1_Init(); // Setup control pins and PWM module, // which is needed also to schedule "soft" // real-time tasks w/PWM interrupt tick counts DIR1 = direction_flags.motor1_dir;//0; DIR2 = direction_flags.motor2_dir;//1; DIR3 = direction_flags.motor3_dir; //BRAKE1 = 0; //BRAKE2 = 0; DIR1_TRIS = OUTPUT; DIR2_TRIS = OUTPUT; DIR3_TRIS = OUTPUT; //BRAKE1_TRIS = OUTPUT; //BRAKE2_TRIS = OUTPUT; CURRSENSE1_TRIS = INPUT; CURRSENSE2_TRIS = INPUT; CURRSENSE3_TRIS = INPUT; PWM_Init(); // MUST SETUP ALSO ANALOG PINS AS INPUTS AN0_TRIS = INPUT; AN1_TRIS = INPUT; AN2_TRIS = INPUT; ADC_Init(); DMA0_Init(); // SETUP ENCODER INPUTS // QEI inputs are "module controlled" // -> no need to set TRISx QEI1_Init(); QEI2_Init(); // Timers used to acquire Encoder 3 // corresponding PINS set as inputs T1CK_TRIS = INPUT; T4CK_TRIS = INPUT; Timer1_Init(); Timer2_Init(); Timer4_Init(); // Timer5 used to schedule POSITION loops Timer5_Init(); //Input capture IC1_Init(); IC2_Init(); // TEST PIN TEST_PIN_TRIS = OUTPUT; TEST_PIN = FALSE; while(1)//a ciclo infinito ripeto queste 2 routine { medium_event_handler(); slow_event_handler(); } return 0; //code should never get here }// END MAIN()
int main(void) { int addScore, position, pauseSel; // Initializations PLL_Init(); // Clock set at 80 MHz LCD_Init(); Board_Init(); Input_Init(); DAC_Init(); Random_Init(NVIC_ST_CURRENT_R); Timer2_Init(80000000); // time interrupt Timer1_Init(2000); // sound interrupt EnableInterrupts(); generateRandomTile(); drawAllTiles(); writeScore(0); writeHighscore(0); writeTime(0); displayHighestTile(); while(1) { // draw arrow if ready if (arrowReady == 1) { // acknowledge flag arrowReady = 0; // draw arrow drawArrow(); } // write time if ready if (timeReady == 1) { // acknowledge flag timeReady = 0; // write time writeTime(elapsedTime); } // Play mode and button1 is pushed if(Button1 && !pauseMode && !gameOver) { // Play sound playSound = 1; // shift and merge tiles towards arrow position = getSliderPosition(); if (position == 1) { shiftLeft(); addScore = mergeLeft(); shiftLeft(); } else if (position == 2) { shiftUp(); addScore = mergeUp(); shiftUp(); } else if (position == 3) { shiftRight(); addScore = mergeRight(); shiftRight(); } else { shiftDown(); addScore = mergeDown(); shiftDown(); } eraseBoard(); drawAllTiles(); // update score score += addScore; addScore = 0; writeScore(score); displayHighestTile(); // delay before adding new tile delay(200); // create new tile if (countEmptyTiles() != 0) { generateRandomTile(); } drawAllTiles(); // update highest tile image displayHighestTile(); // check if game over if (checkGameOver() == 1) { gameOver = 1; } // unset flag Button1 = 0; } // button 2 is pause else if (Button2 && !gameOver && !pauseMode) { pauseMode = 1; pauseSel = 0; // disable arrow and timer NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); // draw pause mode screen drawPauseMode(); // acknowledge button Button2 = 0; // wait until button is pushed while (pauseMode) { // Button 1 selects current pause selection button if (Button1) { // acknowledge button Button1 = 0; Button2 = 0; pauseMode = 0; // if pause selection = "continue" (pauseSel = 0), continue with game if (pauseSel == 0) { // redraw screen eraseBoard(); drawAllTiles(); // enable gameplay NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } // if pause selection = "restart" (pauseSel = 0), end game else if (pauseSel == 1) { if (score > highscore) { writeHighscore(score); } score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } } // Button 2 changes pause selection else if (Button2) { Button2 = 0; if (pauseSel == 0) { pauseSel = 1; LCD_DrawRect(144,112,58,16,BLACK); LCD_DrawRect(222,112,51,16,WHITE); } else if (pauseSel == 1) { pauseSel = 0; LCD_DrawRect(222,112,51,16,BLACK); LCD_DrawRect(144,112,58,16,WHITE); } } } } // game over if (gameOver == 1) { NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(156,38,100,20,BLACK); LCD_SetTextColor(255,255,240); LCD_Goto(30,5); printf("GAME OVER"); while (Button1 == 0 && Button2 == 0) {} Button1 = 0; Button2 = 0; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); drawGameOver(score, elapsedTime); if (score > highscore) { writeHighscore(score); gameOverHighscore(score); } // wait til button is pushed while (Button1 == 0 && Button2 == 0) {} // acknowledge buttons Button1 = 0; Button2 = 0; // start new game score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; // finish game over mode gameOver = 0; } } }