数码管时钟显示按键调时间.docx

上传人:b****1 文档编号:3062204 上传时间:2023-05-05 格式:DOCX 页数:22 大小:17.95KB
下载 相关 举报
数码管时钟显示按键调时间.docx_第1页
第1页 / 共22页
数码管时钟显示按键调时间.docx_第2页
第2页 / 共22页
数码管时钟显示按键调时间.docx_第3页
第3页 / 共22页
数码管时钟显示按键调时间.docx_第4页
第4页 / 共22页
数码管时钟显示按键调时间.docx_第5页
第5页 / 共22页
数码管时钟显示按键调时间.docx_第6页
第6页 / 共22页
数码管时钟显示按键调时间.docx_第7页
第7页 / 共22页
数码管时钟显示按键调时间.docx_第8页
第8页 / 共22页
数码管时钟显示按键调时间.docx_第9页
第9页 / 共22页
数码管时钟显示按键调时间.docx_第10页
第10页 / 共22页
数码管时钟显示按键调时间.docx_第11页
第11页 / 共22页
数码管时钟显示按键调时间.docx_第12页
第12页 / 共22页
数码管时钟显示按键调时间.docx_第13页
第13页 / 共22页
数码管时钟显示按键调时间.docx_第14页
第14页 / 共22页
数码管时钟显示按键调时间.docx_第15页
第15页 / 共22页
数码管时钟显示按键调时间.docx_第16页
第16页 / 共22页
数码管时钟显示按键调时间.docx_第17页
第17页 / 共22页
数码管时钟显示按键调时间.docx_第18页
第18页 / 共22页
数码管时钟显示按键调时间.docx_第19页
第19页 / 共22页
数码管时钟显示按键调时间.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数码管时钟显示按键调时间.docx

《数码管时钟显示按键调时间.docx》由会员分享,可在线阅读,更多相关《数码管时钟显示按键调时间.docx(22页珍藏版)》请在冰点文库上搜索。

数码管时钟显示按键调时间.docx

数码管时钟显示按键调时间

#include

#defineuintunsignedint

#defineucharunsignedchar

ucharcodetable[]={

0x3f,/*0*/0x06,/*1*/0x5b,/*2*/0x4f,/*3*/

0x66,/*4*/0x6d,/*5*/0x7d,/*6*/0x07,/*7*/

0x7f,/*8*/0x6f,/*9*/0x00,/**灭*10*/0xf3,/*P.*11*/

0x40,/*-*12*/0xB7,/*n.*13*/0xF6/*H.*14*/};

//--------------------------------------------------------

//---------------------定义变量---------------------------

//--------------------------------------------------------

ucharmiao,fen,shi,miaonao,fennao,shinao,nao,gn,gnnz;

ucharflag,aa,bb,cc,dd,ck,a0,a1,a2,a3,a4,a5,a6,a7;

uintt0,t1;

bitss;

sbitbeep=P1^5;

//--------------------------------------------------------

//---------------------初始化-----------------------------

//--------------------------------------------------------

voidinit()

{

shinao=8;//初始定义闹钟时间为8点整

gn=1;

gnnz=1;

ss=0;

aa=0;

//dd=0;

bb=1;//进入调闹钟日常时间循环

cc=1;//进入调闹钟日常时间循环

//ck=1;

nao=0;

TH0=0x3c;

TL0=0xb0;

TH1=0x3c;

TL1=0xb0;//定时50ms中断一次

EA=1;//开总中断

ET0=1;//开定时器0中断

TR0=0;

ET1=1;//开定时器1中断

TR1=0;

}

//--------------------------------------------------------

//---------------------延时函数---------------------------

//--------------------------------------------------------

voiddelay(uinti)

{

uchary;

for(i;i>0;i--)

for(y=110;y>0;y--);

}

//--------------------------------------------------------

//----------------------定时器0,1----------------------

//--------------------------------------------------------

voidtimer0()interrupt1

{

TMOD=0x01;

TH0=0x3c;

TL0=0xb0;

t0++;

if(nao==0)//日常时间读秒处理

{

if(t0==20)

{

t0=0;

miao++;

if(miao==60)

{

miao=0;

fen++;

if(fen==60)

{

fen=0;

shi++;

{if(shi==24)

shi=0;

}

}

}

}

}

if(nao==1)//闹钟时间读秒处理

{

if(t0==20)

{

t0=0;

miaonao++;

if(miaonao==60)

{

miaonao=0;

fennao++;

if(fennao==60)

{

fennao=0;

shinao++;

{if(shinao==24)

shinao=0;

}

}

}

}

}

}

voidtimer1()interrupt3

{

if(dd==1)//串口调时间闹钟闪烁处理

{

RI=0;

flag=1;

delay(4);

ss=~ss;

}

if(dd==0)//按键调时间闹钟闪烁处理

{

TMOD=0x01;

TH0=0x3c;

TL0=0xb0;

t1++;

if(t1==40)

{

t1=0;

ss=~ss;

}

}

}

