标题:
倒计时99s(original)程序
[打印本页]
作者:
liuda
时间:
2015-1-22 01:59
标题:
倒计时99s(original)程序
//这一次脱离教程,看看自己还行不行
//编完这个程序就可以继续往下进行了
//依然是倒计时99s
//这一次我想利用重装载定时器
//让他自己赋值
#include<reg52.h>
#define duan P0
//void Timer1init();
void Timer0Cofig(void) ;
sbit shi=P1^1;
sbit ge=P1^0;
unsigned char code dig[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int j,k;
char Time,Second;
//int num;
unsigned char ch[2];
void main()
{
//Timer1init();//最关键的函数没有初始化
Timer0Cofig();
//i=0;
Second=19;
while(1)
{
if(Second<0)
{
Second=19;
}
if(Second>=0)
{
ch[0]=dig[Second%10]; //个位
ch[1]=dig[Second/10];
// 十位
for(j=0;j<2;j++)
{
if(j==0)
{
shi=1;
ge=0;
}
if(j==1)
{
shi=0;
ge=1;
}
duan=ch[j];
k=10;
while(k--);
duan=0x00;//消隐
}
}
}
}
/*void Timer1init()
{
TMOD=0X20;//定时器1工作方式为2
TH1=0x06;
//初始值我想设置为250微秒
TL1=0x06;
//注意到hl的值是一样的,因为装载的内容一样
EA=1;
//打开总中断
ET1=1; //打开定时器1中断
TR1=1;//定时器1运行
}
//中断的编写参考help
void Timer1() interrupt 1
{
i++;
if(i==4000)
{
num--;
i=0;
}
} */
void Timer0Cofig(void)
{
TMOD = 0x01; //定时器0选择工作方式1
TH0 = 0x3C;
//设置初始值,定时50MS
TL0 = 0xB0;
EA = 1;
//打开总中断
ET0 = 1;
//打开定时器0中断
TR0 = 1;
//启动定时器0
}
void Timer0() interrupt 1
{
TH0 = 0x3C;
//设置初始值
TL0 = 0xB0;
Time++;
if(Time == 20)
{
Second --;
Time = 0;
}
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1