计数时开始都是0,可是不久后就显示乱码,
有哪位高手帮助一下,小弟在这感激不尽了,
急呀,过两天就要交板了!!
我Q是170074505,这两天我会一直在线!!
#include <AT89x51.h>
/*********************************
全局变量定义
*********************************/
unsigned char code pcode[]={215,17,205,93,27,94,222,21,223,95};//无小数点
unsigned char code chom[]={8,64,32,16,4,128}; //数码管选择
unsigned char temp[6]={0,0,0,0,0,0};
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;
/******************************************************
子函数定义
*******************************************************/
void t0(void) interrupt 1 using 1
{
T0count++;
}
void t1(void) interrupt 3 using 1 //定时2m
{
TH1=(65536-15536)/256;
TL1=(65536-15536)%256;
timecount++;
if(timecount==40)
{
TR0=0; //T0停止计数
timecount=0;
flag=1;
}
}
void get_1()
{
x=(T0count*65536+TH0*256+TL0)/2; //低频
}
void get_2()
{
x=(T0count*65536+TH0*256+TL0)*8; //高频
}
void deal() //存六位数码值
{
int i;
for(i=0;i<6;i++)
{
temp=x%10;
x=x/10;
}
}
void delay(unsigned dly)
{
unsigned i;
for(;dly>0;dly--)
for(i=50;i>0;i--);
}
void play()
{ int i;
for(i=0;i<6;i++)
{
P1=pcode[temp]; //数码显示
P2=chom; //数码管选择
delay(10);
}
}
/**************************
主函数,定时器0对外部脉冲计数,定时器1定时50m*40=2s;
****************************/
void main(void)
{
int a;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-15536)/256;
TL1=(65536-15536)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
if(flag==1)
{ a=P3&0x80;
if(a==0x80)
get_2();
else
get_1();
deal();
TR0=1; //重启T0计数
flag=0;
}
play();
}
}
a89588038 发表于 2018-8-2 09:49
我来帮你,我加你Q了
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |