如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
STC单片机AD转换程序#include<STC12C2052AD.h>//定义的系统头文件和全局变量#include<intrins.h>#defineucharunsignedchar#defineuintunsignedint#defineDogReset()WDT_CONTR=0x35//T1定时0.1ms.作为系统计时用,#definevT01ms2#definevT10ms10#definevT100ms10#definevT01S100//1s=10ms*100#definevT0HVal0xfe//0xff//0xfe//0xf6#definevT0LVal0x33//0x9c//0x0c//0x4cucharcodedisplay_AD_channel_ID[2]={0x00,0x01};staticunsignedchardataCS;uchardataAD_channel_result[2][5];//各通道A/D转换结果。前是通道号;后是转换的值uintcT01ms;ucharcT10ms;ucharcT100ms;ucharcT01s;ucharTHTL;bitOutFlag;/***************************************************************************函数原型:voiddelay_ms(uintCount)*功能:延时Count个ms**************************************************************************/voiddelay_ms(registeruintCount){registerucharT;for(;Count>0;Count--){for(T=0;T<80;T++){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}DogReset();}}/***************************************************************************函数原型:voidComOutChar(unsignedcharOutData)*功能:向串口输出一个字符(非中断方式)**************************************************************************/voidsend_char_com(unsignedcharOutData){SBUF=OutData;//输出字符while(!TI);//空语句判断字符是否发完TI=0;//清TI}/***************************************************************************函数原型:voidComOutChar(unsignedcharOutData)*功能:向串口输出一个字符(非中断方式)**************************************************************************/voidsend_string_com(uchar*str,ucharstrlen){uchari;for(i=strlen;i>0;i--){send_char_com(*str);str++;DogReset();}}/***************************************************************************函数原型:voidAd_Change(ucharchannel)*功能:A/D转换*入口:channel=通道号.0:0通道;1:1通道。。。。。。。*出口:AD_channel_1_result:10位的数据,16进制。**************************************************************************/ucharAd_Change(ucharchannel){uintAD_Result_Temp=0;//---------------------将P1.0--P1.1设置成适合AD转换的模式///P1=0xff;//将P1口置高,为A/D转换作准备ADC_CONTR=ADC_CONTR|0x80;//1000,0000打开A/D转换电源P1M0=0x03;//0000,0011用于A/D转换的P1.x口,先设为开漏P1M1=0x0