//文件名:main.c //版本: 1.0 //描述:MC430F14開發(fā)板的主程序,實(shí)現(xiàn)讀單路單次A7然后進(jìn)行數(shù)值顯示。 //編程環(huán)境:IAR WE430 3.40A //時(shí)期: 2006.8.26. # include # include "f14demo_1.h" //**************************************************** //定義區(qū) unsigned int value; unsigned char ADVAL[5]={'x','x','x','x','\0'}; unsigned char number_tab[]={'0','1','2','3','4','5','6','7','8','9'}; //**************************************************** //說明:實(shí)驗(yàn)標(biāo)題1,應(yīng)用單實(shí)形式發(fā)送. void send_title() //標(biāo)題顯示 { //sendCMD(DDRAM_0); //DDRAM sendCMD(off_cursor); //關(guān)光標(biāo) sendCMD(LCD_L21); display(LCD_L21,0xBD,0xE1); //結(jié) display(LCD_L22,0xB9,0xFB); //果 sendDAT('A'); sendDAT('D'); sendDAT('7'); sendDAT('='); } //**************************************************** //說明:單片機(jī)初始化 void init(void) { initlcm(); //LCD初始化 char_string (title,LCD_L11); //發(fā)送本實(shí)驗(yàn)標(biāo)題1 send_title(); //發(fā)送本實(shí)驗(yàn)標(biāo)題2 sendCMD(off_cursor); //關(guān)光標(biāo) //ADC12初始化---------------------- //單通道,單次采樣模式 P6SEL |= 0x80; //使能A/D通道 A7 ADC12CTL0 = ADC12ON + SHT0_2; //開ADC12內(nèi)核和設(shè)置SHIT0=2(N=4) ADC12CTL1 |= SHP; //SAMPCON信號(hào)選擇為采樣定時(shí)器輸出 ADC12CTL1 |= CSTARTADD_7; //定義單次轉(zhuǎn)換地址 ADC12MCTL7 |= INCH_7; //ADC12MCTL0 = SREF_2; // 使用外部參考電壓 Vr+ = VeREF+ ADC12CTL0 |= ENC; //ADC轉(zhuǎn)換允許 //Timer_A初始化-------------------- P1DIR = 0x02; CCR0 = 1638-1; CCTL0 = CCIE; TACTL = TASSEL_1+MC_1; //timerA CLK=ACLK,增計(jì)數(shù)模式 _EINT(); //開總中斷 } //**************************************************** //說明:數(shù)值轉(zhuǎn)換 void conv(unsigned int intdata, unsigned char *pc) { unsigned int a,b,c; pc[0]=number_tab[intdata/1000] ; a=intdata%1000 ; pc[1]=number_tab[a/100] ; b=a%100 ; pc[2]=number_tab[b/10] ; c=b%10; pc[3]=number_tab[c/1] ; } //**************************************************** //TimerA0中斷服務(wù)程序 #pragma vector=TIMERA0_VECTOR __interrupt void Timer_a(void) { LPM0_EXIT; } //---------------------------------------------------- void main(void) { WDTCTL=WDTPW+WDTHOLD; //停止WDT init(); LPM3; while(1) {ADC12CTL0 |= ADC12SC; // 開始轉(zhuǎn)換 while((ADC12IFG & BIT7)==0); _NOP(); P1OUT ^= BIT1; //反轉(zhuǎn) P1.1 value=ADC12MEM7; // 讀取結(jié)果 conv(value,ADVAL); //數(shù)據(jù)轉(zhuǎn)換調(diào)用 char_string (ADVAL,LCD_L25); //發(fā)送本實(shí)驗(yàn)標(biāo)題1 LPM3; } } |