//--------------------------------------------------------

//-------------------数码管显示处理程序-------------------

//--------------------------------------------------------

voiddisplay(uchara7,uchara6,uchara5,uchara4,uchara3,uchara2,uchara1,uchara0)

{

P0=table[a7];

P2=0xfe;

delay

(1);

P0=table[a6];

P2=0xfd;

delay

(1);

P0=table[a5];

P2=0xfb;

delay

(1);

P0=table[a4];

P2=0xf7;

delay

(1);

P0=table[a3];

P2=0xef;

delay

(1);

P0=table[a2];

P2=0xdf;

delay

(1);

P0=table[a1];

P2=0xbf;

delay

(1);

P0=table[a0];

P2=0x7f;

delay

(1);

}

//--------------------------------------------------------

//-------------------数码管送数及闪烁---------------------

//--------------------------------------------------------

voidsend()

{

if(nao==0)//日常时间送数

{

a0=miao%10;

a1=miao/10;

a2=12;

a3=fen%10;

a4=fen/10;

a5=12;

a6=shi%10;

a7=shi/10;

}

if(nao==1)//闹钟时间送数

{

a0=miaonao%10;

a1=miaonao/10;

a2=12;

a3=fennao%10;

a4=fennao/10;

a5=12;

a6=shinao%10;

a7=shinao/10;

}

if(ss==1)

{

switch(gn)//调时间闪烁

{

case2:

a0=10,a1=10;break;

case3:

a3=10,a4=10;break;

case4:

a6=10,a7=10;break;

}

switch(gnnz)//调闹钟闪烁

{

case2:

a0=10,a1=10;break;

case3:

a3=10,a4=10;break;

case4:

a6=10,a7=10;break;

}

}

}

//--------------------------------------------------------

//-------------------------闹钟---------------------------

//--------------------------------------------------------

voidsmq()

{

if(shi==shinao)

{

if(fen==fennao)

{

if(miao==miaonao)

{

beep=0;

delay(100);

beep=1;

beep=0;

delay(100);

beep=1;

beep=0;

delay(100);

beep=1;

}

}

}

}

//--------------------------------------------------------

//---------------------按键处理程序-----------------------

//--------------------------------------------------------

ucharkeychuli()

{

uchark;

k=P1;//P1口内容送K

k=~k;//取反

k=(k&0xff);//屏蔽高4位,如果扫描8键,屏蔽该句。

return(k);//返回键值

}

ucharkey()

{

ucharkey1,key2;//电子钟键盘按键键值临时存放

key1=keychuli();//调P1口处理函数

if(key1!

=0)//有键动作延时去抖动,否则函数返回

{

send();

display(a0,a1,a2,a3,a4,a5,a6,a7);

display(a0,a1,a2,a3,a4,a5,a6,a7);

key1=keychuli();//再次调P1口处理函数

if(key1!

=0)//真正有键按下,取键值并暂存

{

key2=key1;

while(key1!

=0)//判按键是否释放,没有释放延时去抖动等待释放

{

send();

display(a0,a1,a2,a3,a4,a5,a6,a7);

display(a0,a1,a2,a3,a4,a5,a6,a7);

key1=keychuli();

}

key1=key2;//按键释放后恢复按键键值

}

}

return(key1);//返回按键键值

}

//--------------------------------------------------------

//------------------------串口初始化----------------------

//--------------------------------------------------------

/*voidck_init()//串口初始化

{

TMOD=0x20;//定时器工作方式2

TH1=0xfd;//253

TL1=0xfd;

TR1=1;//启动定时器1

REN=1;//允许串行口接收数据

SM0=0;//串口工作方式1

SM1=1;

EA=1;//开总中断

ES=1;//开串口中断

}*/

//--------------------------------------------------------

//---------------------串口调时间-------------------------

//--------------------------------------------------------

/*voidck_gn()

{

dd=1;

ss=1;

ck_init();

while(ck)

{

if(key()==2)//按键k2功能键

{

gn++;//判断按下的次数

switch(gn)

{//case1:

TR0=1;TR1=0;ss=0;break;

case2:

//一次条秒同时闪烁

case3:

//两次调分同时闪烁

case4:

TR0=0;TR1=1;ss=1;break;//三次调分同时闪烁

case5:

gn=1;TR0=1;TR1=0;ss=0;bb=0;cc=0;dd=0;ck=0;break;//四次跳出调整状态时钟继续走,gn=1循环使用

}

}

if(flag==1)//接收串口发来的数据调闹钟调时

{

switch(gn)

{

case2:

miao=SBUF;

flag=0;

if(miao>=60)

{

miao=0;

}

break;

case3:

fen=SBUF;

flag=0;

if(fen>=60)

{

fen=0;

}

break;

case4:

shi=SBUF;

flag=0;

if(shi>=24)

{

shi=0;

}

break;

}

}

send();//送数

display(a0,a1,a2,a3,a4,a5,a6,a7);//显示时间

}

}*/

