|
程序代碼
#include"stc8g.h"
#define uchar unsigned char
#define uint unsigned int
sbit LED = P5^4; //定義IO管腳
int counter; //計(jì)數(shù)變量
void InitTimer0() //中斷函數(shù)
{
TMOD = 0x01;
TH0=(65536-60000)/256; //50ms
TL0=(65536-60000)%256;
EA = 1; //允許CPU中斷
ET0 = 1; //定時(shí)器0中斷打開
TR0 = 1; //啟動(dòng)定時(shí)器
}
/*--------------------------主函數(shù)------------------------------*/
void main()
{
P3M0 = 0x00; //設(shè)置P3.0~P3.7為雙向口模式
P3M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
InitTimer0(); //初始化定時(shí)器
LED = 0; //IO初始化為低電平
while(1);
}
void Timer0() interrupt 1 //啟用中斷組1
{
TH0=(65536-60000)/256; //裝初值
TL0=(65536-60000)%256;
counter++; //產(chǎn)生200MS的脈沖 等待ECU檢測(cè)
if(counter >= 1000) { LED = 1;} //延時(shí)30S
else if(counter >= 1950) { LED = 0; counter = 0; TR0 = 0; }
}
|
|