#include"at89x52.h"
#define uchar unsigned char
#define uint unsigned int
sbit m=P1^0;
void main()
{
TMOD=0X10; // T1為定時(shí),方式1(不能自動(dòng)重裝載)
TR1=1; //開定時(shí)T1
m=1; //初值為高電平,可以不寫
while(1) //死循環(huán)
{ TH1=(-5000)>>8; //16位定時(shí)器設(shè)置初值5ms
TL1=-5000;
while(TF1==0); //定時(shí)沒有到,TF1==0則等待
{ TF1=0; //定時(shí)到,TF1==1清零
m=0; //輸出低電平
TH1=(-12000)>>8; //T1設(shè)置初值12ms
TL1=-12000;
while(TF1==0); //定時(shí)沒有到,則等待
{TF1=0;m=1;} //清零,同時(shí)輸出高電平
}
}
}
另外您還可以參考這兩篇文章,關(guān)于定時(shí)器和計(jì)數(shù)器的
http://www.torrancerestoration.com/mcuteach/236.html
http://www.torrancerestoration.com/mcuteach/233.html
謝謝
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |