我的数码管电子钟什么都没问题了,可就是按键调时间时,一按下按键整个频就黑了,松开又亮了,而且功能也都实现了,就是按下按键时会黑一下,请问各位大佬是怎么回事呢???????我在板子上实现的,应该是我的程序不完善,下面是我的程序。。。。。希望各位大佬帮忙解答下。。。。。
单片机源程序如下:
- #include<reg51.h>
- typedef unsigned int u16;
- typedef unsigned char u8;
- u8 ms0;
- u8 sec;
- u8 min;
- u8 hour;
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- sbit k1=P3^1;
- sbit k2=P3^0;
- sbit k3=P3^2;
- sbit k4=P3^3;
- u8 code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- void delay(u8 i)
- {
- i--;
- }
- void keyscan();
- void display();
- void main()
- {
- P0=0X00;
- TMOD|=0X01;
- TH0=(65536-49960)/256;
- TL0=(65536-49960)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- display();
- }
-
- }
- void display()
- {
- while(1)
- {
- LSA=0;LSB=0;LSC=0;
- P0=smgduan[sec%10];
- delay(2);
- P0=0x00;
- LSA=1;LSB=0;LSC=0;
- P0=smgduan[sec/10];
- delay(2);
- P0=0x00;
- LSA=0;LSB=1;LSC=0;
- P0=0x40;
- delay(2);
- P0=0x00;
- LSA=1;LSB=1;LSC=0;
- P0=smgduan[min%10];
- delay(2);
- P0=0x00;
- LSA=0;LSB=0;LSC=1;
- P0=smgduan[min/10];
- delay(2);
- P0=0x00;
- LSA=1;LSB=0;LSC=1;
- P0=0x40;
- delay(2);
- P0=0x00;
-
- LSA=0;LSB=1;LSC=1;
- P0=smgduan[hour%10];
- delay(2);
- P0=0x00;
- LSA=1;LSB=1;LSC=1;
- P0=smgduan[hour/10];
- delay(2);
- P0=0x00;
- }
- }
- void T0_time() interrupt 1
- {
- TH0=(65536-49960)/256;
- TL0=(65536-49960)%256;
- ms0++;
- if(ms0>=20)
- {
- ms0=0;
- sec++;
- if(sec>=60)
- {
- sec=0;
- min++;
- if(min>=60)
- {
- min=0;
- hour++;
- if(hour>=20)
- hour=0;
- }
- }
- }
- keyscan();
- }
- /*void digdisplay()
- {
- switch(a)
- {
- case(0):
- LSA=0;LSB=0;LSC=0;break;
- case(1):
- LSA=0;LSB=0;LSC=1;break;
- case(2):
- LSA=0;LSB=1;LSC=0;break;
- case(3):
- LSA=0;LSB=1;LSC=1;break;
- case(4):
- LSA=1;LSB=0;LSC=0;break;
- case(5):
- LSA=1;KSB=0;LSC=1;break;
- case(6):
- LSA=1;LSB=1;LSC=0;break;
- case(7):
- LSA=1;LSB=1;LSC=1;break;
- }
- } */
- void keyscan()
- {
- if(k1==0)
- {
- delay(5);
- if(k1==0)
- {
- min--;
- if(min>=60)
- min=0;
- }
- while(!k1);
- }
- if(k2==0)
- {
- delay(5);
- if(k2==0)
- {
- min++;
- if(min>=60)
- min=0;
- }
- while(!k2);
- }
- if(k3==0)
- {
- delay(5);
- if(k3==0)
- {
- hour--;
- if(hour>=24)
- hour=0;
- }
- while(!k3);
- }
- if(k4==0)
- {
- delay(5);
- if(k4==0)
- {
- hour++;
- if(hour>=24)
- hour=0;
- }
- while(!k4);
- }
- }
复制代码
所有资料51hei提供下载:
数码管.zip
(24.99 KB, 下载次数: 5)
|