芯片启动初始化过程
chip_init();
主循环开始
while(1)
{
P2 = 0x00;
以下定时取反P2口输出状态
for(loop=0;loop50;loop++);
P2 = 0xff;
for(loop=0;loop50;loop++);
}
}
启动时IO初始化子过程
void chip_init()
{
BTCON = 0xa3; Watch-dog disable
CLKCON = 0x18; selet non-divided CPU clock
P0PND = 0x0; P0INT disable
P0CONH = 0xdf; P0.7 is as AD convert port
P0.6 is PWM output
P0.5 is as AD convert port
P0.4 is as AD convert port
P0CONL = 0xfa; P0.3 is as AD convert port
P0.2 is as AD convert port
P0.0,P0.1 is as push-pull output port
P0 = 0x0;
P1CON = 0xa; P1.0 is as push-pull output port
P1.1 is as push-pull output port
P1 = 0x0;
P2CONH = 0x2a; P2.0-P2.5 is as push-pull output
P2CONL = 0xaa; P2.6 is as AD input
P2 = 0x1e;