int main(void){ // for the real board grader to work, you must connect PD3 to your DAC output int piano; // to read current piano keys int prevPiano; // to store piano keys in prev cycle TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done while(1){ piano = Piano_In(); if(piano != prevPiano){ // only react if piano keys pressed if(piano == 0x00) Sound_Off(); else if(piano == 0x01) Sound_Tone(2389); else if(piano == 0x02) Sound_Tone(2128); else if(piano == 0x04) Sound_Tone(1896); else if(piano == 0x08) Sound_Tone(1594); delay(10); } prevPiano = piano; } }
int main(void){ TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn); // bus clock at 80 MHz //Timer0A_Init(&songTask, F80HZ); Piano_Init(); Sound_Init(0); DAC_Init(); Heartbeat_Init(); // other initialization EnableInterrupts(); uint32_t input; while(1){ GPIO_PORTF_DATA_R ^= 0x04; input = Piano_In(); if (input == 0x04){ Sound_Play(A); } else if (input == 0x02){ Sound_Play(C); } else if (input == 0x01){ Sound_Play(Eb); } else if (input == 0x07){ Sound_Play(A); } else { Sound_Play(0); } } }
int main(void){ // Real Lab13 // for the real board grader to work // you must connect PD3 to your DAC output TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz // PortE used for piano keys, PortB used for DAC Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done DAC_Init(); while(1){ volatile unsigned long current_switch; current_switch = Piano_In(); if (current_switch == 0x01){ EnableInterrupts(); Sound_Tone(4780); } else if (current_switch == 0x02){ EnableInterrupts(); Sound_Tone(4259); } else if (current_switch == 0x04){ EnableInterrupts(); Sound_Tone(3794); } else if (current_switch == 0x08){ EnableInterrupts(); Sound_Tone(3189); } // else if (current_switch == 0x00){ // Sound_Off(); // DisableInterrupts(); // } delay(10); } }
int main(void) { unsigned long input= 0; PLL_Init(); Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done while(1) { // input from keys to select tone input= Piano_In(); switch (input) { case 0x01: Sound_Tone(C); break; case 0x10: Sound_Tone(D); break; case 0x04: Sound_Tone(E); break; case 0x08: Sound_Tone(G); break; default: Sound_Off(); break; } } }
int main(void){ // Real Lab13 // for the real board grader to work // you must connect PD3 to your DAC output TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz // PortE used for piano keys, PortB used for DAC Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done while(1){ // input from keys to select tone } }
int main(void){ // Real Lab13 // for the real board grader to work // you must connect PD3 to your DAC output TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz // PortE used for piano keys, PortB used for DAC Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done while(1){ /*DAC_Out(wave[n]); // your code to output to the DAC delay(1000); // wait 1s (later change this to 1ms) n = (n+1)&0x1F;*/ switch(Piano_In()) { case C: delay(delayValue); //EnableInterrupts(); //Sound_Tone(523.251); Sound_Tone(C0); break; case D: //EnableInterrupts(); delay(delayValue); Sound_Tone(D0); break; case E: //EnableInterrupts(); delay(delayValue); Sound_Tone(E0); break; case G: //EnableInterrupts(); delay(delayValue); Sound_Tone(G0); break; default: delay(delayValue); Sound_Off(); //DisableInterrupts(); break; } } }
void main(void) { PLL_Init(); // Engaging PLL allows use to run 9S12 at 24MHz even in RUN mode DAC_Init(); Piano_Init(); Sound_Init(); EnableInterrupts; Data = 0; for(ever) { Piano_In(); PTP ^= 0x80; // Heartbeat } /* for(;;) { DAC_Out(Data); Data = 0x0F&(Data+1); } */ }
// PE=Switch controls (input), PB=DAC output int main(void){ TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn); // bus clock at 80 MHz /*unsigned long Data; // 0 to 15 DAC output //PLL_Init(); // like Program 4.6 in the book, 80 MHz DAC_Init(); for(;;) { DAC_Out(Data); Data = 0x0F&(Data+1); // 0,1,2...,14,15,0,1,2,... }*/ Piano_Init(); EnableInterrupts(); Sound_Init(0); // other initialization Sound_Play(0); while(1){} }
//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; } } }