牛肉体育网

您现在的位置是: 首页 > 比赛信息

文章内容

单片机课程设计60秒倒计时,基于单片机奥运会倒计时

tamoadmin 2024-05-28
1.利用单片机设计实现一个60秒倒计时显示装置,并且计时到后发出报警声音。2.单片机 60秒倒计时#include<reg51.h>#define

1.利用单片机设计实现一个60秒倒计时显示装置,并且计时到后发出报警声音。

2.单片机 60秒倒计时

单片机课程设计60秒倒计时,基于单片机奥运会倒计时

#include<reg51.h>

#define uchar unsigned char

uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9

unsigned char sec=0,min=0,hour=24,scanled;

unsigned char key,mode,time;

unsigned char disdat[8];

unsigned char alarm[3]={23,59,58},dly;

sbit keyhu=P1^0;

sbit keyhd=P1^1;

sbit keymu=P1^2;

sbit keymd=P1^3;

sbit keysu=P1^4;

sbit keysd=P1^5;

sbit keyst=P1^6;

sbit fmq=P3^0;

bit flag=0;

void delay(unsigned int x)

{

unsigned int i,j;

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

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

}

void dischg()

{

disdat[0]=sec%10;

disdat[1]=sec/10;

disdat[2]=min%10;

disdat[3]=min/10;

disdat[4]=hour%10;

disdat[5]=hour/10;?

}

void t0isr() interrupt 1?//秒计时

{

TH0=0x3c;

TL0=0xb0;

time++;

switch(mode)

{

case 0:

if(time==20)

{

time=0;

sec++;

if(sec>59)

{

sec=0;

min++;

if(min>59)

{

min=0;

hour++;

if(hour>23)hour=0;

}

}

}

break;

case 1:

if(time==20)

{

time=0;

if(sec>0 && flag==0)sec--;

else if(min>0 && flag==0){sec=59;min--;}

else if(hour>0 && flag==0){sec=59;min=59;hour--;}

if((hour == alarm[0]) && (min == alarm[1]) && (sec == alarm[2])){fmq=1;flag=1;dly++;}

}

break;

}

if(dly>=2){fmq=0;flag=0;TR0=0;dly=0;}

dischg();

}

void t1isr() interrupt 3?//显示

{

TH1=0xec;

TL1=0x78;

switch(scanled)

{

case 0:

P2=0x20;

P0=~ledtab[disdat[5]];

break;

case 1:

P2=0x10;

P0=~ledtab[disdat[4]]&0x7f;

break;

case 2:

P2=0x08;

P0=~ledtab[disdat[3]];

break;

case 3:

P2=0x04;

P0=~ledtab[disdat[2]]&0x7f;

break;

case 4:

P2=0x02;

P0=~ledtab[disdat[1]];

break;

case 5:

P2=0x01;

P0=~ledtab[disdat[0]];

break;

default:break;

}

scanled++;

scanled%=6;

}

main()

{

TMOD=0x11;

TH0=0x3c;

TL0=0xb0;

TH1=0xec;

TL1=0x78;

TR1=1;

TR0=0;

ET0=1;

ET1=1;

EA=1;

fmq=0;

scanled=0;

time=0;

mode=1;

dischg();

while(1)

{

if(keyhu==0)

{

while(keyhu==0);

TR0=0;

hour++;

hour%=24;

}

if(keyhd==0)

{

while(keyhd==0);

TR0=0;

if(hour>0)hour--;

if(hour==0)hour=23;

}

if(keymu==0)

{

while(keymu==0);

TR0=0;

min++;

min%=60;

}

if(keymd==0)

{

while(keymd==0);

TR0=0;

if(min>0)min--;

if(min==0)min=59;

}

if(keysu==0)

{

while(keysu==0);

TR0=0;

sec++;

sec%=60;

}

if(keysd==0)

{

while(keysd==0);

TR0=0;

if(sec>0)sec--;

if(sec==0)sec=59;

}

if(keyst==0)

{

while(keyst==0);

TR0=~TR0;

}

dischg();

}

}

利用单片机设计实现一个60秒倒计时显示装置,并且计时到后发出报警声音。

A1 输入 2008-8-8 8:8:8

A2 输入 =NOW()

A3 输入 =A1-A2

A4 输入:

=INT(A3)&"天"&TEXT(A3-INT(A3),"h时m分s秒")

A4 便是倒计时

如要倒计时每秒运行, 便要执行宏, VBA代码:

Sub Olympic()

ActiveSheet.Calculate

Application.OnTime Now + TimeValue("00:00:01"), "Olympic"

End Sub

如需停止倒计时, 要另多写一个宏

单片机 60秒倒计时

#include<reg52.h>

sbit?bz=P3^1;

unsigned?char?a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90};

unsigned?char?n,time=60;

main()

{

P1=a[0];

P2=a[6];

TMOD=0X01;

TH0=(65536-10000)/256;

TL0=(65536-10000)%256;

EA=1;

ET0=1;

TR0=1;

while(1);

}

timer0()?interrupt?1

{

TH0=(65536-10000)/256;

TL0=(65536-10000)%256;

if(time!=0)

{

n++;

if(n==100)

{

n=0;

time--;

P1=a[time%10];

P2=a[time/10];

}

}

else?bz=~bz;

}

我是用汇编语言做的,如果显示的速度不理想 你改下延时程序段的数值就OK了,课堂上这个60S倒计时的课题用了很多方法做过

ORG 0000H

LJMP START

ORG 0100H

START:MOV R0, #59

MOV DPTR, #TABLE

LOOP:LCALL DISPLAY

DEC R0

CJNE R0,#0,LOOP

JMP START

DISPLAY:MOV A, R0

MOV B, #10

DIV AB

MOV R1, A

MOV R2, B

MOV R3, #50

LOOP1:MOV A, R2

LCALL CHANG

CLR P2.6

LCALL DLY10MS

SETB P2.6

MOV A, R1

LCALL CHANG

CLR P2.7

LCALL DLY10MS

SETB P2.7

DJNZ R3, LOOP1

RET

CHANG:MOVC A, @A+DPTR

MOV P0, A

RET

DLY10MS:MOV R6, #256

D1:MOV R7, #256

NOP

NOP

NOP

NOP

DJNZ R7, $

DJNZ R6, D1

RET

TABLE:DB 28H,7EH,0A4H,64H,72H,61H,21H,7CH,20H,60H

END