#include<reg51.h>
#include<stdio.h>
#define uchar unsigned char
sfr ADC_CONTR=0xC5;
sfr p1=0x90;
sfr p2=0xB0;
sfr p1M0=0x91;
sfr p1M1=0x90;
sfr ADC_DATA=0xC6;
sbit p1_7=p1^7;
void delayMs(unsigned int number);
void adc(void);
uchar code tab[6]={0x3F,0x06,0x5B,0x4F,0x66,0x6D};
void main()
{
p1=0;
p2=0;
ADC_CONTR=0x80;
delayMs(10);
p1M0=1;
p1M1=1;
while(1)
{
adc();
}
}
void adc()
{ uchar ad_in;
ADC_CONTR |=0x08;
while(!(ADC_CONTR&&0x10));
ADC_CONTR &=0xe7;
ad_in=ADC_DATA;
if(ad_in>204)
P1=tab[5];
else if(ad_in>153)
P1=tab[4];
else if(ad_in>102)
P1=tab[3];
else if(ad_in>51)
P1=tab[2];
else P1=tab[1];
delayMs(10);
}
void delayMs(unsigned int number)
{
unsigned char temp;
for(;number!=0;number--)
{
for(temp=0;temp<124;temp++)
;
}
}