您的位置 首页 硬件

单片机–电子时钟(C51)

简单电子时钟的C程序代码,没有消隐,没有按键功能author:hellowordincludedefineuintunsignedintdefineucharunsignedcharsbitsego

//简略电子时钟的C程序代码,没有消隐,没有按键功用

//author:helloword

#include

#defineuintunsignedint

#defineucharunsignedchar

sbitsegoe=P1^3;//数码管的使能操控端,低电平有用

sbitduanxuan=P1^4;//数码管的段选操控,7段发光LED显现

sbitweixuan=P1^5;//数码管的位选操控,8个数码管的挑选

ucharcodesmg_duan[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码管段选码表,咱们的数码管是共阴极数码管

ucharcodesmg_wei[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

uinttime_flag=20;

uintsecond=0;

uintminute=02;

uinthour=10;

voiddisplay();

voiddelay(uint);

voidmain()

{

TMOD=0x01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

TR0=1;

ET0=1;

EA=1;

segoe=0;

while(1)

display();

}

voidInt_T0(void)interrupt1

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

time_flag–;

if(time_flag==0)

{

second++;

time_flag=20;

}

}

voiddisplay()

{

uintsec_1,sec_2;

uintmin_1,min_2;

uinthou_1,hou_2;

weixuan=1;

P0=smg_wei[2];

weixuan=0;

duanxuan=1;

P0=0x40;

duanxuan=0;

delay(3);

weixuan=1;

P0=smg_wei[5];

weixuan=0;

duanxuan=1;

P0=0x40;

duanxuan=0;

delay(3);

if(second<60)

{

sec_2=second/10;

sec_1=second;

weixuan=1;

P0=smg_wei[0];

weixuan=0;

duanxuan=1;

P0=smg_duan[sec_1];

duanxuan=0;

delay(3);

weixuan=1;

P0=smg_wei[1];

weixuan=0;

duanxuan=1;

P0=smg_duan[sec_2];

duanxuan=0;

delay(3);

}

if(minute<60)

{

min_2=minute/10;

min_1=minute;

weixuan=1;

P0=smg_wei[3];

weixuan=0;

duanxuan=1;

P0=smg_duan[min_1];

duanxuan=0;

delay(3);

weixuan=1;

P0=smg_wei[4];

weixuan=0;

duanxuan=1;

P0=smg_duan[min_2];

duanxuan=0;

delay(3);

}

if(hour<24)

{

hou_2=hour/10;

hou_1=hour;

weixuan=1;

P0=smg_wei[6];

weixuan=0;

duanxuan=1;

P0=smg_duan[hou_1];

duanxuan=0;

delay(3);

weixuan=1;

P0=smg_wei[7];

weixuan=0;

duanxuan=1;

P0=smg_duan[hou_2];

duanxuan=0;

delay(3);

}

if(second==60){minute++;second=0;}

if(minute==60){hour++;minute=0;second=0;}

if(hour==24){second=0;minute=0;hour=0;}

}

voiddelay(uintz)

{

uinti,j;

for(i=z;i>0;i–)

for(j=95;j>0;j–);

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/yingjian/261737.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部