本程式來自《微控制器C語言程式設計實訓100例——基於8051+Proteus模擬》沒用中斷。
#include
#define uchar unsigned char
#define uint unsigned int
void main()
{
uchar T_Count = 0;
P0 = 0xfe;
P2 = 0xfe;
TMOD = 0x10;//定時器1方式1
TH1 = (65535-50000)/256;//定時50000us=50ms
TL1 = (65535-50000)%256;
TR1 = 1;//啟動定時器1
while(1)
if(TF1== 1)//查詢方式定時時間到後TF1=1
TF1 = 0;
TH1 = (65535-50000)/256;
if(++T_Count == 20)//50ms*20=1000ms
P0 = _crol_(P0,1);
P2 = _crol_(P2,1);
T_Count = 0;
}
本程式來自《微控制器C語言程式設計實訓100例——基於8051+Proteus模擬》沒用中斷。
#include
#include
#define uchar unsigned char
#define uint unsigned int
void main()
{
uchar T_Count = 0;
P0 = 0xfe;
P2 = 0xfe;
TMOD = 0x10;//定時器1方式1
TH1 = (65535-50000)/256;//定時50000us=50ms
TL1 = (65535-50000)%256;
TR1 = 1;//啟動定時器1
while(1)
{
if(TF1== 1)//查詢方式定時時間到後TF1=1
{
TF1 = 0;
TH1 = (65535-50000)/256;
TL1 = (65535-50000)%256;
if(++T_Count == 20)//50ms*20=1000ms
{
P0 = _crol_(P0,1);
P2 = _crol_(P2,1);
T_Count = 0;
}
}
}
}