高手们大侠们父老乡亲们都来看看程序吧 在用3位数码管显示连续变化的AD值,我写的程序怎么就是实现不了啊,求救。
#include<reg51.h>
#define uchar unsigned char
sbit oe=P1^0;
sbit eoc=P1^1;
sbit st=P1^2;
sbit clk=P1^3;
sbit led2=P2^1;
sbit led3=P2^2;
sbit led4=P2^3;
int ad_out;
int div_buf;
int div[2]; //16????×a10????μ?3??°???ê?3?£?ò2ê?LEDμ??o′?ê?3?
int xdata *DPTR;
void timer(void) interrupt 1 using 0
{
clk=!clk;
}
void delay(uchar z)
{
int i;
for(i=0;i<=z;i++);
}
led()
{
switch(div_buf)
{
case 0: return(0xc0); break; //êy??1ü12??
case 1: return(0xf9); break;
case 2: return(0xa4); break;
case 3: return(0xb0); break;
case 4: return(0x99); break;
case 5: return(0x92); break;
case 6: return(0x82); break;
case 7: return(0xf8); break;
case 8: return(0x80); break;
case 9: return(0x90); break;
}
}
void output()
{
led2=1;led3=0;led4=0; //μú2??êy??1ü
div_buf=div[0];
P0=led();
delay(123);
led2=0;led3=1;led4=0;//μú3??êy??1ü
div_buf=div[1];
P0=led();
delay(123);
led2=0;led3=0;led4=1;//μú4??êy??1ü
div_buf=div[2];
P0=led();
delay(123);
led2=1;led3=1;led4=1;
delay(1230000);
}
void main(void)
{
int num=0,j=1;
TMOD=0x02;//T0·?ê?2
TH0=0xff;
TL0=0xff;
TR0=1;
EA=1;
ET0=1;
while(1)
{
DPTR=0x0000;
*DPTR=0x00;
delay(123);
st=1;
st=0;
st=1;
while(eoc==1);//μè′y×a??
{
oe=1;
ad_out=P3;
oe=0;
div[0]=ad_out/100;
div[1]=ad_out%100/10;
div[2]=ad_out%10;
}
output();
}
}
用PTOYUSE仿真的电路已经上传,麻烦高手指点迷津吧!谢过!!!!!!!
原理图.rar
(95.02 KB, 下载次数: 22)
|