标题:
51单片机倒计时程序
[打印本页]
作者:
yyl
时间:
2014-12-12 16:27
标题:
51单片机倒计时程序
时钟倒计时
xx.zip
2014-12-12 16:27 上传
点击文件名下载附件
下载积分: 黑币 -5
29.2 KB, 下载次数: 102, 下载积分: 黑币 -5
倒计时
作者:
admin
时间:
2014-12-12 17:36
好资料 下面是楼主的源码
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit KEY1 = P3^2;
sbit KEY2 = P3^3;
sbit KEY3 = P3^4;
uint hour=12,min=23,sec=33;
uint flag=1;
uint Count = 0;
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码管段值
void Delay(uint del)
{ uchar i,j;
for(i=0; i<del; i++)
for(j=0; j<140; j++)
;}
void Time0_Init()
{ Count++;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;}
void timer0_int(void)interrupt 1
{
Count++;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256; }
void time()
{ P2=7;
P0=table[sec%10];
Delay(1);
P2=6;
P0=table[sec/10];
Delay(1);
P2=5;
P0=0x40;
Delay(1);
P2=4;
P0=table[min%10];
Delay(1);
P2=3;
P0=table[min/10];
Delay(1);
P2=2;
P0=0x40;
Delay(1);
P2=1;
P0=table[hour%10];
Delay(1);
P2=0;
P0=table[hour/10];
Delay(1); }
void Key(void)
{ if(KEY1==0 ) //计时开始
{Delay(1); //20毫秒软件防抖
if(KEY1==0)
TR0=1; }
if(KEY2==0 )
{ Delay(1);
if(KEY2 == 0)
TR0=0;
Delay(1);}
if(KEY3==0 ) //改变加减法
{Delay(1); //20毫秒软件防抖
if(KEY3 == 0)
flag=!flag;
Delay(1);
}
}
void Main(void)
{ Time0_Init();
while(1)
{ time();
Key();
if(Count == 100)
{ Count=0;
if(flag==1) //type=1时为加法
{ sec++;
if(sec>59)
{ sec=0;
min++;
if(min>59)
{min=0;
hour++;
if(hour>23)
hour=0; }} }
else if(flag==0)
{sec--;
if(sec<1)
{sec=59;
min--;
if(min<1)
{min=59;
hour--;
if(hour<1)
hour=23;} } }
}
}}
作者:
oldoldpotato
时间:
2018-1-8 15:20
牛批牛批
作者:
七猴
时间:
2019-7-28 15:28
这个数码管的选通端是直接连的计数器吗?P2是对应的什么?直接就是位码吗?
作者:
6313
时间:
2021-7-14 10:15
有电路图吗
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1