请大家帮我看看程序吧~~要憋疯了又不知道哪错~~
[复制链接]
这个是要实现八路数据采集然后用LCD显示,可是无论如何调节AAD输入端电压输出端就是显示5V~不知道是程序哪里出了错误啊~
#include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit adoe=P3^7; //OE接3.7 sbit eoc=P3^3; //EOC接3.1 sbit adstart=P3^6; //start接3.2 sbit a0=P3^0; //A 3.3 sbit a1=P3^1; //B 3.4 sbit a2=P3^2; //C 3.5 sbit lcdrs=P3^5; //LCD RS 3.6 sbit lcden=P3^4; //LCD EN 3.7 sbit dula=P2^6; sbit wela=P2^7; long int advel,temp,b1,b2,b3,b4,b5; uchar tt; uchar code table[]="0123456789.V"; //显示电压 void delay(uint z) //延时 { uint x,y; for(x=z;x>0;x--) for(y=100;y>0;y--); } void write_command(uchar com)//写命令 { dula=0; wela=0; lcdrs=0; //输入指令 P0=com; delay(5); lcden=1; //读数据 delay(5); lcden=0; //写指令或者数据 } void write_data(uchar date)//写数据 { lcdrs=1; //输入数据 P0=date; //显示 delay(5); lcden=1; //读数据 delay(5); lcden=0; //写指令或数据 } void init()//初始化 { lcden=0; write_command(0x38);//不可变,显示模式设置:16*2显示,5*7点阵,8位数据接口 write_command(0x0c);//屏幕开启和光标闪烁 write_command(0x06);//显示开关及光标设置 write_command(0x01);//清屏
} void start() //开始AD转换 { adoe=0; adstart=0; _nop_(); adstart=1; _nop_(); adstart=0; advel=P0; }
void xianshi() //AD转化结果显示 { write_data(table[b1]); //最高位 delay(1); // write_data(table[10]); // 小数点 delay(1); // write_data(table[b2]); //第二位 delay(1); // write_data(table[b3]); // 第三位 delay(1); // write_data(table[11]); // 电压V delay(1); } void first_mark() //0-4路通道的标号 { write_command(0x01); write_command(0x80); write_data('A'); delay(1); write_command(0x80+0x01); write_data('='); delay(1); write_command(0x80+0x09); write_data('B'); delay(1); write_command(0x80+0x0a); write_data('='); delay(1); write_command(0x80+0x40); write_data('C'); delay(1); write_command(0x80+0x41); write_data('='); delay(1); delay(1);write_command(0x80+0x49); write_data('D'); delay(1); write_command(0x80+0x4a); write_data('='); delay(1); } void second_mark() //5-7路通道的标号 { write_command(0x01); write_command(0x80); write_data('E'); delay(1); write_command(0x80+0x01); write_data('='); delay(1); write_command(0x80+0x09); write_data('F'); delay(1); write_command(0x80+0x0a); write_data('='); delay(1); write_command(0x80+0x40); write_data('G'); delay(1); write_command(0x80+0x41); write_data('='); delay(1); delay(1);write_command(0x80+0x49); write_data('H'); delay(1); write_command(0x80+0x4a); write_data('='); delay(1); } void main() { a2=0; init(); //调用LCD初始化子程序 TMOD=0x01; EA=1;//开总中断 TH0=(65535-1000)/256; TL0=(65535-1000)%256; ET0=1;//开定时器0中断 TR0=1;//定时器0置位 first_mark(); while(1) { a0=0; //0路或4路通道的AD转化 a1=0; start(); while(!eoc); adoe=1; temp=P1; delay(3); adoe=0; b1=(temp*500/255)/100; //最高位 b2=(temp*500/255)%100/10; //第二位 b3=(temp*500/255)%10; //第三位 write_command(0x80+0x02); xianshi();
a0=1; //1路或5路通道的AD转化 a1=0; start(); while(!eoc); adoe=1; temp=P1; delay(3); adoe=0; b1=(temp*500/255)/100; //最高位 b2=(temp*500/255)%100/10; //第二位 b3=(temp*500/255)%10; //第三位 write_command(0x80+0x0b); xianshi();
a0=0; //2路或6路通道的AD转化 a1=1; start(); while(!eoc); adoe=1; temp=P1; delay(3); adoe=0; b1=(temp*500/255)/100; //最高位 b2=(temp*500/255)%100/10; //第二位 b3=(temp*500/255)%10; //第三位 write_command(0x80+0x42); xianshi();
a0=1; //3路或7路通道的AD转化 a1=1; start(); while(!eoc); adoe=1; temp=P1; delay(3); adoe=0; b1=(temp*500/255)/100; //最高位 b2=(temp*500/255)%100/10; //第二位 b3=(temp*500/255)%10; //第三位 write_command(0x80+0x4b); xianshi();
} } void timer0() interrupt 1 //什么意思? { TH0=(65536-50000)/256; TL0=(65536-50000)%256; tt++; if((a2==0&&tt==20)==1) //LCD第二屏显示 { tt=0; a2=1; second_mark(); } if((a2==1&&tt==20)==1) //LCD第一屏显示 { tt=0; a2=0; first_mark(); } }
|