#include "extern.h"
#define bit0 0x01
ad_1 bit pa.0;
void adc();
void wendu();
word ad_1_a1;
word wendu_a1;
byte wendu_a2;
void FPPA0 (void)
{
//.ADJUST_IC SYSCLK=IHRC/4, IHRC=16MHz, VDD=5V, Bandgap=On;
.ADJUST_IC SYSCLK=IHRC/4, IHRC=16MHz, VDD=5V;
/**************************************************/ //ad配置
$ ad_1 in;
$ padier =~bit0; //只写寄存器
$ adcc enable,pa0;
$ adcm 12bit,/8;
$ adcrgc vdd;
.delay 4*400; //400us
ad_start =1;
while(!ad_done) {};
ad_1_a1$1 =adcrh;
ad_1_a1$0 =adcrl;
ad_1_a1 >>=4;
/**************************************************/
while (1)
{
adc();
wendu_a1 =ad_1_a1;
wendu();
}
}
/**************************************************/
void adc()
{
.delay 4*400; //400us
ad_start =1;
while(!ad_done) {};
ad_1_a1$1 =adcrh;
ad_1_a1$0 =adcrl;
ad_1_a1 >>=4;
ad_1_a1 =~ad_1_a1; //取反变增长
}
/**************************************************/
void wendu()
{
if(wendu_a1>62000) //减基数
{
wendu_a1 -=62000;
}
if(wendu_a1 >1444 ){wendu_a2 =40;return;}
if(wendu_a1 >1412 ){wendu_a2 =39;return;}
if(wendu_a1 >1360 ){wendu_a2 =38;return;}
if(wendu_a1 >1320 ){wendu_a2 =37;return;}
if(wendu_a1 >1281 ){wendu_a2 =36;return;}
if(wendu_a1 >1244 ){wendu_a2 =35;return;}
if(wendu_a1 >1211 ){wendu_a2 =34;return;}
if(wendu_a1 >1171 ){wendu_a2 =33;return;}
if(wendu_a1 >1131 ){wendu_a2 =32;return;}
if(wendu_a1 >1090 ){wendu_a2 =31;return;}
if(wendu_a1 >1051 ){wendu_a2 =30;return;}
if(wendu_a1 >1016 ){wendu_a2 =29;return;}
if(wendu_a1 >988 ){wendu_a2 =28;return;}
if(wendu_a1 >947 ){wendu_a2 =27;return;}
if(wendu_a1 >902 ){wendu_a2 =26;return;}
if(wendu_a1 >864 ){wendu_a2 =25;return;}
if(wendu_a1 >830 ){wendu_a2 =24;return;}
if(wendu_a1 >786 ){wendu_a2 =23;return;}
if(wendu_a1 >756 ){wendu_a2 =22;return;}
}
/**************************************************/
|