单片机毕业设计----基于单片机的多功能电子时钟设计(含外文翻译) 下载本文

{

TMOD=0X01;

TH0=((65535-5000)/256); TL0=((65535-5000)%6); IE=0X82; TR0=1; }

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

void T0_srv(void) interrupt 1 {

TH0=((65535-5000)/256); TL0=((65535-5000)%6); deda++; counter++;

if(deda>=200){sec++;deda=0;} if(sec==60){min++;sec=0;} if(min==60){hour++;min=0;} if(hour==24){hour=0;} }

void disp(uchar H,uchar M,uchar S) {

P1=H/10;P3=0xDf;delay(5); P1=H;P3=0xEf;delay(5);

25

P1=M/10;P3=0xf7;delay(5); P1=M;P3=0xfB;delay(5); P1=S/10;P3=0xfD;delay(5); P1=S;P3=0xfE;delay(5) }

//---------------------延时模块-----------------------------------

void delay(uint ms) {

uchar i; }

//-----------------------------LED闪烁------------------------------

void ledsd() { LED=0; delay(500); LED=1; }

26

;

while(ms--) { }

for(i=0;i<120;i++);

//------------------------------蜂鸣器鸣响模块---------------------

void BZ(uint k) { uint i; while(k--) {

for(i=0;i<1000;i++) } }

//------------------按键扫描函数-----------------------------------

void keyscan() { if(K1==0)

{while(!K1);ledsd();K1function();}

{ SPK=~SPK;

disp(hour,min,sec);

}

if(K2==0)

{while(!K2);ledsd();K2function();}

if(K3==0)

{while(!K3);ledsd();K3function();}

if(K4==0) }

27

{while(!K4);ledsd();K4function();}

//---------------------按键功能函数--------------------------------

void K1function() { TR0=0; do { if(K2==0)

{while(!K2);hour++;hour%=24;disp(hour,min,sec);}

if(K3==0)

{while(!K3);min++;min%=60;disp(hour,min,sec);}

disp(hour,min,sec); }while(K4!=0); ledsd(); TR0=1; }

void K2function() { do { if(K2==0)

{while(K2!=0);AH++;AH%=24;disp(AH,AM,0);}

if(K3==0)

{while(K3!=0);AM++;AM%=60;disp(AH,AM,0);}

disp(AH,AM,0); }while(K4!=0);

28