8位数码管时钟显示格式为11-11-11,当如果调整时、分、秒任时,能让其中的两位数码管闪烁,其余不变。
单片机源程序如下:
- #include <reg52.h>
- #include "MACROANDCONST.H"
- #include "DISPLAY.H"
- #include "LCD.H"
- sbit Shift=P2^5;
- sbit Plu=P2^6;
- sbit Red=P2^7;
- uchar KeyNum;
- void
- void KeyScan()
- {
- if(Shift==0)
- {
- Delay_ms(5);
- if(Shift==0)
- {
- KeyNum++;
- while(!Shift);
- if(KeyNum==1)
- {
- TR0=0;
- WriteCommandLCD(0x80+0x44+7,1);
- WriteCommandLCD(0X0f,1);
- }
- }
- if(KeyNum==2)
- {
- WriteCommandLCD(0x80+0x44+4,1);
- WriteCommandLCD(0X0f,1);
- }
- if(KeyNum==3)
- {
- WriteCommandLCD(0x80+0x44+1,1);
- WriteCommandLCD(0X0f,1);
- }
- if(KeyNum==4)
- {
- KeyNum=0;
- WriteCommandLCD(0X0c,1);
- TR0=1;
- }
- }
- if(KeyNum!=0)
- {
- if(Plu==0)
- {
- Delay_ms(5);
- if(Plu==0)
- {
- while(!Plu);
- if(KeyNum==1)
- {
- Miao++;
- if(Miao>=60)
- Miao=0;
- Write_SFM(6,Miao);
- WriteCommandLCD(0x80+0x44+7,1);
- }
- if(KeyNum==2)
- {
- Fen++;
- if(Fen>=60)
- Fen=0;
- Write_SFM(3,Fen);
- WriteCommandLCD(0x80+0x44+4,1);
- }
- if(KeyNum==3)
- {
- Shi++;
- if(Shi>=24)
- Shi=0;
- Write_SFM(0,Shi);
- WriteCommandLCD(0x80+0x44+1,1);
- }
- }
- }
-
- if(Red==0)
- {
- Delay_ms(5);
- if(Red==0)
- {
- while(!Red);
- if(KeyNum==1)
- {
- Miao--;
- if(Miao<=-1)
- Miao=59;
- Write_SFM(6,Miao);
- WriteCommandLCD(0x80+0x44+7,1);
- }
- if(KeyNum==2)
- {
- Fen--;
- if(Fen<=-1)
- Fen=59;
- Write_SFM(3,Fen);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
时钟.rar
(49.96 KB, 下载次数: 20)
|