AD部分:
#include<pic.h>#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3C64);
void delay(uint x);
void init();
uint get_ad();
void main()
{
init();
while(1)
{
GPIO=get_ad();
}
}
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init()
{
TRISIO=0x08;
GPIO=0x00;
ANSEL=0x71;
ADCON0=0x01;
delay(20);
}
uint get_ad()
{
uint adval;
ADCON0=0x03;
while(ADCON0==0x01);
adval=ADRESH<<1;//结果处理方式可自行设计
// ADRESL=(ADRESL>>2)&0XF0;
// ADRESH=ADRESH<<1;
// adval=ADRESH+ADRESL;
return (adval);
}
|