200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 单片机数码管万年历c语言 基于51单片机和数码管的万年历程序

单片机数码管万年历c语言 基于51单片机和数码管的万年历程序

时间:2021-11-21 13:22:21

相关推荐

单片机数码管万年历c语言 基于51单片机和数码管的万年历程序

#define uChar unsigned char

#define uInt unsigned int

uChar a []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

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 Key1 = P3^7; //计时停止

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;ifor(j=0;j<125;j++)

;

}

void Dispaly1(uChar second,uChar minute,uChar hour)

{

P2=b[0];

P0=a[hour/10];

Delayms(5);

P2=b[1];

P0=a[hour%10];

Delayms(5);

P2=b[2];

P0=0x40;

Delayms(5);

P2=b[3];

P0=a[minute/10];

Delayms(5);

P2=b[4];

P0=a[minute%10];

Delayms(5);

P2=b[5];

P0=0x40;

Delayms(5);

P2=b[6];

P0=a[second/10];

Delayms(5);

P2=b[7];

P0=a[second%10];

Delayms(5);

}

void Dispaly2(uChar day,uChar month,uChar year)

{

P2=b[0];

P0=a[day/10];

Delayms(5);

P2=b[1];

P0=a[day%10];

Delayms(5);

P2=b[2];

P0=0x40;

Delayms(5);

P2=b[3];

P0=a[month/10];

Delayms(5);

P2=b[4];

P0=a[month%10];

Delayms(5);

P2=b[5];

P0=0x40;

Delayms(5);

P2=b[6];

P0=a[year/10];

Delayms(5);

P2=b[7];

P0=a[year%10];

Delayms(5);

}

void Keyscan1()

{

staticuChar 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;

}

}

}

void Keyscan2()

{

staticuChar 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;

}

}

}

void main()

{

TMOD=0x01;

TH0=(65536-10000)/256;

TL0=(65536-10000)%256;

EA=1;

ET0=1;

TR0=1;

while(1)

{

staticuChar 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();

}

}

}

void time0_int(void) interrupt 1

{

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;

}

}

}

}

}

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。