中易网

求一个51单片机AD转换实验?

答案:1  悬赏:20  
解决时间 2021-10-04 12:06
求一个51单片机AD转换实验?
最佳答案
#include <reg51.h>
#include <INTRINS.H>
#include <STDIO.H>

// define P1.0 to check STATUS.
sbit STATUS = P1^0;

unsigned char xdata CTRL _at_ 0x2FFF;
unsigned char xdata ADSEL _at_ 0x4FFF;
unsigned char hByte;
unsigned char lByte;

void adc_Convert (void)
{ // Start a conversion with A0 and A/$C$ low.
// The convesion takes place on rising CE edge.
CTRL = 0x00;
ADSEL = 0x00;
// Wait until we have completed a conversion .
while(STATUS==1);
// Set R/$C$ with A0 low and read the low byte.
CTRL = 0x02;
hByte = ADSEL;
// Set R/$C$ with A0 high and read the high.
CTRL = 0x03;
lByte = ADSEL;
}


void main(void)
{ unsigned int delay, MSB , LSB, adc_Res;
// Initialize serial interface
SCON = 0xDA; // SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; // TH1: reload value for 1200 baud @ 12MHz */
TR1 = 1; // TR1: timer 1 run */
TI = 1; // TI: set TI to send first char of UART */

while(1)
{ adc_Convert();
MSB=(unsigned int)(hByte << 4);
LSB=(unsigned int)(lByte >> 4);
// adc_Res now has the converted data with 12-bit resolution.
adc_Res = MSB + LSB;
// Send adc results to the serial interface
printf("ADC READINGS: %03Xh\n", adc_Res);
// simple delay - it is mcu clock dependent !
for (delay=0; delay<10000; delay++)
;
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
楼房什么镇宅?
成都双流真维斯的店吗
青岛即墨市到徐州怎么走高速
从长春到三亚怎么走省钱
一体式门禁系统需要多少钱?
深圳观澜厂房装修有哪些公司,哪家比较好,大
水晶酒架价格怎么样?
怎样选择抽烟机?
中式隔墙怎么设计比较好?
冰糖葫芦的做法
在佛山求租9座面包车按天数记多少钱一天
电视天线什么牌子好
孕妇4个月开始肚皮痒痒 有什么好的解决办法吗
去漳州华阳体育馆要坐几路公交车啊
求大神给说说厨房间装饰有哪些项目?谁说说看
推荐资讯
如何缓解婴幼儿冬季皮肤的干燥现象呢?
韩国饭店装修风格是怎样的?谁知道市场价?
婴儿晚上吃奶粉用喂水吗
早晨起来脸浮肿而且黑眼圈很重是怎么一回事呢
明樓的意思是什么?明樓的释义是什么啊?
应天府书院的意思是什么?应天府书院的释义是
激光祛斑后多长时间好要注意什么
天津塘沽新港船厂的废铁个人可以进厂去收购吗
1987年12月27号到2018年4月10号是多少天
南宁吴圩机场怎样去凭祥
问一下大家衣服如何收纳
紫檀柳对眼手串报价贵吗
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?