#defineGLOBAL_CLK 1 #include<stdlib.h> #include<string.h> #include"def.h" #include"option.h" #include"2440addr.h" #include"2440lib.h" #include"2440slib.h" #include"mmu.h" #include"profile.h" #include"memtest.h" int Readadc(intch) { rADCCON= (1<<14)| (49<<6) | ((ch)<<3);//adc使能,設置頻率為1MHZ rADCTSC=~(0x1<<2);//adc設置為普通轉換模式 rADCCON|=0x1;//啟動ad while(rADCCON0x1);//等待ad轉換開始 while(!(rADCCON(0x1<<15)));//等待ad轉換結束 return(rADCDAT0 0x3ff); //讀取A/D轉換的數據 } void Main() {float v0,v1; int t0,t1; Uart_Printf("請調整滑動電阻并輸入1選擇顯示電壓值!\r"); while(Uart_GetIntNum()==1) {v0=((float)Readadc(0)*3.3)/1024.0;//計算電壓值 v1=((float)Readadc(1)*3.3)/1024.0;//計算電壓值 t0=(v0-(int)v0)*1000;//計算小數部分,Uart_Printf函數無法打印浮點數 t1=(v1-(int)v1)*1000;//計算小數部分,Uart_Printf函數無法打印浮點數 Uart_Printf("電壓值為AIN0:%d.%-3dVAIN1:%d.%-3dV\r",(int)v0,t0,(int)v1,t1); Uart_Printf("\n");}}
|