对一下寄存器操控
ADCON0
ADCON1
GODONE =1时相当于开端AD转化,过一点时刻会变为0,表明AD转化完结
ADRESH
ADRESL
#include
#include
__CONFIG(1,XT) ; //晶振为外部4M
__CONFIG(2,WDTDIS) ; //看门狗封闭
__CONFIG(4,LVPDIS) ; //制止低电压编程
#define uchar unsigned char
#define uint unsigned int
#define nop NOP()
#define en RB3
#define rw RB4
#define rs RB5
void delayms(uint z)
{
uint i,j;
for(i=0;i<100;i++)
for(j=0;j
}
void write_com(uchar com)
{
rs=0;
rw=0;
delayms(5);
en=1;
delayms(5);
PORTD=com;
en=0;
delayms(5);
}
void write_dat(uchar dat)
{
rs=1;
rw=0;
delayms(5);
en=1;
delayms(5);
PORTD=dat;
en=0;
delayms(5);
}
void init_1602()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
uchar temp;
ADCON0=0x21;
ADCON1=0x00;
TRISA=0xff;
TRISB=0xc7;
TRISD=0x00;
init_1602();
while(1)
{
GODONE=1;
while(GODONE);
temp=ADRESH;
write_com(0x80);
write_dat(0x30+temp/1000);
write_dat(0x30+(temp-1000*(temp/1000))/100);
write_dat(0x30+(temp-1000*(temp/1000)-100*((temp-1000*(temp/1000))/100))/10);
write_dat(0x30+temp);
}
}