这是洗衣机,有没有大神按着这个思路,编程,我的问题是定时器中断想让它每一秒,时间减少1秒,10秒内电机正传8秒,停2秒,然后下10秒内,反转8秒,停2秒,自己试了好多次,总是实现不了,求帮助
时间:10-02
整理:3721RD
点击:
TMOD=0x11; //′ò?a?¨ê±?÷ TH0=(65536-50000)/256; TL0=(65536-50000)%256; ET0=1; ET1=1; EA=1; TH1=(65536-1000)/256; TL1=(65536-1000)%256; if(flag_start == 1) { if(flag_gongzuo == 0) //1???[表情] { TR0=0; TR1=0; jinshui = 0; led_y = 0;led_g = 1;led_r = 1; if(shuiwei >= set_shuiwei) { jinshui = 1 ; //í£?1???[表情] flag_gongzuo = 2; } } if(flag_gongzuo == 2) //?′μó { TR1=1; TR0=1; if(miao <= 0) { fen --; miao = 10; } if(value1==20) value1=0; miao--; if(fen < xitiao+2)//8.9 16.9 26.9 { TR1=0; TR0=0; flag_gongzuo = 3; } } if(flag_gongzuo == 3) //1???[表情] { chushui = 0; //3??[表情] if(shuiwei == 0) { TR1 = 1; flag_z_f = 0; num = 10; flag_gongzuo = 4; } } if(flag_gongzuo == 4) //1í??[表情] { led_y = 1;led_g = 1;led_r = 0; //×′ì???ê?μ? chushui = 0; //3??[表情] if(miao <= 0) { fen --; miao = 10; } delay_1ms(1000); miao -- ; if(fen < xitiao)// 6.9 14.9 24.9 { chushui=1; TR1=0; TR0=0; flag_gongzuo =5; } } if(flag_gongzuo == 5) //2???[表情] { jinshui = 0; //???[表情] if(shuiwei >= set_shuiwei) { jinshui = 1 ; //í£?1???[表情] flag_gongzuo = 6; } } if(flag_gongzuo == 6) //1?ˉ?′ { led_y = 1;led_g = 0;led_r = 1; //×′ì???ê?μ? if(miao <= 0) { fen --; miao = 10; } delay_1ms(1000); miao -- ; if(fen <=piaoxi+1 )// 1.9 8.9 11.9 { TR0 = 0; TR1 = 0; flag_gongzuo = 7; } } if(flag_gongzuo == 7) //2???[表情] { chushui = 0; //3??[表情] if(shuiwei == 0) { flag_gongzuo = 8; } } if(flag_gongzuo == 8) //2í??[表情] { led_y = 1;led_g = 1;led_r = 0; //×′ì???ê?μ? chushui = 0; //3??[表情] flag_z_f = 0; TR1=1; num=10; if(miao <= 0) { fen --; miao = 10; } delay_1ms(1000); miao -- ; if(fen < piaoxi)// 0 6.9 9.9 { TR1 = 0; TR0=0; flag_gongzuo = 9; chushui = 1; //í£?13??[表情] } } if(flag_gongzuo == 9) //3???[表情] { led_y = 1;led_g = 0;led_r = 1; //×′ì???ê?μ? jinshui = 0; //???[表情] if(shuiwei >= set_shuiwei) { jinshui = 1 ; //í£?1???[表情] flag_gongzuo = 10; } } if(flag_gongzuo == 10) //2?ˉ?′ { led_y = 1;led_g = 0;led_r = 1; //×′ì???ê?μ? if(miao <= 0) { fen --; miao = 10; } delay_1ms(1000); miao--; if(fen <=piaoxi1+1)//1.9 1.9 { TR0 = 0; TR1 = 0; flag_gongzuo = 11; } } if(flag_gongzuo == 11) //3???[表情] { chushui = 0; //3??[表情] if(shuiwei == 0) { flag_gongzuo = 12; } } if(flag_gongzuo == 12) //3í??[表情] { led_y = 1;led_g = 1;led_r = 0; //×′ì???ê?μ? chushui = 0; //3??[表情] flag_z_f = 0; num = 10; TR1 = 1; TR0=1; if(miao <= 0) { fen --; miao = 10; } delay_1ms(1000); miao -- ; if(fen <piaoxi1)// 0 0 { flag_gongzuo = 13; chushui =1; led_r = 1; PWM1=1; PWM2=1; EA=0; fen=0; miao=0; display(); beep_dis(); } } if(value <= 160) //?y×a { flag_z_f = 0; } else if(value <= 200) //í£?? { PWM1=1; PWM2=1; } else if(value <= 360) //·′×a { flag_z_f = 1; } else if(value<= 400) //í£?? { PWM1=1; PWM2=1; }else value = 0;
这代码没法看,主体思路,定时器只负责1秒定时,到1秒产生一个标志,电机动作处理程序里,流程为计时清零,并开始计时,启动电机正转,到8秒,电机停转,继续计时,到10秒,电机反转,到18秒,电机停止,到20秒,计时清零,如果继续如此循环的话,电机动作处理程序从头再来,如果结束的话,退出就行了