PIC_A/D converte
ADCON0
ADCON1
GODONE =1時相當于開始AD轉(zhuǎn)換,過一點時間會變?yōu)?,表示AD轉(zhuǎn)換完成
ADRESH
ADRESL
#include
#include
__CONFIG(1,XT) ; //晶振為外部4M
__CONFIG(2,WDTDIS) ; //看門狗關(guān)閉
__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);
}
}
評論