智能车制作
标题:
求助
[打印本页]
作者:
重口辣泡菜
时间:
2017-12-6 22:53
标题:
求助
写了个可调时钟的程序,按键还没完全弄好,但在开关定时器和调整时间的按钮按下去后数码管上无显示,松开又恢复正常,
第一个数字比其他几个亮,这个怎么改呢?谢谢
#include <reg52.h>
#include <intrins.h>
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
sbit wela=P2^1;
sbit dula=P2^0;
unsigned char num=-1;
unsigned char tabledsq[]={0,1};
unsigned char code tabledu[]=
{0x3F,0x06,0x5B,0x4F,
0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,
0x39,0x5E,0x79,0x71,};
long s=0,m=0,h=0,shi1=0,ge1=0,shi2=0,ge2=0,shi3=0,ge3=0;
void Delay2ms(); //@11.0592MHz
void time_set();
void timer_set();
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
timer_set();
while(1)
{
shi1=s/10;
ge1=s%10;
shi2=m/10;
ge2=m%10;
shi3=h/10;
ge3=h%10;
wela=1;
P1=0x7F;
wela=0;
dula=1;
P1=tabledu[ge1];
dula=0;
Delay2ms();
wela=1;
P1=0xBF;
wela=0;
dula=1;
P1=tabledu[shi1];
dula=0;
Delay2ms();
wela=1;
P1=0xDF;
wela=0;
dula=1;
P1=0x40;
dula=0;
Delay2ms();
wela=1;
P1=0xEF;
wela=0;
dula=1;
P1=tabledu[ge2];
dula=0;
Delay2ms();
wela=1;
P1=0xF7;
wela=0;
dula=1;
P1=tabledu[shi2];
dula=0;
Delay2ms();
wela=1;
P1=0xFB;
wela=0;
dula=1;
P1=0x40;
dula=0;
Delay2ms();
wela=1;
P1=0xFD;
wela=0;
dula=1;
P1=tabledu[ge3];
dula=0;
Delay2ms();
wela=1;
P1=0xFE;
wela=0;
dula=1;
P1=tabledu[shi3];
dula=0;
Delay2ms();
time_set();
}
}
void Delay2ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 4;
j = 146;
do
{
while (--j);
} while (--i);
}
void timer0() interrupt 1
{
static long t=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
if(t==20)
{
t=0;
s++;
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
{
h=0;
}
}
}
}
}
void time_set()
{
if(key1==0)
delay(10);
if (key1==0)
{
num++;
if(num==2)
{
num=0;
}
TR0=tabledsq[num];
while(!key1);
delay(10);
while(!key1);
}
else if(key2==0)
delay(10);
if (key2==0)
{
m++;
if(m==60)
{
m=0;
}
while(!key2);
delay(10);
while(!key2);
}
else if(key3==0)
delay(10);
if (key3==0)
{
h++;
if(h==24)
{
h=0;
}
while(!key3);
delay(10);
while(!key3);
}
else if(key4==0)
delay(10);
if (key4==0)
{
h++;
if(h==24)
{
h=0;
}
while(!key4);
delay(10);
while(!key4);
}
}
void timer_set()
{
TMOD |=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
}
作者:
UPC_AE86
时间:
2017-12-7 08:04
单片机上机实验吧\笑哭
作者:
lxa0
时间:
2017-12-19 20:48
很想帮你
可惜看不懂C
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2