| /******************************************************/
 uchar ad(uchar com)
 {
 ADCON = 0x00;
 if(com == bat_com)
 {ADCON = 0x00;}           //选通道
 if(com == co_com)
 {ADCON = 0x02;}
 ADCON |= 0x80;           //使能AD
 delay_ms(1);
 ADCON |= 0x01;    //开始转换
 while(ADCON&0x01)        //等待
 {;}
 return(ADDH);
 }
 void main(void)
 {
 initail();
 ad_initail(); //初始化
 if(first_power_on == 0xaa)
 goto wdt_reset;                                //WDT reset
 if(!key)
 {
 delay_ms(10);
 if(!key)
 {
 clr_ee();
 }
 }
 correct();
 alarm = 1;
 g_led = 1;
 delay_ms(20);
 alarm = 0;
 g_led = 0;
 read_data();
 work_status = monitor_status;
 wdt_reset:
 first_power_on = 0xaa;
 while(1)
 {
 switch(work_status)
 {
 case  monitor_status:
 monitor();
 power_dwon();
 break;
 case  alarm_status:
 alarming();
 power_dwon();
 break;
 default:                        work_status = monitor_status;
 break;
 }
 }
 }
 void initail(void)
 {
 //                 SP = 0x00;
 //                 PSW = 0x00;           //程序状态寄存器
 // C AC F0 RS1 RS0 OV F1 P
 
 CLKCON = 0x60;           //内部RC震荡 16M           12分频
 //32k_spdup clks1 clks0 scmif rcon rs --
 TCON = 0x01;         //外部中断INT0允许
 //
 TMOD = 0x00;                  //关闭定时器
 //
 TCON1 = 0x00;                  //
 //
 IEN0 = 0x81;                //
 //
 IEN1 = 0x00;                //
 //
 EXF0 = 0x00;                //
 //
 RSTSTAT = 0x00;        //
 // WDOF - PORF LVRF CLRF WDT2 WDT1 WDT0
 PWMCON = 0x00;                 //PWM禁止
 P1M0 = 0x03;                //0x03
 P1M1 = 0xfc;                //AN0 AN1模拟输入 P1.0 P1.1           0xfc
 P3M0 = 0x04;                //0x04
 P3M1 = 0xfb;        //P3.2输入 Z中断使能                 0xfb
 P4M0 = 0x00;                //0x00
 P4M1 = 0xff;                //0xff
 P4M1 = 0x00;
 P1 = 0x00;
 P3 = 0x00;
 P4 = 0x00;
 }
 |