#include<stc12.h> #define uchar unsigned char #define uint unsigned int main() { unsigned long i; uchar status; ADC_CONTR|=0X80; //打开A/D转换电源 for(i=0;i<10000;i++); P1ASF=0x01; //选择P1^0作为A/D转换通道 ADC_CONTR=0XE0; for(i=0;i<10000;i++); while() { ADC_CONTR|=0X08; //重新启动A/D转换 status=0; ADC_RES=0; //清除以前数据 while(!(ADC_CONTR|=0X10)); //判断转换是否结束 ADC_CONTR=0XE7; status=ADC_RES; } }
以上是我写的stc12c5a60s2内部A/D转换程序,P1^0作为转换通道与传感器模块的AO端相连,麻烦看看有没有问题,下面是利用LCD1602显示光强传感器采集的光强数据程序,和运行结果,数据没有显示出来,拜托各位大神帮忙找找原因,做好能帮忙写一个A/D转换程序,急求············拜托了···········
显示程序:
#include<stc12.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="hello world!";
uchar code table1[]="guan:--.- C";
sbit en = P2^5;
sbit rs = P2^7;
sbit rw = P2^6;
uchar num;
void delay(uint z)
{
uint x, y;
for(x = z;x > 0;x--)
for(y = 110;y > 0;y--);
}
void write_c(uchar c)
{
rs = 0;
P0 = c;
delay(5);
en = 1;
delay(5);
en = 0;
}
void write_da(uchar date)
{
rs = 1;
P0 = date;
delay(5);
en = 1;
delay(5);
en = 0;
}
void init()
{
rw = 0;
en = 0;
write_c(0x38);
write_c(0x0c);
write_c(0x06);
write_c(0x01);
write_c(0x80);
for(num = 0;num < 12;num++)
{
write_da(table[num]);
delay(5);
}
delay(20000);
write_c(0x01);
write_c(0x80);
for(num = 0;num < 11;num++)
{
write_da(table1[num]);
delay(5);
}
}
void yjxianshi(uint date)
{
uchar a, b, c;
// ds = 0;
a = date/100;
b = date%100/10;
c = date%10;
write_c(0x80 + 5);
write_da(0x30 + a);
write_c(0x80 + 6);
write_da(0x30 + b);
write_c(0x80 + 8);
write_da(0x30 + c);
}
uint guangqiang(void)
{
unsigned long i;
uint status;
ADC_CONTR|=0X80; //打开A/D转换电源
for(i=0;i<10000;i++);
P1ASF=0x01; //选择P1^0作为A/D转换通道
ADC_CONTR=0XE0;
for(i=0;i<10000;i++);
ADC_CONTR|=0X08; //重新启动A/D转换
status=0;
ADC_RES=0;
while(!(ADC_CONTR|=0X10));
ADC_CONTR=0XE7;
status=ADC_RES;
return(status);
}
void main()
{
uint t = 0;
uchar e;
init();
while(1)
{
for(e = 240;e > 0;e--)
yjxianshi(t);
t = guangqiang();
}
}