標(biāo)題:
可以幫我把這段單片機(jī)程序數(shù)碼管顯示部分改成倒計(jì)時(shí)的那種嗎?
[打印本頁(yè)]
作者:
17809278269
時(shí)間:
2019-5-9 07:34
標(biāo)題:
可以幫我把這段單片機(jī)程序數(shù)碼管顯示部分改成倒計(jì)時(shí)的那種嗎?
#include<reg52.h>
unsigned char code LedChar[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned int cnt = 0;
#define uchar unsigned char//宏定義
#define uint unsigned int//宏定義
bit flag=0;
uchar b=0;//秒計(jì)數(shù)
unsigned char i = 0;
//unsigned char s1;
sbit k1=P1^1;
sbit k2=P1^4;
sbit L1=P3^4;
void Timer0Init(void);
void key_scan();
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
void main()
{
P0=0X00;
Timer0Init();
// display(0);
while(1)
{
key_scan();
if(cnt>1000)
{
cnt=0;
b++;
}
if(L1==0)
{
ET0=1;
P0=LedChar[b];
}
if(b>9)
{
L1=1;
b=0;
ET0=0;
}
}
}
void key_scan()
{
if(k1==0) //夜晚
{
if(k1==0)
{
if(k2==0) //有聲音
{
delay(10);//延時(shí)10毫秒
if(k2==0)
{
L1=0;
}
}
}
}
}
void InterruptTime0() interrupt 1
{
TL0 = 0x18; //設(shè)置定時(shí)初值
TH0 = 0xFC; //設(shè)置定時(shí)初值
cnt++;
}
void Timer0Init(void) //1毫秒@12.000MHz
{
P1&= 0x7F; //定時(shí)器時(shí)鐘12T模式
TMOD &= 0xF0; //設(shè)置定時(shí)器模式
TMOD |= 0x01; //設(shè)置定時(shí)器模式
TL0 = 0x18; //設(shè)置定時(shí)初值
TH0 = 0xFC; //設(shè)置定時(shí)初值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開(kāi)始計(jì)時(shí)
EA=1;
ET0=0;
}
復(fù)制代碼
作者:
609763691
時(shí)間:
2019-5-9 11:29
這個(gè)很簡(jiǎn)單吧,你這個(gè)是增加計(jì)數(shù)的程序,++就改為--,判斷最大改為<0,就行了,
作者:
xdh568470911
時(shí)間:
2019-5-9 14:45
你已經(jīng)寫了 cnt > 1000 也就是 1s b++ 。向上計(jì)數(shù),
你需要倒計(jì)時(shí),一開(kāi)始的時(shí)候,賦值 b = 60, 然后 b--就好了。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1