智能手机充电器设计 程序代码如下: #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; }
|