#include<reg52.h> //52單片機頭文件
#include <intrins.h> //包含有左右循環移位子函數的庫
#define uint unsignedint //宏定義
#define uchar unsignedchar //宏定義
sbit P1_0=P1^0;
uchar tt,a;
void main() //主函數
{
TMOD=0x01;//設置定時器0為工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;//開總中斷
ET0=1;//開定時器0中斷
TR0=1;//啟動定時器0
a=0xfe;
while(1);//等待中斷產生
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==2)
{
tt=0;
P1=a;
a=_crol_(a,1);
}
}
|