历史上的今天
今天是:2025年03月05日(星期三)
2020年03月05日 | 基于51单片机和数码管的万年历程序
2020-03-05 来源:eefocus
可实现功能:
启动程序数码管按照××-××-××格式显示时分秒并走时
按下C1按钮后按照××-××-××格式显示年月日
按下C3调时模式按钮时分秒/年月日静止,指示灯亮起,进入调时模式
先按C2选位按钮再按下C0加一按钮,对应的位置改变
再次按下C3按钮退出调时模式,继续走时
#include uChar a []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; sbit Key1 = P3^7; //计时停止 void Dispaly1(uChar second,uChar minute,uChar hour) P2=b[0]; P2=b[2]; P2=b[3]; P2=b[5]; P2=b[6]; P2=b[0]; P2=b[2]; P2=b[3]; P2=b[5]; P2=b[6]; void Keyscan1() void Keyscan2() void main() void time0_int(void) interrupt 1
#define uChar unsigned char
#define uInt unsigned int
uChar b []={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uChar second=00,minute=00,hour=10,year=17,month=01,day=11,count;
sbit Key2 = P3^6; //调位
sbit Key3 = P3^0; //加一
sbit Key4 = P3^2; //切换
sbit LED1 = P1^7;
void Delayms(uInt t)
{
uInt i,j;
for(i=0;i
;
}
{
P0=a[hour/10];
Delayms(5);
P2=b[1];
P0=a[hour%10];
Delayms(5);
P0=0x40;
Delayms(5);
P0=a[minute/10];
Delayms(5);
P2=b[4];
P0=a[minute%10];
Delayms(5);
P0=0x40;
Delayms(5);
P0=a[second/10];
Delayms(5);
P2=b[7];
P0=a[second%10];
Delayms(5);
}
void Dispaly2(uChar day,uChar month,uChar year)
{
P0=a[day/10];
Delayms(5);
P2=b[1];
P0=a[day%10];
Delayms(5);
P0=0x40;
Delayms(5);
P0=a[month/10];
Delayms(5);
P2=b[4];
P0=a[month%10];
Delayms(5);
P0=0x40;
Delayms(5);
P0=a[year/10];
Delayms(5);
P2=b[7];
P0=a[year%10];
Delayms(5);
}
{
static uChar i=0,j=0;
if(Key1==0)
{
Delayms(10); //消抖
if(Key1==0)
while(!Key1); //等待按键弹起
i++;
}
if(i%2==1)
{
LED1=0;
TR0=0;
}
if(i%2==0)
{
LED1=1;
TR0=1;
}
if(Key2==0)
{
Delayms(10);
if(Key2==0)
while(!Key2);
j++;
}
if(j%4==1)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
second++;
if(second==60)
second=0;
}
}
if(j%4==2)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
minute++;
if(minute==60)
minute=0;
}
}
if(j%4==3)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
hour++;
if(hour==24)
hour=0;
}
}
}
{
static uChar m=0,n=0;
if(Key1==0)
{
Delayms(10);
if(Key1==0)
while(!Key3);
m++;
}
if(m%2==1)
{
LED1=0;
TR0=0;
}
if(m%2==0)
{
LED1=1;
TR0=1;
}
if(Key2==0)
{
Delayms(10);
if(Key2==0)
while(!Key2);
n++;
}
if(n%4==1)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
day++;
if(day==30)
day=0;
}
}
if(n%4==2)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
month++;
if(month==12)
month=0;
}
}
if(n%4==3)
{
if(Key3==0)
{
Delayms(10);
if(Key3==0)
while(!Key3);
year++;
if(year==99)
year=0;
}
}
}
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
static uChar h=0;
if(Key4==0)
{
Delayms(10);
if(Key4==0)
while(!Key4);
h++;
}
if(h%2==1)
{
Dispaly2(year,month,day);
Keyscan2();
}
if(h%2==0)
{
Dispaly1(second,minute,hour);
Keyscan1();
}
}
}
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
count++;
if(count==100)
{
count=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
day++;
if(day==30)
{
day=0;
month++;
if(month==12)
{
month=0;
year++;
if(year==99)
{
year=0;
}
}
}
}
}
}
}
}
上一篇:51单片机EA=1的问题
下一篇:51单片机-指针方法-串口实例
史海拾趣
|
memory-mapped registers 的具体含义? RT TI DSP中memory-mapped registers是指实际在DSP中存在的寄存器还是仅在存储器中存在的呢? 小弟很菜,望各位大哥多多指教!… 查看全部问答> |
|
我用PB编译好了winCE内核后,已经把镜像下载到了目标平台上,跑起来了。现在下一步是开发应用程序,就是把evc下的应用程序也下载到目标平台上。我不想使用把应用程序编译到内核然后一起下载到目标板上的的方法,觉得那样不够灵活。请问内核下载到目 ...… 查看全部问答> |
|
当波特率为19200,38400或者57600时,电脑接收到的数据正常,当用9600时,电脑接收到的数据有时候被分成两部分。 这会是什么原因,请指点。 图片.pdf (36.88 KB) 下载次数:63 2009-12-7 17: ...… 查看全部问答> |




