2、++);//16MHz--1msfor(jj=0;jj<2270;jj++);//32MHz--1ms//for(jj=0;jj<4006;jj++);//48MHz--1msfor(jj=0;jj<4341;jj++);//64MHz--1ms}voidSetBusCLK_40M(void){CLKSEL=0X00;//disengagePLLtosystemPLLCTL_PLLON=1;//turnonPLLSYNR=0xc0
3、0x04;REFDV=0x80
4、0x01;POSTDIV=0x00;//pllc
5、lock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;_asm(nop);//BUSCLOCK=40M_asm(nop);while(!(CRGFLG_LOCK==1));//whenpllissteady,thenuseit;CLKSEL_PLLSEL=1;//engagePLLtosystem;}voidPIT0_init(void)//定時(shí)PIT0中斷{PITCFLMT_PITE=0;//定時(shí)中斷通道PITCE_PCE0=1;//定時(shí)器通道0使能PITMTLD0=40-1;//8位定時(shí)器
6、初值設(shè)定。40分頻,在40MHzBusClock下,為0.1MHz,即1us=0.001msPITLD0=500-1;//16位定時(shí)器初值設(shè)定。PITTIME*0.01MS,定時(shí)500*0.001ms=0.5msPITINTE_PINTE0=1;//定時(shí)器中斷通道0中斷使能PITCFLMT_PITE=1;//定時(shí)器通道使能改為在按下鍵之后才置1}voidPAOVFinit(void){TSCR1_TEN=1;//(7)使能定時(shí)器模塊PACTL_PAEN=0;//(6)累加器禁止PACTL_PAMOD=0;//(
7、5)PAMOD=0,事件計(jì)數(shù)模式;PAMOD=1,門控時(shí)間累加模式PACTL_PEDGE=0;//(4)選擇通道7的脈沖沿(0,下降沿)PACTL_PAOVI=0;//使能累加器溢出中斷,即PAOVF=1時(shí)申請(qǐng)中斷PACTL_PAI=0;//使能累加器輸入中斷,即PAIF=0時(shí)申請(qǐng)中斷PACNT=0;//計(jì)算器初值為0PAFLG_PAOVF=1;//寫入清除該位,當(dāng)累加器溢出時(shí)置位PAFLG_PAIF=1;//寫入時(shí)清除該位,當(dāng)累加器有變化時(shí)置位PACTL_PAEN=1;//(6)累加器使能}intcheckk
8、ey()//按鍵程序{if(!KEY1){Dly_ms(10);if(!KEY1)return(1);}if(!KEY2){Dly_ms(10);if(!KEY2)return(2);}if(!KEY3){Dly_ms(10);if(!KEY3)return(3);}if(!KEY4){Dly_ms(10);if(!KEY4)return(4);}return0;}intboma_key(){chara=0,b=0,c=0,d=0,boma=0;a=PORTE_PE4;b=PORTE_PE5;c=PORTE_P
9、E6;d=PORTE_PE7;if(a==1)boma=boma
10、0x08;if(b==1)boma=boma
11、0x04;if(c==1)boma=boma
12、0x02;if(d==1)boma=boma
13、0x01;return(boma);}//////////////PWMvoidPWM01_init(void)//dajiao{PWME_PWME1=0;PWMCTL_CON01=1;//通道23級(jí)聯(lián)PWMCAE_CAE1=0;//左對(duì)齊PWMPOL_PPOL1=1;//1:起始為高電平0:起始為低電平PWM
14、CLK_PCLK1=1;//=1時(shí)鐘來源選擇ClocksSAPWMSCLA=5;//ClockSA=ClockA/(2*PWMSCLA)clockA=主頻40M/(2*PWMSCLA)=4MHzPWMPER01=60000;//輸出頻率=4000000Hz/(60000)PWMDTY01=5455;//PWME_PWME1=1;//啟動(dòng)PWM輸出}voidPWM23_init(void