|
学校要求做一个24小时的时钟 格式为 XX:XX (小时:分钟) 程序已经完成 但是显示的时候应该熄灭的灯管确实微微亮着的 比如应该显示6的时候 却有些像8 老师说是学校的设备达不到要求 如果使用两个中断就可以解决
我不知道该如何弄 还请各位大大赐教 多谢
code:
- #include
- #include
- #include "d:\Keil\Lcd.h"
- #include "d:\Keil\serial.h"
- #include "d:\Keil\keyboard.h"
- #define MinutesButton KEY7
- #define ToggleNameLed 0x01
- #define HoursButton KEY6
- #define PowerButton KEY0
- int i=0,dot=0,dotm=0;
- int disp=1,j=0;
- int count=0;
- int seg[10] = {0xAF,0xA0,0xCD,0xE9,0xE2,0x6B,0x6F,0xA1,0xEF,0xEB};
- int digit[4]={4,2,3,1};
- void inittimer(void)
- {
- EAL=0;
- TMOD=0X01;
- TR0=1;
- ET0=1;
- TL0=0x17;
- TH0=0xFC;
- EAL=1;
- }
- void task1 (void) interrupt 1
- {
- TL0=0X17;
- TH0=0XFC;
- count++;
- dotm++;
- }
-
- void main(void)
- {
- int sec=0;
- int min=0;
- int Tmin=0;
- int hour=0;
- int Thour=0;
- int minutes=0;
- LcdInit();
- KeyboardInit();
- port_init();
- inittimer();
- digit[0] = 0;
- digit[2] = 0;
- digit[1] = 0;
- digit[3] = 0;
- LcdSetXY(1,0);
- LcdString("power is on");
- while(1){
- i++;
- if (i > 3)
- {
- i=0;
- }
-
- disp*=2;
- if (dotm>500)
- {
- dot=dot^0x10;
- dotm=0;
- }
-
- if (disp >8)
-
- {
- disp =1;
- }
-
-
- P5=disp|0xC0;
-
- P1=seg[digit[i]] | dot;
-
- if(count>=1000)
- {
- sec++;
- count=0;
- }
-
- digit[0] = min;
- digit[2] = Tmin;
- digit[1] = hour;
- digit[3] = Thour;
-
- if(!(P5&0x40))
- {
-
-
- if (count>30)
- {
- if (min<9)
-
- {
- min++;
- }
- else if (min==9)
-
- {
- Tmin++;
- min=0;
- }
-
- count=0;
- }
-
- }
- if(!(P5&0x80))
- {
-
- if (count>30)
- {
- if (min>0)
- {
- min--;
- }
- else if ((min==0)&&(Tmin>0))
-
- {
- Tmin--;
- min=9;
- }
- else if ((min==0)&&(Tmin==0)&&(hour>0))
- {
- Tmin=5;
- min=9;
- hour--;
- }
- else if ((min==0)&&(Tmin==0)&&(hour==0)&&(Thour>0))
- {
- min=9;
- Tmin=5;
- hour=9;
- Thour--;
- }
- else if ((min==0)&&(Tmin==0)&&(hour==0)&&(Thour==0))
- {
- min=9;
- Tmin=5;
- hour=3;
- Thour=2;
- }
- count=0;
-
- }
-
- }
- if(sec==59)
- {
- if (min<9)
- {
- min++;
- }
- else if (min==9)
- {
- Tmin++;
- min=0;
- }
- sec=0;
- }
-
- else if((Tmin==6)&&(min==0))
- {
- if ((Thour<2)&&(hour<9))
- {
- hour++;
- }
- else if ((Thour<2)&&(hour==9))
- {
- Thour++;hour=0;
- }
- else if ((Thour==2)&&(hour<3))
- {
- hour++;
- }
- else if ((Thour==2)&&(hour==3))
- {
- Thour=0;
- hour=0;
- }
- Tmin=0;
- }
- }
-
-
-
-
-
- }
-
复制代码
|
|