|
//這一次脫離教程,看看自己還行不行
//編完這個(gè)程序就可以繼續(xù)往下進(jìn)行了
//依然是倒計(jì)時(shí)99s
//這一次我想利用重裝載定時(shí)器
//讓他自己賦值
#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();//最關(guān)鍵的函數(shù)沒(méi)有初始化
Timer0Cofig();
//i=0;
Second=19;
while(1)
{
if(Second<0)
{
Second=19;
}
if(Second>=0)
{
ch[0]=dig[Second%10]; //個(gè)位
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;//定時(shí)器1工作方式為2
TH1=0x06; //初始值我想設(shè)置為250微秒
TL1=0x06; //注意到hl的值是一樣的,因?yàn)檠b載的內(nèi)容一樣
EA=1; //打開(kāi)總中斷
ET1=1; //打開(kāi)定時(shí)器1中斷
TR1=1;//定時(shí)器1運(yùn)行
}
//中斷的編寫(xiě)參考help
void Timer1() interrupt 1
{
i++;
if(i==4000)
{
num--;
i=0;
}
} */
void Timer0Cofig(void)
{
TMOD = 0x01; //定時(shí)器0選擇工作方式1
TH0 = 0x3C; //設(shè)置初始值,定時(shí)50MS
TL0 = 0xB0;
EA = 1; //打開(kāi)總中斷
ET0 = 1; //打開(kāi)定時(shí)器0中斷
TR0 = 1; //啟動(dòng)定時(shí)器0
}
void Timer0() interrupt 1
{
TH0 = 0x3C; //設(shè)置初始值
TL0 = 0xB0;
Time++;
if(Time == 20)
{
Second --;
Time = 0;
}
}
|
|