本帖最后由 qq124469142 于 2011-6-2 14:18 编辑
#include <AT89C51.H>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char code dispcode[]={0x44,0xD7,0x1C,0x15,0x87,
0x25,0x24,0x57,0x04,0x05};
unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
unsigned int delay_count=0;
bit flag;
unsigned long x;
void main(void)
{
unsigned char i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<8;i++)
{
temp=0;
}
i=0;
while(x/10)
{
temp=x%10;
x=x/10;
i++;
}
temp=x;
for(i=0;i<6;i++)
{
dispbuf=temp;
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
delay_count++;
if(delay_count>=100)
{
delay_count=0;
P0=0xff;
P2=dispcode[dispbuf[dispcount]];
P0=dispbit[dispcount];
dispcount++;
if(dispcount>=6)
{
dispcount=0;
}
}
}
}
void t0(void) interrupt 1 using 0
{
T0count++;(脉冲计数溢出)
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
timecount++;
if(timecount>=20)
{
TR0=0;
timecount=0;
flag=1;
}
本人大一,做出不易
第一次做的。请各位高手指教,并且提出修改意见。
基于LM331和单片机的电压测量 通过单片机输出显示频率,之后算出输入电压。 |