#include
#define XBYTE ((unsigned char volatile xdata *) 0)
#define adin XBYTE[0x7fff] //P2=0x7f P0 = 0xff
#define addo (5.0/255.0)
#define zero 0.005
sbit LED1 = P3^0
sbit LED2 = P3^1;
sbit LED3 = P3^2;
sbit LED4 = P3^3;
sbit dp = P3^5;
static unsigned char dispdata[4];
unsigned char code num[] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x77,0x3e }
void delayus(unsigned int us)
{
while(us--);
}
unsigned char ad_action(unsigned char chn)
{
unsigned char read_data;
adin = chn
delayus(6);
read_data = adin;
return read_data
}
//êyÖμ′|àí
void decodenum(float adv,unsigned char chn
{
unsigned int temp;
temp = (unsigned int)(adv*100);
dispdata[0] = temp/100;
dispdata[1] = temp/10%10;
dispdata[2] = temp%10;
dispdata[3] = chn;
}
void dispone(unsigned char LED,bit ifpoint,unsigned char number) //number 0--9
{
switch(LED)
{
case 0:LED1 = 0;break;
case 1:LED2 = 0;break;
case 2:LED3 = 0;break;
case 3:LED4 = 0;break;
default: P3 = 0xff;
}
if( ifpoint == 1 ) dp = 1;
else dp = 0;
P2 = num[number]|0x80
delayus(200);
P3 = 0xff;
}
void disp()
{
unsigned char i;
bit point;
for(i = 0;i<4;i++)
{
if(i == 1) point = 0
else point = 1;
dispone(i,point,dispdata[i]);
}
}
void main()
{
unsigned int cnt = 0
while(1)
{
switch(cnt++)
{
case 0 : decodenum(ad_action(0)*addo+zero,0);break
case 70 : decodenum(ad_action(1)*addo+zero,1);break
case 140: decodenum(ad_action(2)*addo+zero,2);break
case 210: decodenum(ad_action(3)*addo+zero,3);break
case 280: decodenum(ad_action(4)*addo+zero,4);break
case 350: decodenum(ad_action(5)*addo+zero,5);break
case 420: decodenum(ad_action(6)*addo+zero,6);break
case 490: decodenum(ad_action(7)*addo+zero,7);break;
case 560: cnt = 0;break;
}
disp();
}
}