adc0804转换电压使用1602显示。为什么检测不到P1端的电压值。
程序:
- #include<reg52.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar code table[]="Voltage:";
- uchar code table1[]="V";
- uchar table2[3];
- uchar table3[]={0,1,2,3,4,5,6,7,8,9};
- uchar table4[]={.1};
- sbit lcden=P3^4;
- sbit lcdrs=P3^5;
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit adwr=P3^6;
- sbit adrd=P3^7;
- sbit adcs=P3^0;
- uchar num;
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_com(uchar com)
- { lcden=0;
- lcdrs=0;
- P0=com;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_data(uchar date)
- { lcden=0;
- lcdrs=1;
- P0=date;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void init()
- {
- dula=0;
- wela=0;
- lcden=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- }
- void main()
- { uchar adval,A3,A2,A1,b;
- init();
- write_com(0x80);
- for(num=0;num<8;num++)
- {
- write_data(table[num]);
- delay(5);
- }
- write_com(0x80+0x0e);
- for(num=0;num<1;num++)
- {
- write_data(table1[num]);
- delay(5);
- }
- while(1)
- { adcs=1;
- adwr=1;
- _nop_();
- adwr=0;
- _nop_();
- adwr=1;
-
- P1=0xff;
- adrd=1;
- _nop_();
- adrd=0;
- _nop_();
- adval=P1;
- adcs=0;
- adrd=1;
- for(b=0;b<5;b++)
- {
- write_com(0x80+0x0a);
- write_data(table2[0]+48);
- write_com(0x80+0x0b);
- write_data(table2[1]+48);
- write_com(0x80+0x0c);
- write_data(table2[2]+48);
- }
- A1=adval/100 ;
- A2=adval%100/10;
- A3=adval%10;
- table2[0]=table3[A1];
- table2[1]=table3[A2];
- table2[2]=table3[A3];
-
-
-
- }
- }
复制代码
|