|
.C語言程序設計結果:#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int uchar tc0=0,tc1=0;
//主程序 void main() { P0=0xfe; P2=0xfe; TMOD=0x11; //定時器 0、定時 器 1 均工作于方式 1 TH0=(65536-15000)/256; //定時器 0:15ms TL0=(65536-15000)%256; TH1=(65536-50000)/256; //定時器 1:50ms TL1=(65536-50000)%256; IE=0x8a; TR0=1; //啟動定時器 TR1=1; while(1); } //T0 中斷函數 void Time0() interrupt 1 { TH0=(65536-15000)/256; //恢復定時器 0 初值 TL0=(65536-15000)%256; if(++tc0==10) //150ms 轉換狀態 { tc0=0; P0=_crol_(P0,1); } } //T1 中斷函數 void Time1() interrupt 3 { TH0=(65536-50000)/256; //恢復定時器 1 初值 TL0=(65536-50000)%256; if(++tc1==10) //500ms 轉換狀態{ tc1=0; P2=_crol_(P2,1); } }
|
|