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){ // 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){ /*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 Snake_Game() //游戏过程 { Snake_Init(); //初始化游戏 Play_Music(sound_canon); while(snake.life) //有生命,便可玩 { uint8 i; switch(keypad)//直接读取键值,贪吃蛇不需要消抖 { case K_UP: if((snake.direc==left)||(snake.direc==right)) snake.direc=up; //按下UP键时,只有蛇在水平方向时才能改变 break; case K_DOWN:if((snake.direc==left)||(snake.direc==right)) snake.direc=down; //按下DOWN键时,只有蛇在水平方向时才能改变 break; case K_LEFT:if((snake.direc==up)||(snake.direc==down)) snake.direc=left; //按下left键时,只有蛇在垂直方向时才能改变 break; case K_RIGHT:if((snake.direc==up)||(snake.direc==down)) snake.direc=right; //按下right键时,只有蛇在垂直方向时才能改变 break; default : break; } if(KEY_OK==0) speeds = ASPEED;//加速键 else speeds = NORSPEED; keypad = K_NULL; if(tms > speeds) //半秒前进一格 { tms=0; Snake_Run(); //无聊散步 } if((snake.x[0]==food.x) && (snake.y[0]==food.y))//是否吃到食物 { Sound_Tone(sound_ON,4,5); // getfood=1;//直接在此增加蛇长度会在下一个显示扫描产生一个原有数据留影,故通过加长 snake.node++; // game_speed-=10; //每吃一个食物增加10点速度 Create_Food(); //产生新食物 } if((snake.x[0]>WIDTH-1)||(snake.x[0]<0)||(snake.y[0]>LENGTH-1)||(snake.y[0]<0))//是否碰壁 { snake.life=0; //蛇碰到墙壁死亡 } for(i=3;i<snake.node;i++)//从蛇的第四节开始判断是否撞到自己了,因为蛇头不可能撞到二三四节 { if((snake.x[i]==snake.x[0])&&(snake.y[i]==snake.y[0]))//是否自残 snake.life=0; //蛇头碰到自身死亡 } Snake_Disp(); //显示游戏图像 scores = snake.node-3; SMG_Display(scores,duty); } scores = snake.node-3; TR2_OFF; }
// **************Sound_Off********************* // stop outputing to DAC // Output: none void Sound_Off(void){ // this routine stops the sound output Sound_Tone(0); isOn = 0; }