问题:
本电路共有两个显示模块,分为数码管和点阵显示。在分别调试两个显示程序时没有问题,综合后就发现两个显示有明显的闪烁感。怀疑是执行程序为顺序执行,导致延时时间太长。特求解各位大神。
附原理图:
程序:
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char
sbit IO = P2^0;
sbit SCLK = P2^1;
sbit RST = P2^2;
sbit duan = P2^6;
sbit wei = P2^7;
sbit duan1 = P2^3;
sbit wei1 = P2^4;
sbit led = P2^5;
char t1=0;
uchar DateTime[7];
void display(uint t );
void display1(uchar shu);
uchar shu;
uchar temp=0;
uchar code M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0x00};
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
uchar code weixuan[]=
{
0x01,0x02,0x04,0x08
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=1;y>0;y--);
}
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<1;i++);
}
}
void Write_A_Byte_TO_DS1302(uchar x) //
{
uchar i;
for(i=0;i<8;i++)
{
IO=x&0x01;SCLK=1;SCLK=0;x>>=1;
}
}
uchar Get_A_Byte_FROM_DS1302()
{
uchar i,b=0x00;
for(i=0;i<8;i++)
{
b |= _crol_((uchar)IO,i);
SCLK=1;SCLK=0;
}
return b/16*10+b%16;
}
uchar Read_Data(uchar addr)
{
uchar dat;
RST = 0;SCLK=0;RST=1;
Write_A_Byte_TO_DS1302(addr);
dat = Get_A_Byte_FROM_DS1302();
SCLK=1;RST=0;
return dat;
}
void GetTime()
{
uchar i,addr = 0x81; //从分钟开始取数字
for(i=0;i<3;i++)
{
DateTime[i]=Read_Data(addr);addr+=2;
}
}
void main()
{
uint temp1;
TMOD = 0x01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
IT0 = 1;
TR0 = 1;
IE = 0x83; //中断使能
P1 = 0x00;
while(1)
{
GetTime();
temp1= DateTime[1]+DateTime[2]*60 ;
display(temp1);
//display1( DateTime[0]) ;
}
}
void Show_Dot_Matrix() interrupt 1
{
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
if(++temp==20)
{
temp=0;
led=~led ;
}
}
void display1(uchar shu)
{
uchar lie1,lie2,lie3,lie4,lie5,lie6,lie7,lie8,j;
if(0<shu&&shu<8)
{
lie1=shu%8;
lie2=8;
lie3=8;
lie4= 8;
lie5= 8;
lie6= 8;
lie7= 8;
lie8= 8;
}
if(8<=shu&&shu<16)
{
lie1=7;
lie2=(shu-8)%8;
lie3= 8;
lie4= 8;
lie5= 8;
lie6= 8;
lie7= 8;
lie8= 8;
}
if(16<=shu&&shu<24)
{
lie1=7;
lie2=7;
lie3=(shu-16)%8;
lie4= 8;
lie5= 8;
lie6= 8;
lie7= 8;
lie8= 8;
}
if(24<=shu&&shu<32)
{
lie1=7;
lie2=7;
lie3=7;
lie4=(shu-24)%8;
lie5= 8;
lie6= 8;
lie7= 8;
lie8= 8;
}
if(32<=shu&&shu<41)
{
lie1=7;
lie2=7;
lie3=7;
lie4=7;
lie5=(shu-32)%8;
lie6= 8;
lie7= 8;
lie8= 8;
}
if(40<=shu&&shu<48)
{
lie1=7;
lie2=7;
lie3=7;
lie4=7;
lie5=7;
lie6=(shu-40)%8;
lie7= 8;
lie8= 8;
}
if(48<=shu&&shu<56)
{
lie1=7;
lie2=7;
lie3=7;
lie4=7;
lie5=7;
lie6=7;
lie7=(shu-48)%8;
lie8= 8;
}
if(56<=shu&&shu<64)
{
lie1=7;
lie2=7;
lie3=7;
lie4=7;
lie5=7;
lie6=7;
lie7=7;
lie8=(shu-56)%8;
}
wei1=0;
duan1=0;
for(j=0;j<10;j++)
{
wei1=1 ;
P1 =0x01;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie1];
delay(2);
duan1=0;
P1 =0x00;
delay(2);
wei1=1;
P1 =0x02;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie2];
duan1=0;
delay(2) ;
wei1=1 ;
P1 =0x04;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie3];
duan1=0;
delay(2) ;
wei1=1;
P1 =0x08;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie4];
duan1=0;
delay(2) ;
wei1=1;
P1 =0x10;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie5];
duan1=0;
delay(2) ;
wei1=1 ;
P1 =0x20;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie6];
duan1=0;
delay(2) ;
wei1=1;
P1 =0x40;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie7];
duan1=0;
delay(2) ;
wei1=1;
P1 =0x80;
wei1=0;
delay(1);
duan1=1;
P1 = ~M[lie8];
duan1=0;
delay(2) ;
}
}
void display(uint t ) //数码管任意数显式,
{
char shi1,shi2,fen1,fen2; //1代表十位 2代表个位
char i=3;
fen2=t%10;
fen1=t%60/10;
shi2=t/60%10;
shi1=t/60/10;
while(i--)
{
wei=1;
P0=~weixuan[0];
wei=0;
duan=1;
P0=LEDData[shi1];
delay(3);
P0=0x00;
duan=0;
wei=1;
P0=~weixuan[1];
wei=0;
duan=1;
P0=LEDData[shi2];
delay(3);
P0=0x00;
duan=0;
wei=1;
P0=~weixuan[2];
wei=0;
delay(1);
duan=1;
P0=LEDData[fen1];
delay(3);
duan=0;
wei=1;
P0=~weixuan[3];
wei=0;
duan=1;
P0=LEDData[fen2];
delay(3);
duan=0;
}
} |