×
单片机 > 单片机程序设计 > 详情

51单片机编写60秒倒计时程序

发布时间:2024-05-19 发布时间:
|

#include

#define guan P0

#define wei P2

#define uchar unsigned char

#define uint unsigned int

uint m=0;

uchar a1,a0,k=0,j,k,s=60;

sbit beep=P2^3;

unsigned char code weiyu[]={0x1f,0x2f,0x4f,0x8f}; //代码与P2对应做位处理,显示相应的位

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,

0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴极数码管码表

void delay(unsigned char xms)

{

for(j=xms;j>0;j--)

for(k=125;k>0;k--);

}

void display1(uchar wei1,uchar shu)

{

wei=0xff;

P0=table[shu];

wei=wei&weiyu[wei1];

delay(5);

}

void display(uchar a,uchar b)

{

display1(2,a);

display1(3,b);

}

void main()

{

TMOD=0x01;

ET0=1;

TR0=1;

EA=1;

while(1)

{

if(m==20)

{

m=0;

s--;

}

a1=s/10;

a0=s%10;

display(a1,a0);

if(s==0)

{

TR0=0;

beep=0;

}

}

}

void TO_TIMER () interrupt 1

{

TH0=(65536-46080)/256;

TL0=(65536-46080)%256;

m++;

}


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM 汇编的必知必会