#include "N76E003.h"
#include <intrins.h>
#include "stdint.h"
#include "SFR_Macro.h"
unsigned char duanma[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay (uint16_t z)
{
uint16_t i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void main(void)
{
uint16_t BandGap_H, BandGap_L, AIN3_H, AIN3_L;
uint16_t BandGap_v;
uint32_t AIN3_v = 0;
uint16_t voltage = 0;
P1M1 = 0x00;
P1M2 = 0xff;
P0M1 = 0x40;
P0M2 = 0xbf;
while(1)
{
ADCCON0 &= 0xf0;
ADCCON0 |= 3;
ADCF=1;
ADCS=1; // Each time ADC start trig signal
while(ADCF==0);
AIN3_H = ADCRH;
AIN3_L = ADCRL;
// AIN3_H = 0xf4;
// AIN3_L = 0xf4;
AIN3_v = AIN3_H << 4 | AIN3_L;
voltage = AIN3_v *500/4096;
P0=0xf7;
delay(50);
P1=duanma[voltage/1000];
P0=0xfe;
delay(50);
P1=duanma[voltage%1000/100];
P0=0xfd;
delay(50);
P1=duanma[voltage%100/10];
P0=0xef;
delay(50);
P1=duanma[voltage%10];
四位数码管显示0 AD没启动 数据 可以转换 |