/*电压表 精确到小数点后面三位*/
/*连线:电位器接IN0,AD_CS接CS0,CS1接KEY/LED_CS*/
#include
typedef unsigned char uchar;
xdata uchar LED_CS _at_ 0x9000;
xdata uchar LED_OUTSEG _at_ 0x9004;
xdata uchar LED_OUTBIT _at_ 0x9002;


xdata uchar AD_CS _at_ 0x8000;
xdata uchar AD_MODE _at_ 0x8003;


code unsigned char LEDMAP[] = {  // 八段管显示码
  0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
  0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
code unsigned char LEDWED[] = {0x20,0x10,0x08,0x04,0x02,0x01};
int num[6];
void delay(int ms)
{
 int i,j;
 for(i=0;i     for(j=0;j<14;j++)
         ;
}
void adf()
{
 AD_CS = 0;
 delay(10);
}
void main()
{
 int led_c=0;
 unsigned char temp;
 AD_MODE = 0x82;
 AD_CS = 0;
 while(1)
 {
  adf();
  delay(10);
  num[0] = AD_CS*5/256;
  num[1] = AD_CS*5%256*10/256;
  num[2] = AD_CS*5%256*10%256*10/256;
  num[3] = AD_CS*5%256*10%256*10%256*10/256;
  temp = LEDMAP[num[led_c]];
  if(led_c == 0)
           temp = temp|0x80;
  LED_OUTBIT = LEDWED[led_c];
  LED_OUTSEG = temp;
  led_c = (led_c+1)%4;
  delay(10);
 }
}