#include "C8051F020.h"
sbit P10 = P1^0;
sbit P11 = P1^1;
void SYS_Init (void);
void Timer2_Delay (void);
void SYS_Init (void)
{
int i = 0;
WDTCN = 0xDE;
WDTCN = 0xAD; //关狗
CKCON = 0x20; //定时器2时钟源为系统时钟
P1MDOUT = 0x03;
XBR2 = 0x40; //P1.0P1.1推挽。其他不动
OSCXCN = 0x65;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x08; //启动外部晶振,内部晶振关闭
}
void Timer2_Delay (void)interrupt 4 using 1
{
if(P11==0) //P1.0在P1.1为低时再翻转,整好1000us
P10=~P10;
P11=~P11; //P1.1每500us翻转一次,
}
void main (void)
{
Init_Device();
RCAP2H= (65536-1000)/256; // 设置定时器T2 500us溢出 重装
RCAP2L= (65536-1000)%256;
TH2 = (65536-1000)/256;
TL2 = (65536-1000)%256;
TR2=1;
while(1);
}