基于STC89c52RC单片机的智能风扇设计

光电信息协会电子设计竞赛 钟培文小组

irtime++; //外部中断 EA=1;

IT0 = 1; //指定外部中断0下降沿触发,INT0 (P3.2) EX0 = 1; ET0=1; ET1=1;

TR0=1; TR1=1; }

/*-----------------------------------------------外部中断0初始化------------------------------------------------*/

void Timer1(void) interrupt 3 using 1 {

static uchar count; TH1=(65536-256)/256; TL1=(65536-256)%6; irtime++; time3++; if(time3==255 { time3=0; }

if(beep_on==1)

{ spk=!spk; }

if(beep_time==1) {

beep_on=0; }

//定时器1pwm

25

光电信息协会电子设计竞赛 钟培文小组

if(p) {

if (count==PWM_ON) {

PWM = 0; } count++;

if(count == CYCLE) {

count=0;

if(PWM_ON!=0)

PWM = 1;

} } }

//定时器0

void Timer0(void) interrupt 1 {

TH0=(65536-50000)/256; TL0=(65536-50000)%6; num++; if(num==1) {

beep_time=1; }

if(num==20) { num=0; time1++; if(time2)

26

光电信息协会电子设计竞赛 钟培文小组

time2--; } }

/*... ..........按键扫描.............. ..................................... */

unsigned char KeyScan(void) {

unsigned char keyvalue; if(KeyPort!=0xff) {

Delayms(3); if(KeyPort!=0xff) {

keyvalue=KeyPort;

while(KeyPort!=0xff); switch(keyvalue)

{

case 0xfe:return 1;break; case 0xfd:return 2;break; case 0xfb:return 3;break; case 0xf7:return 4;break; case 0xef:return 5;break; case 0xdf:return 6;break; case 0xbf:return 7;break; case 0x7f:return 8;break; default:return 0;break; }

} } return 0; }

/*..........................................

27

光电信息协会电子设计竞赛 钟培文小组

.............................................*/

void Timing(void) {

switch(timing_flag) {

定时功能 定时器2

case 1: tim=10; if(timing_on==0)write_string(11,1,\case 2: tim=1800; if(timing_on==0)write_string(11,1,\case 3: tim=3600; if(timing_on==0)write_string(11,1,\case 4: tim=7200;if(timing_on==0)write_string(11,1,\case 5: tim=10800;if(timing_on==0)write_string(11,1,\case 6: tim=0;timing_flag=0; write_string(11,1,\ \}

if(timing_on==0) {

timing_r=1; time2=0; }

if(timing_run && timing_r && timing_on) { time2=tim; timing_r=0; timing_flag=0; } }

void write_com(uchar com) {

Delayms(5);

//30min //60min

//120min //180min

//定时取消

/*.........................................1602部分.............................................*/

28

联系客服:779662525#qq.com(#替换为@)