本文是根据89C51的八路AD转化体系规划
一)硬件部分:
二)程序部分:
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ADC0809 XBYTE[0x7fff]
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code act[4]={0xfe,0xfd,0xfb,0xf7};
sbit P1_7=P1^7;
sbit P2_6=P2^6;
sbit P3_3=P3^3;
bit flag;
uchar m;
uint X[8];
void d200us(void);
void delay(uint k);
/******************************/
void main(void)
{
TMOD=0x01;
TH0=-(1000/256);
TL0=-(1000%256);
TR0=1;
IE=0x82;
while(1)
{
if(!P2_6){delay(30);if(!P2_6)flag=!flag;delay(300);}
ADC0809=m;
while(!P3_3);
X[m]=ADC0809;
m++;
if(m>7)m=0;
delay(50);
}
}
/************************************/
void delay(uint k)
{
uint i,j;
for(i=0;i for(j=0;j60;j++)
{;}}
}
/***********************************/
void timer0(void) interrupt 1 using 1
{static uchar disbit,n;static uint cnt;
TH0=-(1000/256);
TL0=-(1000%256);
switch(disbit)
{
case 0:{P1=SEG7[n];if(flag)P1_7=1;else P1_7=0;}break;
case 1:{P1=SEG7[(X[n]*49/25)/100];P1_7=1;}break;
case 2:{P1=SEG7[(X[n]*49/25)%100/10];}break;
case 3:{P1=SEG7[(X[n]*49/25)%100%10];}break;
default:break;
}
P2=act[disbit];
disbit++;cnt++;
if(disbit>3)disbit=0;
if(!flag)
{if(cnt>500){cnt=0;n++;}}
if(n>7)n=0;
}