//--------------------------------------------------------

//---------------------串口调闹钟-------------------------

//--------------------------------------------------------

/*voidck_gnnz()

{

dd=1;

ss=1;

ck_init();

while(ck)

{

if(key()==2)//按键k2功能键

{

gnnz++;//判断按下的次数

switch(gnnz)

{//case1:

TR0=1;TR1=0;ss=0;break;

case2:

//一次条秒同时闪烁

case3:

//两次调分同时闪烁

case4:

TR0=0;TR1=1;ss=1;break;//三次调分同时闪烁

case5:

gn=1;TR0=1;TR1=0;ss=0;bb=0;cc=0;dd=0;ck=0;break;//四次跳出调整状态时钟继续走,gn=1循环使用

}

}

if(flag==1)//接收串口发来的数据调闹钟调时

{

switch(gnnz)

{

case2:

miaonao=SBUF;

flag=0;

if(miaonao>=60)

{

miaonao=0;

}

break;

case3:

fennao=SBUF;

flag=0;

if(fennao>=60)

{

fennao=0;

}

break;

case4:

shinao=SBUF;

flag=0;

if(shinao>=24)

{

shinao=0;

}

break;

}

}

send();//送数

display(a0,a1,a2,a3,a4,a5,a6,a7);//显示时间

}

}*/

//--------------------------------------------------------

//--------------------按键调时间--------------------------

//--------------------------------------------------------

voidajgn()

{

while(cc)

{

display(10,10,10,10,10,10,10,14);

if(key()==1)

{

while(bb)

{

if(key()==16)

{

TR0=1;TR1=0;ss=0;bb=0;cc=0;

}

switch(key())

{

case2:

//按键k2功能键

{

gn++;//判断按下的次数

switch(gn)

{//case1:

TR0=1;TR1=0;ss=0;break;

case2:

//一次条秒同时闪烁

case3:

//两次调分同时闪烁

case4:

TR0=0;TR1=1;ss=1;break;//三次调分同时闪烁

case5:

gn=1;TR0=1;TR1=0;ss=0;bb=0;cc=0;break;//四次跳出调整状态时钟继续走,gn=1循环使用

}

}

break;

case4:

//k3键上调

{

switch(gn)

{

case1:

break;

case2:

miao++;if(miao==60)miao=0;break;

case3:

fen++;if(fen==60)fen=0;break;

case4:

shi++;if(shi==24)shi=0;break;

}

}

break;

case8:

//k4键下调

{

switch(gn)

{

case1:

break;

case2:

miao--;if(miao==255)miao=59;break;

case3:

fen--;if(fen==255)fen=59;break;

case4:

shi--;if(shi==255)shi=23;break;

}

}

break;

}

send();//送数

display(a0,a1,a2,a3,a4,a5,a6,a7);//显示时间

}

}

}

}

//--------------------------------------------------------

//-----------------------按键调闹钟-----------------------

//--------------------------------------------------------

voidajgnnz()

{

while(cc)

{

display(10,10,10,10,10,10,10,13);

if(key()==1)

{

while(bb)

{

if(key()==16)

{

TR0=1;TR1=0;ss=0;nao=0;bb=0;cc=0;

}

switch(key())

{

case2:

//按键k2闹钟功能键

{

//miaonao++;if(miaonao==60)miaonao=0;

gnnz++;//判断按下的次数

switch(gnnz)

{//case1:

TR0=1;TR1=0;ss=0;break;

case2:

//一次条秒同时闪烁

case3:

//两次调分同时闪烁

case4:

TR0=0;TR1=1;ss=1;break;//三次调分同时闪烁

case5:

gnnz=1;TR0=1;TR1=0;ss=0;nao=0;bb=0;cc=0;break;//四次跳出调整状态时钟继续走,gnn1=1循环使用

}

}

break;

case4:

//k3键闹钟上调

{//fennao++;if(fennao==60)fennao=0;

switch(gnnz)

{

case1:

break;

case2:

miaonao++;if(miaonao==60)miaonao=0;break;

case3:

fennao++;if(fennao==60)fennao=0;break;

case4:

shinao++;if(shinao==24)shinao=0;break;

}

}

break;

case8:

//k4键闹钟下调

{//shinao++;if(shinao==24)shinao=0;

switch(gnnz)

{

case1:

break;

case2:

miaonao--;if(miaonao==255)miaonao=59;break;

case3:

fennao--;if(fennao==255)fennao=59;break;

case4:

shinao--;if(shinao==255)shinao=23;break;

}

}

break;

}

send();//送数

display(a0,a1,a2,a3,a4,a5,a6,a7);//显示闹钟时间

}

}

}

}

//------------------------

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2