#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");}}
|