智能手機充電器設計 程序代碼如下: #include <reg51.h> unsigned int T3HOUS=3600; unsigned int T1NUM=0; unsigned int INTONUM=0; sbit SPEAK=P0^1; sbit EN/OK=P0^2; void main(void) { system_init(); /*調用系統初始化函數*/ EA=1;EX0=1; /*使能INT0中斷*/ while(1) { EN/OK=1; } /*使能MAX1898*/ } void int0_interrupt(void) { if(INTONUM==0) {TR1=1; SPEAK=0;}/*使能定時器1*/ INTONUM++; } void t1_interrupt(void) { T1NUM++; T3HOUS--; if((T3HOUS!=0)&&( INTONUM ==1)) { if(T1NUM==6000) /*3s*/ { T1NUM=0; SPEAK=0; } } else { EN/OK=0; /*禁止MAX1898*/ T3HOUS =0; SPEAK=1; } void system_init(void) { SPEAK=1; /*禁止蜂鳴器*/ EN/OK=0; /*禁止MAX1898*/ TMOD=0X20; /*設置定時器1*/ TCON|=0X01; TH1=0;TL1=0; }
|