找回密码
 注册

QQ登录

只需一步,快速开始

搜索

滚筒洗衣机ICC源代码与详细电路图 (ATmega16芯片)

[复制链接]
山海致远 发表于 2013-7-17 02:25:27 | 显示全部楼层 |阅读模式
电路图为JPG图形格式,高清晰。
线路图第1页(总共3页).jpg
线路图第2页.jpg
线路图第3页.jpg
  1. #include <iom16v.h>
  2. #include <macros.h>
  3. #include <eeprom.h>

  4. //PA
  5. //NTC IN
  6. #define clk       0x02
  7. //NC
  8. #define com7      0x08
  9. #define com1      0x10
  10. #define com6      0x20
  11. #define com2      0x40
  12. #define com3      0x80  

  13. #define clk_h       SETBIT(PORTA,clk)
  14. #define clk_l       CLRBIT(PORTA,clk)

  15. #define com7_h      SETBIT(PORTA,com7)
  16. #define com7_l      CLRBIT(PORTA,com7)
  17. #define com6_h      SETBIT(PORTA,com6)
  18. #define com6_l      CLRBIT(PORTA,com6)
  19. #define com1_h      SETBIT(PORTA,com1)
  20. #define com1_l      CLRBIT(PORTA,com1)
  21. #define com2_h      SETBIT(PORTA,com2)
  22. #define com2_l      CLRBIT(PORTA,com2)
  23. #define com3_h      SETBIT(PORTA,com3)
  24. #define com3_l      CLRBIT(PORTA,com3)
  25. //PB
  26. #define data      0x01
  27. #define direct    0x02
  28. #define wash_spin      0x04
  29. #define heat      0x08
  30. //DOOR IN
  31. #define door_in   0x10
  32. //WATER2
  33. #define water2    0x20
  34. //WATER1
  35. #define water1    0x40
  36. #define bumpa    0x80

  37. #define data_h        SETBIT(PORTB,data)
  38. #define data_l        CLRBIT(PORTB,data)
  39. #define direct_on     SETBIT(PORTB,direct)
  40. #define direct_off    CLRBIT(PORTB,direct)
  41. #define wash_on       CLRBIT(PORTB,wash_spin)
  42. #define spin_on       SETBIT(PORTB,wash_spin)
  43. #define heat_on       SETBIT(PORTB,heat)
  44. #define heat_off      CLRBIT(PORTB,heat)
  45. #define bumpa_on      SETBIT(PORTB,bumpa)
  46. #define bumpa_off     CLRBIT(PORTB,bumpa)

  47. //PD
  48. #define bumpb    0x01
  49. #define bumpc    0x02
  50. //ZERO IN
  51. #define zero_in       0x04
  52. //SPEED IN
  53. #define speed_in      0x08
  54. #define bumph         0x10
  55. #define drain         0x20
  56. #define door          0x40
  57. #define motor         0x80

  58. #define bumpb_on     SETBIT(PORTD,bumpb)
  59. #define bumpb_off    CLRBIT(PORTD,bumpb)
  60. #define bumpc_on     SETBIT(PORTD,bumpc)
  61. #define bumpc_off    CLRBIT(PORTD,bumpc)
  62. #define bumph_on     SETBIT(PORTD,bumph)
  63. #define bumph_off    CLRBIT(PORTD,bumph)
  64. #define drain_on      SETBIT(PORTD,drain)
  65. #define drain_off     CLRBIT(PORTD,drain)
  66. #define door_on       SETBIT(PORTD,door)
  67. #define door_off      CLRBIT(PORTD,door)
  68. #define motor_on      SETBIT(PORTD,motor)
  69. #define motor_off     CLRBIT(PORTD,motor)

  70. //PC
  71. #define buz          0x01
  72. #define key_in       0x02
  73. //S1/SPEED SET
  74. #define speed_set    0x04
  75. //S2/MODE SET
  76. #define mode_set     0x08
  77. //S4
  78. //S3
  79. #define com4        0x80
  80. #define com5        0x40

  81. #define buz_on      SETBIT(PORTC,buz)
  82. #define buz_off     CLRBIT(PORTC,buz)        
  83. #define com4_h      SETBIT(PORTC,com4)
  84. #define com4_l      CLRBIT(PORTC,com4)
  85. #define com5_h      SETBIT(PORTC,com5)
  86. #define com5_l      CLRBIT(PORTC,com5)



  87. #define k_power               1
  88. #define k_start               2
  89. #define k_cycle               3
  90. #define k_fab               4
  91. #define k_temp               5
  92. #define k_extrinse     6
  93. #define k_delay               7


  94. unsigned int  temp_ad;
  95. unsigned int  value,ad;
  96. unsigned char ad_count;
  97. unsigned char water_temp;
  98. unsigned char fact_water_temp;
  99. unsigned char water_temp1;
  100. unsigned char water_temp2;

  101. unsigned char t_1ms;
  102. unsigned char t_3ms;
  103. unsigned char t_10ms;
  104. unsigned char t_50ms;
  105. unsigned char t_100ms;
  106. unsigned int t_500ms;
  107. unsigned int t_1s;
  108. unsigned int t_1m;

  109. unsigned char t_1m_count;
  110. unsigned int time_t_1h_count;
  111. unsigned char time_data;

  112. unsigned char scan_count;

  113. unsigned char buz_count;
  114. unsigned char end_buz_count;
  115. unsigned char test_buz_count;

  116. unsigned char k_power_count;//key_count
  117. unsigned char k_start_count;
  118. unsigned char k_cycle_count;
  119. unsigned char k_fab_count;
  120. unsigned char k_temp_count;
  121. unsigned char k_extrinse_count;
  122. unsigned char k_delay_count;
  123. unsigned char set_count;

  124. unsigned char key_num;

  125. unsigned int addr;
  126. unsigned int addr1;

  127. unsigned int  enter_water_count;  //err_count
  128. unsigned char drain_count;
  129. unsigned char overflow_count;
  130. unsigned char door_lock_count;
  131. unsigned int rise_temp_count;
  132. unsigned char motor_count;

  133. unsigned char door_on_count;
  134. unsigned char door_off_count;
  135. unsigned char water1_on_count;
  136. unsigned char water1_off_count;
  137. unsigned char water2_on_count;
  138. unsigned char water2_off_count;

  139. unsigned char test_count;
  140. unsigned char test_time_count;
  141. unsigned char test_disp_count;
  142. unsigned char temp_disp_count;

  143. unsigned char delay_flash_count;
  144. unsigned char time_flash_count;

  145. unsigned char spin_count;     //脱水计数
  146. unsigned int low_spin_count;

  147. unsigned char main_wash_time;

  148. unsigned int speed_count;

  149. unsigned char wash_time_count;
  150. unsigned char wash_t;

  151. unsigned char flag_prewash;//过程标志
  152. unsigned char flag_wash;
  153. unsigned char flag_rinse;
  154. unsigned char flag_extrinse;
  155. unsigned char flag_spin;
  156. unsigned char flag_time;

  157. unsigned char disp0,disp1,disp2,dig1,dig2,dig3,dig4;//dig为数字

  158. unsigned int s1;//实际测得转速
  159. unsigned int s2;//设定转速

  160. unsigned char t2_count;
  161. unsigned char t1_count;
  162. unsigned int t;//定时器timer1定时常数
  163. unsigned int t1;//可控硅延时开通起始时间,调速宽度t1/100us单位
  164. //可控硅固定开通时间//单位100us待定
  165. #define t2 9000  
  166. #define t0 1000   
  167. //时间步长250us   
  168. #define t_step 20  

  169. //初始速度100us #define t 0xFFFF-t1-100

  170. #define led_h_h_on      SETBIT(disp1,0x40)
  171. #define led_h_h_off     CLRBIT(disp1,0x40)
  172. //#define led_h_h_flash   disp1^=0x40

  173. #define led_h_c_on      SETBIT(disp0,0x10)
  174. #define led_h_c_off     CLRBIT(disp0,0x10)
  175. //#define led_h_c_flash   disp0^=0x10

  176. #define led_w_w_on      SETBIT(disp0,0x04)
  177. #define led_w_w_off     CLRBIT(disp0,0x04)
  178. //#define led_w_w_flash   disp0^=0x04

  179. #define led_c_c_on      SETBIT(disp0,0x02)
  180. #define led_c_c_off     CLRBIT(disp0,0x02)
  181. //#define led_c_c_flash   disp0^=0x02

  182. #define led_mianma_on      SETBIT(disp1,0x10)
  183. #define led_mianma_off     CLRBIT(disp1,0x10)
  184. //#define led_mianma_flash   disp1^=0x10

  185. #define led_huaxian_on      SETBIT(disp1,0x08)
  186. #define led_huaxian_off     CLRBIT(disp1,0x08)
  187. //#define led_huaxian_flash   disp1^=0x08

  188. #define led_sinong_on      SETBIT(disp1,0x01)
  189. #define led_sinong_off     CLRBIT(disp1,0x01)
  190. //#define led_sinong_flash   disp1^=0x01

  191. #define led_maoliao_on        SETBIT(disp0,0x80)
  192. #define led_maoliao_off       CLRBIT(disp0,0x80)
  193. //#define led_maoliao_flash     disp0^=0x80

  194. #define led_prewash_on        SETBIT(disp1,0x20)
  195. #define led_prewash_off       CLRBIT(disp1,0x20)
  196. #define led_prewash_flash     disp1^=0x20

  197. #define led_wash_on        SETBIT(disp0,0x08)
  198. #define led_wash_off       CLRBIT(disp0,0x08)
  199. #define led_wash_flash     disp0^=0x08

  200. #define led_rinse_on        SETBIT(disp1,0x04)
  201. #define led_rinse_off       CLRBIT(disp1,0x04)
  202. #define led_rinse_flash     disp1^=0x04

  203. #define led_spin_on        SETBIT(disp0,0x01)
  204. #define led_spin_off       CLRBIT(disp0,0x01)
  205. #define led_spin_flash     disp0^=0x01

  206. #define led_extrinse_on        SETBIT(disp1,0x02)
  207. #define led_extrinse_off       CLRBIT(disp1,0x02)
  208. #define led_extrinse_flash     disp1^=0x02

  209. #define led_delay_on        SETBIT(disp0,0x20)
  210. #define led_delay_off       CLRBIT(disp0,0x20)
  211. #define led_delay_flash     disp0^=0x20

  212. #define led_door_on        SETBIT(disp0,0x40)
  213. #define led_door_off       CLRBIT(disp0,0x40)
  214. #define led_door_flash     disp0^=0x40

  215. #define colon_on            SETBIT(disp2,0x50)
  216. #define colon_off           CLRBIT(disp2,0x50)
  217. #define colon_flash         disp2^=0x50

  218. #define c_on            SETBIT(disp2,0x08)
  219. #define c_off           CLRBIT(disp2,0x08)
  220. //#define c_flash         disp2^=0x08

  221. //74LS164QG-QA QH=0数码管共阳
  222. const unsigned char data_7seg[]={0x5F,0x48,0x73,0x79,0x6C,0x3D,0x3F,0x58,0x7F,0x7D,0x37,0x22,0x17,0x08,0x00};
  223.                               // 0,1,2,3,4,5,6,7,8,9,E,R,c,度,无显示,  

  224. //-----------------------------------------------------------------------------
  225. // A/D table  -10~110度
  226. //-----------------------------------------------------------------------------
  227. //#pragma data:data
  228. const unsigned int adtable[]=
  229. {
  230. //0x3F1,0x3BD,0x3BA,0x3B7,0x3B0,0x3A8,0x3A2,0x39F,0x39D,0x398,
  231. 0x393,0x38F,0x387,0x385,0x382,0x380,0x378,0x371,0x366,0x360,
  232. 0x35E,0x355,0x34D,0x340,0x33E,0x338,0x330,0x327,0x31F,0x31C,
  233. 0x30F,0x307,0x305,0x303,0x300,0x2E6,0x2E0,0x2D5,0x2C7,0x2C0,
  234. 0x2BF,0x2B1,0x2A2,0x29B,0x290,0x27F,0x27B,0x278,0x267,0x260,
  235. 0x258,0x24C,0x23F,0x238,0x22F,0x21F,0x218,0x20E,0x203,0x1FC,
  236. 0x1F0,0x1E7,0x1E0,0x1D8,0x1C7,0x1C0,0x1BD,0x1B0,0x1A3,0x19E,
  237. 0x18F,0x187,0x182,0x180,0x170,0x167,0x160,0x158,0x14F,0x144,
  238. 0x13F,0x138,0x130,0x127,0x11F,0x11C,0x110,0x106,0x103,0xFF,
  239. 0xFC,0xF8,0xF0,0xE7,0xE3,0xE0,0xD8,0xCF,0xC9,0xC6,                                         
  240. 0xC3,0xC0,0xB8,0xB5,0xB0,0xA7,0xA5,0xA2,0x9F,0x9C,
  241. 0x98,0x94,0x8F,0x8D,0x8A,0x7F,0x7C,0x7A,0x78,0x75,
  242. };

  243. void buzing(void)//一次130-150ms
  244. {
  245. if( f3.bit.buzed==1)//按键
  246. {
  247.   buz_count++;
  248.   buz_on;
  249.   if(buz_count>=3)
  250.   {
  251.   buz_count=0;
  252.   buz_off;
  253.   f3.bit.buzed=0;
  254.   }
  255. }
  256. }

  257. void end_buzing(void)
  258. {
  259.   end_buz_count++;
  260.   PORTC^=buz;
  261.   if(end_buz_count>=12)
  262.   {
  263.    end_buz_count=0;
  264.    buz_off;
  265.    f2.bit.end_buz=1;
  266.   }
  267. }

  268. void test_buzing(void)
  269. {
  270. if(f3.bit.test_buz==1)
  271. {
  272.   buz_off;
  273.   PORTC^=buz;
  274.   test_buz_count++;
  275.   if(test_buz_count>=3)
  276.   {
  277.    buz_off;
  278.    test_buz_count=0;
  279.    f3.bit.test_buz=0;
  280.   }
  281. }
  282. }

  283. void err_buzing(void)
  284. {
  285. if((f10.byte!=0)||(f11.bit.motor_erred==1))
  286.   PORTC^=buz;
  287. }


  288. void disp_test(void)
  289. {
  290.    if(test_count==0) {dig1=dig2=dig3=dig4=0;colon_flash;}
  291.    if(test_count==2) {dig1=dig2=dig3=dig4=1;colon_flash;}
  292.    if(test_count==4) {dig1=dig2=dig3=dig4=2;colon_flash;}
  293.    if(test_count==6) {dig1=dig2=dig3=dig4=3;colon_flash;}
  294.    if(test_count==8) {dig1=dig2=dig3=dig4=4;colon_flash;}
  295.    if(test_count==10) {dig1=dig2=dig3=dig4=5;colon_flash;}
  296. }

  297. void disp_delay_time(void)
  298. {
  299.    c_off;
  300.    dig1=time_data/10;
  301.    dig2=time_data%10;
  302.    dig3=dig4=0x00;
  303.    if(f2.bit.started==1) colon_flash;
  304.    else colon_on;
  305. }

  306. void disp_time(void)
  307. {
  308.     c_off;
  309.         if(f2.bit.started==1) colon_flash;
  310.         else colon_on;
  311.     dig1=0;
  312.         dig2=main_wash_time/60;
  313.         dig3=(main_wash_time-dig2*60)/10;
  314.         dig4=main_wash_time-dig2*60-dig3*10;
  315. }

  316. void disp_temp(void)
  317. {
  318.     colon_off;
  319.         c_on;
  320.         dig1=0;
  321.         dig2=water_temp/10;
  322.         dig3=water_temp%10;
  323.         dig4=12;//data_7seg[12];C
  324. }

  325. void disp_time_temp(void)
  326. {
  327. if(f8.bit.time_disp==0)
  328.    {
  329.      disp_time();
  330.          temp_disp_count++;
  331.          if(temp_disp_count>8)
  332.           {
  333.            temp_disp_count=0;
  334.            f8.bit.temp_disp=1;
  335.            f8.bit.time_disp=1;
  336.            }
  337.     }
  338.    else
  339.     {
  340.          if(f8.bit.temp_disp==1)
  341.          {
  342.           disp_temp();
  343.       temp_disp_count++;
  344.           if(temp_disp_count>8)
  345.           {
  346.            temp_disp_count=0;
  347.            f8.bit.temp_disp=0;
  348.            f8.bit.time_disp=0;
  349.           }
  350.           }
  351.      }
  352. }

  353. void disp_err(void)
  354. {
  355.   if(f10.bit.enter_water_erred==1) {dig1=10;dig2=dig3=11;dig4=1;colon_off;c_off;} //显示ERR1
  356.   if(f10.bit.drain_erred==1) {dig1=10;dig2=dig3=11;dig4=2;colon_off;c_off;} //显示ERR2
  357.   if(f10.bit.overflow_erred==1) {dig1=10;dig2=dig3=11;dig4=3;colon_off;c_off;}
  358.   if(f10.bit.door_lock_erred==1) {dig1=10;dig2=dig3=11;dig4=4;colon_off;c_off;}
  359.   if(f10.bit.rise_temp_erred==1) {dig1=10;dig2=dig3=11;dig4=5;colon_off;c_off;}
  360.   if(f10.bit.abnormality_temp_erred==1) {dig1=10;dig2=dig3=11;dig4=6;colon_off;c_off;}
  361.   if(f10.bit.sensor_erred==1) {dig1=10;dig2=dig3=11;dig4=7;colon_off;c_off;}
  362.   if(f11.bit.motor_erred==1) {dig1=10;dig2=dig3=11;dig4=8;colon_off;c_off;}
  363. }

  364. void disp_conv(void)  //数码管显示处理
  365. {
  366. if(f1.bit.tested==1) disp_test();//测试显示
  367. else
  368. {
  369. if(f2.bit.powered==1)
  370. {
  371.     if(f2.bit.started==1)//程序运行显示
  372.      {
  373.       if((f10.byte!=0)||(f11.bit.motor_erred==1)) disp_err();
  374.       else
  375.       {
  376.        if(flag_time>=1) disp_delay_time();//定时显示
  377.        else   disp_time(); //洗涤时间显示
  378.           }               
  379.      }
  380.     else                   //程序暂停显示
  381.      {
  382.           if(f3.bit.set==0)         //暂停状态
  383.           {
  384.         if(flag_time>0)
  385.                 {
  386.              if(flag_time==1) disp_delay_time();
  387.                  else    //显示闪烁
  388.              {
  389.                  delay_flash_count++;
  390.                  if(delay_flash_count==1) {dig1=dig2=dig3=dig4=14;disp2=0;}
  391.              else {delay_flash_count=0;disp_delay_time();}
  392.                  }
  393.             }
  394.                 else
  395.              {
  396.          time_flash_count++;
  397.          if(time_flash_count==1) {dig1=dig2=dig3=dig4=14;disp2=0;}
  398.              else {time_flash_count=0;disp_time();}               //洗涤时间显示闪烁
  399.          }
  400.           }
  401.           else                    //设定状态
  402.            {
  403.                  if(flag_time==!0) disp_delay_time();
  404.              else
  405.                    {
  406.                     if((f0.bit.k_fab_pushed==1)||(f0.bit.k_cycle_pushed==1)||(f0.bit.k_extrinse_pushed==1))
  407.                         {
  408.                          f0.bit.k_temp_pushed=0;
  409.                          disp_time();
  410.                          set_count++;
  411.                          if(set_count>=3)
  412.                          {
  413.                          set_count=0;
  414.                          f0.bit.k_fab_pushed=0;
  415.                          f0.bit.k_cycle_pushed=0;
  416.                          f0.bit.k_extrinse_pushed=0;
  417.                          }
  418.                         }
  419.                         else if(f0.bit.k_temp_pushed==1)
  420.                         {
  421.                          f0.bit.k_fab_pushed=0;
  422.                          f0.bit.k_cycle_pushed=0;
  423.                          f0.bit.k_extrinse_pushed=0;
  424.                          disp_temp();
  425.                          set_count++;
  426.                          if(set_count>=3)
  427.                          {
  428.                          set_count=0;
  429.                          f0.bit.k_temp_pushed=0;
  430.                          }
  431.                         }
  432.                         else disp_time_temp();
  433.                    }
  434.        }
  435.      }
  436.    }
  437. }
  438. }

  439. void led_disp_test(void)
  440. {
  441.    if(f11.bit.test_prog_end==0)
  442.    {
  443.    test_disp_count++;
  444.    disp0&=0x40;disp1=0;
  445.    if(test_disp_count==1) {led_delay_off;led_extrinse_on;}
  446.    if(test_disp_count==2) {led_extrinse_off;led_h_h_on;}
  447.    if(test_disp_count==3) {led_h_h_off;led_h_c_on;}
  448.    if(test_disp_count==4) {led_h_c_off;led_w_w_on;}
  449.    if(test_disp_count==5) {led_w_w_off;led_c_c_on;}
  450.    if(test_disp_count==6) {led_c_c_off;led_prewash_on;}
  451.    if(test_disp_count==7) {led_prewash_off;led_wash_on;}
  452.    if(test_disp_count==8) {led_wash_off;led_rinse_on;}
  453.    if(test_disp_count==9) {led_rinse_off;led_spin_on;}
  454.    if(test_disp_count==10) {led_spin_off;led_mianma_on;}
  455.    if(test_disp_count==11) {led_mianma_off;led_huaxian_on;}
  456.    if(test_disp_count==12) {led_huaxian_off;led_sinong_on;}
  457.    if(test_disp_count==13) {led_sinong_off;led_maoliao_on;}
  458.    if(test_disp_count==14) {led_maoliao_off;led_delay_on;test_disp_count=0;}
  459.    }
  460.    if(f11.bit.test_prog_end==1)
  461.          {
  462.             if(f1.bit.doored==1) led_door_flash;
  463.             else led_door_off;
  464.          }
  465.    else
  466.      {
  467.           if(test_count>=2) {if(f1.bit.doored==1) led_door_on;}
  468.      }
  469. }

  470. void process_led_disp(void)
  471. {
  472. if(f1.bit.tested==1) led_disp_test();//测试显示
  473. else
  474. {
  475. if(f2.bit.powered==1)
  476. {
  477.    if(f9.bit.h_h_sel==1) led_h_h_on; else led_h_h_off;
  478.    if(f9.bit.h_c_sel==1) led_h_c_on; else led_h_c_off;
  479.    if(f9.bit.w_w_sel==1) led_w_w_on; else led_w_w_off;
  480.    if(f9.bit.c_c_sel==1) led_c_c_on; else led_c_c_off;
  481.    
  482.    if(f9.bit.maoliao_sel==1) led_maoliao_on; else led_maoliao_off;
  483.    if(f9.bit.sinong_sel==1) led_sinong_on; else led_sinong_off;
  484.    if(f9.bit.huaxian_sel==1) led_huaxian_on; else led_huaxian_off;
  485.    if(f9.bit.mianma_sel==1) led_mianma_on; else led_mianma_off;
  486.   //显示洗衣状态和过程
  487.    
  488.    if(flag_time==0)
  489.     {
  490.     if(flag_prewash==1) led_prewash_on;
  491.     else if(flag_prewash==2)
  492.          {
  493.          if(f2.bit.started==1) led_prewash_flash;
  494.          else led_prewash_on;
  495.          }
  496.     else led_prewash_off;
  497. //        -------------------------------------
  498.     if(flag_wash==1) led_wash_on;
  499.     else if(flag_wash==2)
  500.         {
  501.          if(f2.bit.started==1) led_wash_flash;
  502.          else led_wash_on;
  503.         }
  504.     else led_wash_off;
  505. //---------------------------------------
  506.          if(flag_extrinse==1) led_extrinse_on;
  507.     else if(flag_extrinse==2)
  508.          {
  509.           if(f2.bit.started==1) led_extrinse_flash;
  510.           else led_extrinse_on;
  511.           }
  512.     else led_extrinse_off;
  513. //        ---------------------------------------
  514.         if(flag_rinse==1) led_rinse_on;
  515.     else if(flag_rinse==2)
  516.          {
  517.          if(f2.bit.started==1) led_rinse_flash;
  518.          else led_rinse_on;
  519.          }
  520.     else led_rinse_off;
  521. //--------------------------------
  522.         if(flag_spin==1) led_spin_on;
  523.     else if(flag_spin==2)
  524.         {
  525.          if(f2.bit.started==1) led_spin_flash;
  526.          else led_spin_on;
  527.          }
  528.     else led_spin_off;
  529. //        --------------------------------
  530.     }
  531.    else
  532.     {
  533.          if(flag_prewash==0) led_prewash_off;
  534.          else  led_prewash_on;
  535.          
  536.          if(flag_wash==0) led_wash_off;
  537.          else  led_wash_on;
  538.          
  539.          if(flag_extrinse==0) led_extrinse_off;
  540.          else  led_extrinse_on;
  541.        
  542.          if(flag_rinse==0) led_rinse_off;
  543.          else  led_rinse_on;
  544.        
  545.          if(flag_spin==0) led_spin_off;
  546.          else  led_spin_on;
  547.          }
  548.    
  549.     if(flag_time==1) led_delay_on;
  550.     else if(flag_time==2)
  551.          {
  552.           if(f2.bit.started==1) led_delay_flash;
  553.           else led_delay_on;
  554.           }
  555.     else led_delay_off;
  556.    
  557.   
  558.    if(f2.bit.started==1)
  559.     {
  560.      if(f3.bit.prog_end==1)
  561.      {
  562.       if(f1.bit.doored==1) led_door_flash;
  563.       else led_door_off;
  564.      }
  565.         else
  566.          {
  567.           if(f1.bit.doored==1) led_door_on;
  568.           else led_door_off;
  569.           }
  570.     }
  571.   }
  572. }
  573. }

  574. void out_off(void) //
  575. {
  576.    bumpa_off;
  577.    bumpb_off;
  578.    bumpc_off;
  579.    bumph_off;
  580.    drain_off;
  581.    motor_off;
  582.    wash_on;
  583.    direct_off;
  584.    heat_off;
  585. }

  586. void check_k_power(void)
  587. {
  588.       if(f6.bit.key_power_push==0)
  589.              {
  590.                     if(!CHKBIT(PINC,key_in))
  591.                      f6.bit.key_power_push=1;
  592.                   }
  593.           else
  594.              {
  595.                   if(CHKBIT(PINC,key_in))
  596.                   {
  597.                   key_num=k_power;
  598.                   f6.bit.key_power_push=0;
  599.                   f3.bit.buzed=1;
  600.                   f3.bit.set=1;
  601.                   }
  602.                  }
  603. }

  604. void check_k_start(void)
  605. {
  606.          if((f2.bit.powered==1)||(f1.bit.tested==1))
  607.          {
  608.          if(f6.bit.key_start_push==0)
  609.              {
  610.                     if(!CHKBIT(PINC,key_in))
  611.                      f6.bit.key_start_push=1;
  612.                   }
  613.          else
  614.              {
  615.                   if(CHKBIT(PINC,key_in))
  616.                   {
  617.                   f6.bit.key_start_push=0;
  618.                   f0.bit.k_start_pushed=1;
  619.                    key_num=k_start;f3.bit.buzed=1;
  620.                   }
  621.                  }
  622.          }
  623.             if(!CHKBIT(PINC,key_in))
  624.             f2.bit.k_test3=1;
  625.                 else f2.bit.k_test3=0;
  626. }

  627. void check_k_cycle(void)
  628. {
  629.        if((f2.bit.powered==1)&&(f2.bit.started==0))
  630.            {
  631.         if(f6.bit.key_cycle_push==0)
  632.              {
  633.                     if(!CHKBIT(PINC,key_in))
  634.                      f6.bit.key_cycle_push=1;
  635.                   }
  636.             else
  637.              {
  638.                   if(CHKBIT(PINC,key_in))
  639.                   {
  640.                   f6.bit.key_cycle_push=0;
  641.                   f0.bit.k_cycle_pushed=1;
  642.                   key_num=k_cycle;f3.bit.set=1;f3.bit.buzed=1;
  643.                   }
  644.                  }
  645.                 }
  646. }

  647. void check_k_fab(void)
  648. {
  649.       if((f2.bit.powered==1)&&(f2.bit.started==0))
  650.            {
  651.          if(f6.bit.key_fab_push==0)
  652.              {
  653.                     if(!CHKBIT(PINC,key_in))
  654.                      f6.bit.key_fab_push=1;
  655.                   }
  656.             else
  657.              {
  658.                   if(CHKBIT(PINC,key_in))
  659.                   {
  660.                   f6.bit.key_fab_push=0;
  661.                   f0.bit.k_fab_pushed=1;
  662.           key_num=k_fab;f3.bit.set=1;f3.bit.buzed=1;
  663.                   }
  664.                  }
  665.                 }
  666. }

  667. void check_k_temp(void)
  668. {
  669.        if((f2.bit.powered==1)&&(f2.bit.started==0))
  670.             {
  671.                  if(f6.bit.key_temp_push==0)
  672.              {
  673.                     if(!CHKBIT(PINC,key_in))
  674.                      f6.bit.key_temp_push=1;
  675.                   }
  676.             else
  677.              {
  678.                   if(CHKBIT(PINC,key_in))
  679.                   {
  680.                   f6.bit.key_temp_push=0;
  681.                   f0.bit.k_temp_pushed=1;
  682.                   key_num=k_temp;f3.bit.set=1;f3.bit.buzed=1;
  683.                   }
  684.                  }
  685.                 }
  686. }

  687. void check_k_extrinse(void)
  688. {
  689.       if((f2.bit.powered==1)&&(f2.bit.started==0))
  690.            {
  691.         if(f6.bit.key_extrinse_push==0)
  692.              {
  693.                     if(!CHKBIT(PINC,key_in))
  694.                      f6.bit.key_extrinse_push=1;
  695.                   }
  696.             else
  697.              {
  698.                   if(CHKBIT(PINC,key_in))
  699.                   {
  700.                   f6.bit.key_extrinse_push=0;
  701.                   f0.bit.k_extrinse_pushed=1;
  702.                   key_num=k_extrinse;f3.bit.set=1;f3.bit.buzed=1;
  703.                   }
  704.                  }
  705.                 }
  706.            else
  707.            {
  708.              if(!CHKBIT(PINC,key_in))
  709.                  f2.bit.k_test2=1;
  710.                  else f2.bit.k_test2=0;
  711.            }
  712. }

  713. void check_k_delay(void)
  714. {
  715.       if((f2.bit.powered==1)&&(f2.bit.started==0))
  716.            {   
  717.                  if(f6.bit.key_delay_push==0)
  718.              {
  719.                     if(!CHKBIT(PINC,key_in))
  720.                      f6.bit.key_delay_push=1;
  721.                   }
  722.             else
  723.              {
  724.                   if(CHKBIT(PINC,key_in))
  725.                   {
  726.                   f6.bit.key_delay_push=0;
  727.                   f0.bit.k_delay_pushed=1;
  728.                   key_num=k_delay;f3.bit.set=1;f3.bit.buzed=1;
  729.                   }
  730.                  }
  731.                 }
  732.             else
  733.            {
  734.              if(!CHKBIT(PINC,key_in))
  735.                  f2.bit.k_test1=1;
  736.                  else f2.bit.k_test1=0;
  737.            }
  738. }





  739. void process_key(void)
  740. {
  741. //-----------------------------------------
  742.   if(key_num==k_power)
  743.   {
  744.    key_num=0;
  745.    k_power_count++;
  746.    if(k_power_count==1)
  747.      {
  748.       f2.bit.powered=1;
  749.           //-------------------POWER ON默认程序:热洗冷漂,化纤,主洗+漂洗+脱水
  750.       f7.bit.wash_prog6=1;
  751.           f9.bit.huaxian_sel=1;
  752.           f9.bit.h_c_sel=1;
  753.           flag_wash=flag_rinse=flag_spin=1;
  754.           main_wash_time=86;
  755.           water_temp=60;
  756.          }
  757.    else
  758.    {
  759.       k_start_count=0;//清START记数
  760.       k_power_count=0;
  761.       f2.bit.powered=0;
  762.     }
  763.   }
  764. //-----------------------------------------
  765. if(f1.bit.tested==0)
  766. {
  767. if(key_num==k_start)
  768.   {
  769.    key_num=0;
  770.    k_start_count++;
  771.    if(k_start_count==1)
  772.          f2.bit.started=1;
  773.    else
  774.     {
  775.      k_start_count=0;
  776.      f2.bit.started=0;
  777.     }
  778.    }
  779.   }
  780. else                    //测试
  781.   {
  782.    if(f11.bit.test_prog_end==0)
  783.    {
  784.     if(key_num==k_start) {key_num=0;test_count++;}
  785.    }
  786.   }

  787. if(key_num==k_fab)
  788. {
  789.    key_num=0;
  790.    f9.byte=0;
  791.    k_cycle_count=0;
  792.    f7.byte=f5.byte=0;
  793.    flag_prewash=0;
  794.    flag_wash=flag_rinse=flag_spin=1;
  795.    k_fab_count++;
  796.    if(k_fab_count==1)
  797.    {
  798.    f9.bit.mianma_sel=1;
  799.    f9.bit.h_h_sel=1;
  800.    water_temp=90;
  801.    main_wash_time=106;
  802.    }
  803.    if(k_fab_count==2)
  804.    {
  805.    f9.bit.huaxian_sel=1;
  806.    f9.bit.h_c_sel=1;
  807.    water_temp=60;
  808.    main_wash_time=86;
  809.    }
  810.    if(k_fab_count==3)
  811.    {
  812.    f9.bit.sinong_sel=1;
  813.    f9.bit.h_c_sel=1;
  814.    water_temp=60;
  815.    main_wash_time=66;
  816.    }
  817.    if(k_fab_count==4)
  818.    {
  819.    f9.bit.maoliao_sel=1;
  820.    f9.bit.w_w_sel=1;
  821.    water_temp=45;
  822.    main_wash_time=46;
  823.    }
  824.    if(k_fab_count>=5)
  825.    {
  826.    k_fab_count=1;
  827.    f9.bit.mianma_sel=1;
  828.    f9.bit.h_h_sel=1;
  829.    water_temp=90;
  830.    main_wash_time=86;
  831.    }
  832.   }
  833. ///-----------------------------------------
  834. if(f9.bit.mianma_sel==1)
  835. {
  836.   if(key_num==k_cycle)
  837.    {
  838.      key_num=0;
  839.          flag_extrinse=0;
  840.          f7.byte=f5.byte=0;
  841.          flag_prewash=flag_wash=flag_rinse=flag_spin=0;
  842.      k_cycle_count++;
  843.    if(k_cycle_count==1)
  844.     {
  845.          main_wash_time=120;
  846.          f7.bit.wash_prog2=1;
  847.          flag_prewash=flag_wash=flag_rinse=flag_spin=1;
  848.          }
  849.    else if(k_cycle_count==2)
  850.     {
  851.          main_wash_time=8;
  852.          f7.bit.wash_prog3=1;
  853.          flag_spin=1;
  854.          }
  855.    else if(k_cycle_count==3)
  856.      {
  857.           main_wash_time=21;
  858.           f7.bit.wash_prog4=1;
  859.           flag_rinse=flag_spin=1;
  860.           }
  861.    else if(k_cycle_count==4)
  862.      {
  863.           main_wash_time=98;
  864.           f7.bit.wash_prog5=1;
  865.           flag_wash=flag_rinse=1;
  866.           }
  867.    else if(k_cycle_count>4)
  868.       {
  869.            k_cycle_count=0;
  870.            main_wash_time=106;
  871.            f7.bit.wash_prog1=1;
  872.            flag_wash=flag_rinse=flag_spin=1;
  873.            }   
  874.      }
  875.    else if(key_num==k_temp)//--------------------------------
  876.    {
  877.    key_num=0;
  878.    f9.bit.h_h_sel=f9.bit.h_c_sel=f9.bit.w_w_sel=f9.bit.c_c_sel=0;
  879.    k_temp_count++;
  880.    if(k_temp_count==1) {f9.bit.h_h_sel=1;water_temp=90;}
  881.    if(k_temp_count==2) {f9.bit.h_c_sel=1;water_temp=60;}
  882.    if(k_temp_count==3) {f9.bit.w_w_sel=1;water_temp=45;}
  883.    if(k_temp_count==4) {f9.bit.c_c_sel=1;}
  884.    if(k_temp_count>=5)
  885.    {k_temp_count=1;f9.bit.h_h_sel=1;water_temp=90;}
  886.    }
  887. }
  888.   //---------------------------------------
  889. else if(f9.bit.sinong_sel==1)
  890. {
  891.   
  892.   if(key_num==k_cycle)
  893.   {
  894.    key_num=0;
  895.    flag_extrinse=0;
  896.    f7.byte=f5.byte=0;
  897.    flag_prewash=flag_wash=flag_rinse=flag_spin=0;
  898.    k_cycle_count++;
  899.    if(k_cycle_count==1)
  900.     {
  901.          main_wash_time=8;
  902.          f7.bit.wash_prog3=1;
  903.          flag_spin=1;
  904.          }
  905.    else if(k_cycle_count==2)
  906.      {
  907.           main_wash_time=21;
  908.           f7.bit.wash_prog4=1;
  909.           flag_rinse=flag_spin=1;
  910.           }
  911.    else if(k_cycle_count==3)
  912.      {
  913.           main_wash_time=58;
  914.           f5.bit.wash_prog12=1;
  915.           flag_wash=flag_rinse=1;
  916.           }
  917.    else if(k_cycle_count>3)
  918.       {
  919.            k_cycle_count=0;
  920.            main_wash_time=66;
  921.            f5.bit.wash_prog9=1;
  922.            flag_wash=flag_rinse=flag_spin=1;
  923.           }
  924.     }
  925. else if(key_num==k_temp)//----------------------------
  926.    {
  927.    key_num=0;
  928.    f9.bit.h_h_sel=f9.bit.h_c_sel=f9.bit.w_w_sel=f9.bit.c_c_sel=0;
  929.    k_temp_count++;
  930.    if(k_temp_count==1) {f9.bit.h_c_sel=1;water_temp=60;}
  931.    if(k_temp_count==2) {f9.bit.w_w_sel=1;water_temp=45;}
  932.    if(k_temp_count==3) {f9.bit.c_c_sel=1;}
  933.    if(k_temp_count>=4)
  934.    {k_temp_count=1;f9.bit.h_c_sel=1;water_temp=60;}
  935.    }
  936. }
  937. //---------------------------
  938. else if(f9.bit.huaxian_sel==1)
  939. {
  940. if(key_num==k_cycle)
  941.   {
  942.      key_num=0;
  943.          flag_extrinse=0;
  944.          f7.byte=f5.byte=0;
  945.          flag_prewash=flag_wash=flag_rinse=flag_spin=0;
  946.      k_cycle_count++;
  947.    if(k_cycle_count==1)
  948.     {
  949.          main_wash_time=100;
  950.          f7.bit.wash_prog7=1;
  951.          flag_prewash=flag_wash=flag_rinse=flag_spin=1;
  952.          }
  953.    else if(k_cycle_count==2)
  954.     {
  955.          main_wash_time=8;
  956.          f5.bit.wash_prog10=1;
  957.          flag_spin=1;
  958.          }
  959.    else if(k_cycle_count==3)
  960.      {
  961.           main_wash_time=21;
  962.           f5.bit.wash_prog11=1;
  963.           flag_rinse=flag_spin=1;
  964.           }
  965.     else if(k_cycle_count==4)
  966.      {
  967.           main_wash_time=78;
  968.           f7.bit.wash_prog8=1;
  969.           flag_wash=flag_rinse=1;
  970.           }
  971.          else if(k_cycle_count>4)
  972.      {
  973.           k_cycle_count=0;
  974.           main_wash_time=86;
  975.           f7.bit.wash_prog6=1;
  976.           flag_wash=flag_rinse=flag_spin=1;
  977.           }
  978.      }
  979. else if(key_num==k_temp)//----------------------------
  980.    {
  981.    key_num=0;
  982.    k_temp_count++;
  983.    f9.bit.h_c_sel=f9.bit.h_h_sel=f9.bit.w_w_sel=f9.bit.c_c_sel=0;
  984.    if(k_temp_count==1) {f9.bit.h_c_sel=1;water_temp=60;}
  985.    if(k_temp_count==2) {f9.bit.w_w_sel=1;water_temp=45;}
  986.    if(k_temp_count==3) {f9.bit.c_c_sel=1;}
  987.    if(k_temp_count>=4)
  988.    {k_temp_count=1;f9.bit.h_c_sel=1;water_temp=60;}
  989.    }
  990.   }
  991. //---------------------------
  992. else if(f9.bit.maoliao_sel==1)
  993. {
  994. if(key_num==k_cycle)
  995.   {
  996.      key_num=0;
  997.          flag_extrinse=0;
  998.          f7.byte=f5.byte=0;
  999.          flag_prewash=flag_wash=flag_rinse=flag_spin=0;
  1000.      k_cycle_count++;
  1001.    if(k_cycle_count==1)
  1002.     {
  1003.          main_wash_time=8;
  1004.          f5.bit.wash_prog14=1;
  1005.          flag_spin=1;
  1006.          }
  1007.    else if(k_cycle_count==2)
  1008.      {
  1009.           main_wash_time=21;
  1010.           f5.bit.wash_prog15=1;
  1011.           flag_rinse=flag_spin=1;
  1012.           }
  1013.    else if(k_cycle_count==3)
  1014.      {
  1015.           main_wash_time=38;
  1016.           f5.bit.wash_prog16=1;
  1017.           flag_wash=flag_rinse=1;
  1018.           }
  1019.    else if(k_cycle_count>3)
  1020.      {
  1021.       k_cycle_count=0;
  1022.           main_wash_time=46;
  1023.           f5.bit.wash_prog13=1;
  1024.           flag_wash=flag_rinse=flag_spin=1;
  1025.          }
  1026.    }
  1027. else if(key_num==k_temp)//----------------------------
  1028.    {
  1029.    key_num=0;
  1030.    f9.bit.h_c_sel=f9.bit.h_h_sel=f9.bit.w_w_sel=f9.bit.c_c_sel=0;
  1031.    k_temp_count++;
  1032.    if(k_temp_count==1) {f9.bit.w_w_sel=1;water_temp=45;}
  1033.    if(k_temp_count==2) f9.bit.c_c_sel=1;
  1034.    if(k_temp_count>2)
  1035.    {k_temp_count=1;f9.bit.w_w_sel=1;water_temp=45;}// 是否选择没温度。
  1036.    }
  1037.   }


  1038. ///-----------------------------------------
  1039. if(key_num==k_extrinse)
  1040. {
  1041.    key_num=0;
  1042.    k_extrinse_count++;
  1043.    if(k_extrinse_count==1)
  1044.    {
  1045.      if((flag_spin>=1)&&(flag_prewash==0)&&(flag_wash==0)&&(flag_rinse==0))
  1046.          flag_extrinse=0;
  1047.          else if(flag_rinse==2)
  1048.          {flag_rinse=1;flag_extrinse=1;;main_wash_time+=8;}
  1049.          else {flag_extrinse=1;main_wash_time+=8;}
  1050.         }
  1051.    else
  1052.    {
  1053.      k_extrinse_count=0;
  1054.          if(flag_extrinse==1)
  1055.          {flag_extrinse=0;main_wash_time-=8;}
  1056.     }
  1057.   }

  1058. ///-----------------------------------------
  1059. if(key_num==k_delay)
  1060.     {
  1061.       key_num=0;
  1062.           flag_time=1;
  1063.       time_data++;
  1064.          if(time_data>24)
  1065.           {  
  1066.           time_data=0;
  1067.           flag_time=0;
  1068.           }
  1069.       }
  1070. ///-----------------------------------------
  1071.   if(f2.bit.started==1)
  1072.          {
  1073.           f3.bit.set=0;
  1074.           if(flag_time>=1) flag_time=2;
  1075.          }
  1076. }

  1077. void check_water1(void)
  1078. {
  1079.    if(!CHKBIT(PINB,water1))
  1080.     {
  1081.     water1_off_count++;
  1082.     if(water1_off_count>=3)
  1083.      {
  1084.      f1.bit.water1ed=0;
  1085.      water1_off_count=0;
  1086.      }
  1087.     }
  1088.    else {water1_off_count=0;
  1089.   
  1090.    if(CHKBIT(PINB,water1))
  1091.     {
  1092.      water1_on_count++;
  1093.      if(water1_on_count>=18)
  1094.      {
  1095.       f1.bit.water1ed=1;
  1096.       water1_on_count=0;
  1097.      }
  1098.     }
  1099.         else water1_on_count=0;
  1100.    }
  1101. }

  1102. void check_water2(void)
  1103. {
  1104.    if(!CHKBIT(PINB,water2))
  1105.     {
  1106.     water2_off_count++;
  1107.     if(water2_off_count>=3)
  1108.      {
  1109.      f1.bit.water2ed=0;
  1110.      water2_off_count=0;
  1111.      }
  1112.     }
  1113.    else {water2_off_count=0;
  1114.   
  1115.    if(CHKBIT(PINB,water2))
  1116.     {
  1117.      water2_on_count++;
  1118.      if(water2_on_count>=18)
  1119.      {
  1120.       f1.bit.water2ed=1;
  1121.       water2_on_count=0;
  1122.      }
  1123.     }
  1124.         else water2_on_count=0;
  1125.    }
  1126. }

  1127. void check_door(void)
  1128. {
  1129.    if(!CHKBIT(PINB,door_in))
  1130.     {
  1131.     door_on_count++;
  1132.     if(door_on_count>=4)
  1133.      {
  1134.      f1.bit.doored=1;
  1135.      door_on_count=0;
  1136.      }
  1137.     }
  1138.    else door_on_count=0;
  1139.    if(CHKBIT(PINB,door_in))
  1140.     {
  1141.      door_off_count++;
  1142.      if(door_off_count>=18)
  1143.      {
  1144.       f1.bit.doored=0;
  1145.       door_off_count=0;
  1146.       }
  1147.      }
  1148.         else door_off_count=0;
  1149. }


  1150. void check_switch(void)
  1151. {
  1152.         check_water1();
  1153.         check_water2();
  1154.         check_door();
  1155. }

  1156. void enter_water_err(void)   //按START键取消
  1157. {
  1158. if(f10.bit.enter_water_erred=0)
  1159. {
  1160. if((CHKBIT(PORTB,bumpa))||(CHKBIT(PORTD,bumpb))||(CHKBIT(PORTD,bumpc))||(CHKBIT(PORTD,bumph)))
  1161. {
  1162.   enter_water_count++;
  1163.   if(enter_water_count>480)
  1164.    {
  1165.     enter_water_count=0;
  1166.         if(f1.bit.water1ed==0)
  1167.         f10.bit.enter_water_erred=1;
  1168.   }
  1169. }
  1170. }
  1171. }

  1172. void drain_err(void)
  1173. {
  1174. if(f10.bit.drain_erred==0)
  1175. {
  1176.   if(CHKBIT(PIND,drain))//排水泵启动
  1177.   {
  1178.   drain_count++;
  1179.   if(drain_count>240)
  1180.    {
  1181.     drain_count=0;
  1182.         if(f1.bit.water1ed==1)
  1183.          f10.bit.drain_erred=1;
  1184.         }
  1185.    }
  1186.   }
  1187. }

  1188. void overflow_err(void)
  1189. {
  1190. if(f10.bit.overflow_erred==0)
  1191. {
  1192.   if(f1.bit.water2ed==1)
  1193.         {
  1194.      overflow_count++;
  1195.      if(overflow_count>2)
  1196.       {
  1197.        overflow_count=0;
  1198.            f10.bit.overflow_erred=1;   
  1199.           }
  1200.          }
  1201. }
  1202. }

  1203. void door_lock_err(void)
  1204. {
  1205. if( f10.bit.door_lock_erred==0)
  1206. {
  1207.   if((f11.bit.test_prog_end==0)||(f3.bit.prog_end==0))//程序未结束
  1208.   {
  1209.   door_lock_count++;
  1210.   if(door_lock_count>10)
  1211.    {
  1212.      door_lock_count=0;
  1213.      if(f1.bit.doored==1)
  1214.      f10.bit.door_lock_erred=0;
  1215.      else f10.bit.door_lock_erred=1;
  1216.    }
  1217.   }
  1218.   else f10.bit.door_lock_erred=0;
  1219. }
  1220. else
  1221. {
  1222.   if(f1.bit.doored==1)
  1223.   f10.bit.door_lock_erred=0;
  1224. }
  1225. }


  1226. void rise_temp_err(void)
  1227. {
  1228. if(f10.bit.rise_temp_erred==0)
  1229. {
  1230.   water_temp1=fact_water_temp;
  1231.   rise_temp_count++;
  1232.   if(rise_temp_count>900)
  1233.    {
  1234.      rise_temp_count=0;
  1235.          water_temp2=fact_water_temp;
  1236.      if((water_temp2-water_temp1)<1)
  1237.          {
  1238.          if((f3.bit.prog_end==1)||(f11.bit.test_prog_end==1))  // 冷洗冷漂程序结束后报警
  1239.          f10.bit.rise_temp_erred=1;
  1240.          }
  1241.         }
  1242.    }
  1243. }

  1244. void abnormality_temp_err(void)
  1245. {
  1246.   if(f10.bit.abnormality_temp_erred==0)
  1247.   {
  1248.    
  1249.    if((fact_water_temp>90)&&(f9.bit.mianma_sel==1))
  1250.          f10.bit.abnormality_temp_erred=1;
  1251.    if((fact_water_temp>60)&&(f9.bit.sinong_sel==1))
  1252.          f10.bit.abnormality_temp_erred=1;
  1253.    if((fact_water_temp>60)&&(f9.bit.huaxian_sel==1))
  1254.          f10.bit.abnormality_temp_erred=1;
  1255.    if((fact_water_temp>45)&&(f9.bit.maoliao_sel==1))
  1256.          f10.bit.abnormality_temp_erred=1;
  1257. }
  1258. }

  1259. void sensor_err(void)
  1260. {
  1261. if(f10.bit.sensor_erred==0)
  1262. {
  1263.   if(temp_ad>0x03F0)   //开路
  1264.   f10.bit.sensor_erred=1;
  1265.   else if(temp_ad<0x30)//短路
  1266.   {
  1267.   if((f3.bit.prog_end==1)||(f11.bit.test_prog_end==1))
  1268.   f10.bit.sensor_erred=1;
  1269.   }
  1270. }
  1271. }

  1272. void motor_err(void)
  1273. {
  1274. if(f4.bit.motor_run==1)
  1275. {
  1276.   if(CHKBIT(PORTD,speed_in))
  1277.   {
  1278.    motor_count++;
  1279.    if(motor_count>=10)
  1280.    {
  1281.     motor_count=0;
  1282.         f11.bit.motor_erred=1;
  1283.    }
  1284.    }
  1285.   }
  1286. }

  1287. void process_err(void)
  1288. {
  1289.   bumpa_off;
  1290.   bumpb_off;
  1291.   bumpc_off;
  1292.   bumph_off;
  1293.   heat_off;
  1294.   direct_off;
  1295.   motor_off;
  1296.   door_off;
  1297.   if((f10.bit.abnormality_temp_erred==1)||(f10.bit.overflow_erred==1))
  1298.   drain_on;  
  1299.   else drain_off;
  1300. }

  1301. void check_err(void)
  1302. {
  1303. if((f2.bit.started==1)||(f1.bit.tested==1))
  1304. {
  1305. enter_water_err();
  1306. drain_err();
  1307. overflow_err();
  1308. door_lock_err();
  1309. rise_temp_err();
  1310. abnormality_temp_err();
  1311. sensor_err();
  1312. motor_err();
  1313. }
  1314. }

  1315. void check_key_10m(void)
  1316. {
  1317. if((f2.bit.started==0)&&(f2.bit.powered==1))
  1318. {
  1319. if(f1.bit.doored==0)
  1320. {
  1321. if(!f0.byte&0x3f)
  1322.   {
  1323.    t_1m_count++;
  1324.    if(t_1m_count>=10)
  1325.    {
  1326.     t_1m_count=0;
  1327.     f2.bit.powered=0;
  1328.    }   
  1329. }
  1330. else {f0.byte=0;t_1m_count=0;}
  1331. }
  1332. }
  1333. }

  1334. void speed_select(void)
  1335. {
  1336. if(!CHKBIT(PINC,speed_set))
  1337.    f1.bit.speed_selected=1;
  1338. else f1.bit.speed_selected=0;
  1339. }

  1340. void heat_select(void)
  1341. {
  1342. if(!CHKBIT(PINC,mode_set))
  1343.    f1.bit.heated=1;
  1344. else f1.bit.heated=0;
  1345. }

  1346. void time_on(void)
  1347. {
  1348. if(flag_time>=1)
  1349.   {
  1350. if(f2.bit.started==1)
  1351.   {
  1352. // flag_time=2;
  1353.   time_t_1h_count++;
  1354.   if(time_t_1h_count>=60)
  1355.     {
  1356.          time_t_1h_count=0;
  1357.          time_data--;
  1358.          if(time_data==0)
  1359.          {time_data=0;flag_time=0;}
  1360.     }
  1361.    }
  1362.   }
  1363. }

  1364. void spin2(void)
  1365. {
  1366.     spin_on;
  1367.         f4.bit.motor_run=1;
  1368.         low_spin_count++;
  1369.         if(low_spin_count<=6) f4.bit.s_55=1;
  1370.         else if(low_spin_count<=60) {f4.bit.s_55=0;f4.bit.s_93=1;}
  1371.         else if(low_spin_count<=120) {f4.bit.s_93=0;f4.bit.s_500=1;}
  1372.         else if(low_spin_count<=300) {f4.bit.s_500=0;f4.bit.s_800=1;}  
  1373.         else  {f4.bit.s_800=0;f4.bit.motor_run=0;low_spin_count=0;}       
  1374. }

  1375. void spin1(void)
  1376. {
  1377.     spin_on;
  1378.         f4.bit.motor_run=1;
  1379.         low_spin_count++;
  1380.         if(low_spin_count<=6)  f4.bit.s_55=1;
  1381.         else if(low_spin_count<=60) {f4.bit.s_55=0;f4.bit.s_93=1;}
  1382.         else if(low_spin_count<=120) {f4.bit.s_93=0;f4.bit.s_500=1;}
  1383.         else {f4.bit.s_500=0;f4.bit.motor_run=0;low_spin_count=0;}       
  1384. }

  1385. void wash_cycle2(void)  //逆时针11秒 停止4秒,顺时针11秒 停止4秒
  1386. {
  1387.    wash_on;
  1388.    f4.bit.s_55=1;
  1389.    wash_time_count++;
  1390.    if(wash_time_count<=11)
  1391.      {
  1392.      direct_on;
  1393.          f4.bit.motor_run=1;
  1394.          }
  1395.    else if(wash_time_count<=15)
  1396.          f4.bit.motor_run=0;
  1397.    else if(wash_time_count<=26)
  1398.      {
  1399.      direct_off;
  1400.          f4.bit.motor_run=1;
  1401.          }
  1402.    else if(wash_time_count<=30)
  1403.          f4.bit.motor_run=0;
  1404.    else
  1405.      {
  1406.          wash_time_count=0;
  1407.          f4.bit.s_55=0;
  1408.         }
  1409. }


  1410. void wash_cycle1(void)//逆时针6秒 停止9秒,顺时针6秒 停止9秒
  1411. {
  1412.    wash_on;
  1413.    f4.bit.s_55=1;
  1414.    wash_time_count++;
  1415.    if(wash_time_count<=6)
  1416.      {
  1417.      direct_on;
  1418.          f4.bit.motor_run=1;
  1419.          }
  1420.    else if(wash_time_count<=15)
  1421.          f4.bit.motor_run=0;
  1422.    else if(wash_time_count<=21)
  1423.      {
  1424.      direct_off;
  1425.          f4.bit.motor_run=1;
  1426.          }
  1427.    else if(wash_time_count<=29)
  1428.          f4.bit.motor_run=0;
  1429.    else
  1430.       {
  1431.          wash_time_count=0;
  1432.          f4.bit.s_55=0;
  1433.         }
  1434.   
  1435. }


  1436. void test_step1(void)
  1437. {
  1438.     test_time_count++;
  1439.     if(f1.bit.water1ed==0)  bumpa_on;
  1440.     else
  1441.           {
  1442.           bumpa_off;
  1443.           wash_cycle2();
  1444.           if(test_time_count>=60)
  1445.           {
  1446.            drain_on;
  1447.            if(test_time_count>=80)
  1448.            {
  1449.            test_time_count=0;
  1450.            f4.bit.motor_run=0;
  1451.        drain_off;
  1452.            f11.bit.step1_end=1;
  1453.        }
  1454.           }
  1455.          }
  1456. }

  1457. void test_step2(void)
  1458. {
  1459.     test_time_count++;
  1460.     if(f1.bit.water1ed==0)  bumpb_on;
  1461.     else
  1462.           {
  1463.           bumpb_off;
  1464.           wash_cycle2();
  1465.           if(test_time_count>=60)
  1466.           {
  1467.            drain_on;
  1468.            if(test_time_count>=80)
  1469.            {
  1470.            test_time_count=0;
  1471.            f4.bit.motor_run=0;
  1472.        drain_off;
  1473.            f11.bit.step2_end=1;
  1474.        }
  1475.           }
  1476.          }
  1477. }

  1478. void test_step3(void)
  1479. {
  1480.     test_time_count++;
  1481.     if(f1.bit.water1ed==0)  bumpc_on;
  1482.     else
  1483.           {
  1484.           bumpc_off;
  1485.           wash_cycle2();
  1486.           if(test_time_count>=60)
  1487.           {
  1488.            drain_on;
  1489.            if(test_time_count>=80)
  1490.            {
  1491.            test_time_count=0;
  1492.            f4.bit.motor_run=0;
  1493.        drain_off;
  1494.            f11.bit.step3_end=1;
  1495.        }
  1496.           }
  1497.          }
  1498. }

  1499. void test_step4(void)
  1500. {
  1501.     test_time_count++;
  1502.     if(f1.bit.water1ed==0)  bumph_on;//主水阀开?
  1503.     else
  1504.           {
  1505.           bumph_off;
  1506.           wash_cycle2();
  1507.           if(test_time_count>=60)
  1508.           {
  1509.            drain_on;
  1510.            if(test_time_count>=80)
  1511.            {
  1512.            test_time_count=0;
  1513.            f4.bit.motor_run=0;
  1514.        drain_off;
  1515.            f11.bit.step4_end=1;
  1516.        }
  1517.           }
  1518.          }
  1519. }

  1520. void test_step5(void)
  1521. {
  1522.    test_time_count++;
  1523.    drain_on;
  1524.    if(test_time_count<=180)
  1525.     {
  1526.         if(f1.bit.water1ed==0)
  1527.         spin2();
  1528.         }
  1529.    else
  1530.          {
  1531.           test_time_count=0;
  1532.           f4.bit.motor_run=0;
  1533.           drain_off;
  1534.           f11.bit.step5_end=1;
  1535.          }
  1536. }


  1537. void prewash(void)//当选棉麻或丝绒 14分
  1538. {
  1539. if(flag_prewash>=1)
  1540.    {
  1541.     flag_prewash=2;
  1542. if(wash_t<2)
  1543.     {
  1544.      f8.bit.water_in=1;
  1545.      if(f1.bit.water1ed==1) wash_cycle2();
  1546.     }
  1547. else if(wash_t<12) wash_cycle2();
  1548. else if(wash_t<14)
  1549.   {
  1550.      wash_time_count=0;
  1551.          f4.bit.motor_run=0;
  1552.          drain_on;
  1553.          if(f1.bit.water1ed==0)
  1554.          {
  1555. //         wash_cycle_2();
  1556.          spin1();
  1557.           }
  1558.     }
  1559. else
  1560.         {
  1561.          f4.bit.motor_run=0;
  1562.          low_spin_count=0;
  1563.          wash_t=0;
  1564.          flag_prewash=0;
  1565.          drain_off;
  1566.          }
  1567.   }
  1568. }

  1569. void washing(void)//丝绒
  1570. {
  1571. if(flag_wash>=1)
  1572.    {
  1573.     flag_wash=2;
  1574. if(wash_t<2)
  1575.     {
  1576.      f8.bit.water_in=1;
  1577.      if(f1.bit.water1ed==1) wash_cycle2();
  1578.     }
  1579. else if(wash_t<43) wash_cycle2();
  1580. else if(wash_t<45)
  1581.    {
  1582.      wash_time_count=0;
  1583.          f4.bit.motor_run=0;
  1584.          drain_on;
  1585.          if(f1.bit.water1ed==0)
  1586.          {
  1587. //         wash_cycle_2();
  1588.          spin1();
  1589.           }
  1590.     }
  1591. else
  1592.         {
  1593.          f4.bit.motor_run=0;
  1594.          low_spin_count=0;
  1595.          wash_t=0;
  1596.          flag_wash=0;
  1597.          drain_off;
  1598.          }
  1599.   }
  1600. }

  1601. void strongwash(void)//棉麻
  1602. {
  1603. if(flag_wash>=1)
  1604.    {
  1605.     flag_wash=2;
  1606. if(wash_t<2)
  1607.     {
  1608.      f8.bit.water_in=1;
  1609.      if(f1.bit.water1ed==1) wash_cycle2();
  1610.     }
  1611. else if(wash_t<83) wash_cycle2();
  1612. else if(wash_t<85)
  1613.    {
  1614.      wash_time_count=0;
  1615.          f4.bit.motor_run=0;
  1616.          drain_on;
  1617.          if(f1.bit.water1ed==0)
  1618.          {
  1619. //         wash_cycle_2();
  1620.          spin1();
  1621.           }
  1622.     }
  1623. else
  1624.         {
  1625.          f4.bit.motor_run=0;
  1626.          low_spin_count=0;
  1627.          wash_t=0;
  1628.          flag_wash=0;
  1629.          drain_off;
  1630.          }
  1631.   }
  1632. }

  1633. void softwash(void)//化纤
  1634. {
  1635. if(flag_wash>=1)
  1636.    {
  1637.     flag_wash=2;
  1638. if(wash_t<2)
  1639.     {
  1640.      f8.bit.water_in=1;
  1641.      if(f1.bit.water1ed==1) wash_cycle1();
  1642.     }
  1643. else if(wash_t<63) wash_cycle1();
  1644. else if(wash_t<65)
  1645.    {
  1646.      wash_time_count=0;
  1647.          f4.bit.motor_run=0;
  1648.          drain_on;
  1649.          if(f1.bit.water1ed==0)
  1650.          {
  1651. //         wash_cycle_2();
  1652.          spin1();
  1653.           }
  1654.     }
  1655. else
  1656.         {
  1657.          f4.bit.motor_run=0;
  1658.          low_spin_count=0;
  1659.          wash_t=0;
  1660.          flag_wash=0;
  1661.          drain_off;
  1662.          }
  1663.   }
  1664. }

  1665. void quickwash(void)//毛料
  1666. {
  1667. if(flag_wash>=1)
  1668.    {
  1669.     flag_wash=2;
  1670. if(wash_t<2)
  1671.     {
  1672.      f8.bit.water_in=1;
  1673.      if(f1.bit.water1ed==1) wash_cycle2();
  1674.     }
  1675. else if(wash_t<23) wash_cycle2();
  1676. else if(wash_t<25)
  1677.    {
  1678.      wash_time_count=0;
  1679.          f4.bit.motor_run=0;
  1680.          drain_on;
  1681.          if(f1.bit.water1ed==0)
  1682.          {
  1683. //         wash_cycle_2();
  1684.          spin1();
  1685.           }
  1686.     }
  1687. else
  1688.         {
  1689.          f4.bit.motor_run=0;
  1690.          low_spin_count=0;
  1691.          wash_t=0;
  1692.          flag_wash=0;
  1693.          drain_off;
  1694.          }
  1695.   }
  1696. }

  1697. void rinse(void)//一般飘洗,棉麻,丝绒,毛料
  1698. {
  1699.    if(flag_rinse>=1)
  1700.    {
  1701.    flag_rinse=2;
  1702.    if(wash_t<1) f8.bit.water_in=1;
  1703.    else if(wash_t<11) wash_cycle2();
  1704.    else if(wash_t<13)
  1705.     {
  1706.          wash_time_count=0;
  1707.          f4.bit.motor_run=0;
  1708.          drain_on;
  1709.          if(f1.bit.water1ed==0)
  1710.          {
  1711.         //         wash_cycle_2();
  1712.      spin1();
  1713.           }
  1714.      }
  1715.    else
  1716.         {
  1717.      f4.bit.motor_run=0;
  1718.          low_spin_count=0;
  1719.          wash_t=0;
  1720.          flag_rinse=0;
  1721.          drain_off;
  1722.          }
  1723.    }
  1724. }
  1725. void softrinse(void)//化纤
  1726. {
  1727.    if(flag_rinse>=1)
  1728.    {
  1729.    flag_rinse=2;
  1730.    if(wash_t<1) f8.bit.water_in=1;
  1731.    else if(wash_t<11) wash_cycle1();
  1732.    else if(wash_t<13)
  1733.     {
  1734.          wash_time_count=0;
  1735.          f4.bit.motor_run=0;
  1736.          drain_on;
  1737.          if(f1.bit.water1ed==0)
  1738.          {
  1739.         //         wash_cycle_2();
  1740.      spin1();
  1741.           }
  1742.      }
  1743.    else
  1744.         {
  1745.      f4.bit.motor_run=0;
  1746.          low_spin_count=0;
  1747.          wash_t=0;
  1748.          flag_rinse=0;
  1749.          drain_off;
  1750.          }
  1751.    }
  1752. }

  1753. void spin(void)//一般脱水,棉麻,丝绒
  1754. {
  1755. if(flag_spin>=1)
  1756.   {
  1757.    flag_spin=2;  
  1758.    if(wash_t<2)
  1759.     {
  1760.     drain_on;
  1761.     if(f1.bit.water1ed==0) spin2();
  1762.     }
  1763.    else if(wash_t<=6) spin2();
  1764.    else if(wash_t<=8)
  1765.     {
  1766.          f4.bit.motor_run=0;
  1767.          low_spin_count=0;
  1768.      wash_cycle2();//松化
  1769.         }
  1770.    else
  1771.     {
  1772.          wash_time_count=0;
  1773.          f4.bit.motor_run=0;
  1774.          drain_off;
  1775.          wash_t=0;
  1776.          flag_spin=0;
  1777.         }
  1778. }
  1779. }


  1780. void soft_lastspin(void)//化纤
  1781. {
  1782.    if(flag_spin>=1)
  1783.   {
  1784.    flag_spin=2;  
  1785.    if(wash_t<=8)
  1786.     {
  1787.          f4.bit.motor_run=1;
  1788.         //f4.bit.s_55=1;
  1789.         }
  1790.     else
  1791.     {
  1792.          wash_time_count=0;
  1793.          f4.bit.motor_run=0;
  1794.          drain_off;
  1795.          wash_t=0;
  1796.          flag_spin=0;
  1797.         }
  1798.        
  1799.   }
  1800. }
  1801. /************************************
  1802. void soft_lastspin(void)//化纤
  1803. {
  1804.    if(flag_spin>=1)
  1805.   {
  1806.    flag_spin=2;  
  1807.    if(wash_t<2)
  1808.     {
  1809.     drain_on;
  1810.     if(f1.bit.water1ed==0) spin1();
  1811.     }
  1812.    else if(wash_t<=6) spin1();
  1813.    else if(wash_t<=8)
  1814.     {
  1815.          f4.bit.motor_run=0;
  1816.          low_spin_count=0;
  1817.      wash_cycle1();//松化
  1818.         }
  1819.    else
  1820.     {
  1821.          wash_time_count=0;
  1822.          f4.bit.motor_run=0;
  1823.          drain_off;
  1824.          wash_t=0;
  1825.          flag_spin=0;
  1826.         }
  1827.   }
  1828. }
  1829. ************************************/

  1830. void quickwash_lastspin(void)//毛料
  1831. {
  1832.   
  1833.    if(flag_spin>=1)
  1834.   {
  1835.    flag_spin=2;  
  1836.    if(wash_t<2)
  1837.     {
  1838.     drain_on;
  1839.     if(f1.bit.water1ed==0) spin2();
  1840.     }
  1841.    else if(wash_t<=6) spin2();
  1842.    else if(wash_t<=8)
  1843.     {
  1844.          f4.bit.motor_run=0;
  1845.          low_spin_count=0;
  1846.      wash_cycle1();//松化
  1847.         }
  1848.    else
  1849.     {
  1850.          wash_time_count=0;
  1851.          f4.bit.motor_run=0;
  1852.          drain_off;
  1853.          wash_t=0;
  1854.          flag_spin=0;
  1855.         }
  1856.    }
  1857. }   

  1858. void extrinse(void)
  1859. {
  1860.    if(flag_extrinse>=1)
  1861.    {
  1862.    flag_extrinse=2;
  1863.    if(wash_t<1) f8.bit.water_in=1;
  1864.    else if(wash_t<6) wash_cycle2();
  1865.    else if(wash_t<8)
  1866.     {
  1867.          wash_time_count=0;
  1868.          f4.bit.motor_run=0;
  1869.          drain_on;
  1870.          if(f1.bit.water1ed==0)
  1871.          {
  1872.         //         wash_cycle_2();
  1873.      spin1();
  1874.           }
  1875.      }
  1876.    else
  1877.         {
  1878.      f4.bit.motor_run=0;
  1879.          low_spin_count=0;
  1880.          wash_t=0;
  1881.          flag_extrinse=0;
  1882.          drain_off;
  1883.          }
  1884.    }
  1885. }

  1886. void wash_program1(void)
  1887. {
  1888.    if(flag_wash>=1) strongwash();
  1889.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  1890.    if((flag_wash==0)&&(flag_rinse>=1)&&(flag_extrinse==0)) rinse();
  1891.    if((flag_spin>=1)&&(flag_rinse==0)) spin();
  1892.    if(flag_spin==0)
  1893.      {
  1894.           f2.bit.started=0;
  1895.           f7.bit.wash_prog1=0;
  1896.           f3.bit.prog_end=1;
  1897.      }
  1898. }

  1899. void wash_program2(void)
  1900. {
  1901.    if(flag_prewash>=1) prewash();
  1902.    if((flag_wash>=1)&&(flag_prewash==0)) strongwash();
  1903.    if((flag_extrinse>=1)&&(flag_wash==0)&&(flag_prewash==0)) extrinse();
  1904.    if((flag_prewash==0)&&(flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) rinse();
  1905.    if((flag_spin>=1)&&(flag_rinse==0)) spin();
  1906.    if(flag_spin==0)
  1907.     {
  1908.          f2.bit.started=0;
  1909.          f7.bit.wash_prog7=0;
  1910.          f3.bit.prog_end=1;
  1911.      }
  1912. }

  1913. void wash_program3(void)
  1914. {
  1915.    if(flag_spin>=1)  spin();
  1916.    else
  1917.    {
  1918.     f2.bit.started=0;
  1919.         f7.bit.wash_prog3=0;
  1920.         f3.bit.prog_end=1;
  1921.     }
  1922. }

  1923. void wash_program4(void)
  1924. {
  1925.    if(flag_extrinse>=1) extrinse();
  1926.    if((flag_rinse>=1)&&(flag_extrinse==0))  rinse();
  1927.    if((flag_spin>=1)&&(flag_rinse==0)) spin();
  1928.    if(flag_spin==0)
  1929.    {
  1930.     f2.bit.started=0;
  1931.         f7.bit.wash_prog4=0;
  1932.         f3.bit.prog_end=1;
  1933.     }
  1934. }

  1935. void wash_program5(void)
  1936. {
  1937.    if(flag_wash>=1) strongwash();
  1938.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  1939.    if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) rinse();
  1940.    if(flag_rinse==0)
  1941.    {
  1942.     f2.bit.started=0;
  1943.         f7.bit.wash_prog5=0;
  1944.         f3.bit.prog_end=1;
  1945.     }
  1946. }

  1947. void wash_program6(void)
  1948. {
  1949.    if(flag_wash>=1) softwash();
  1950.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  1951.    if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) softrinse();
  1952.    if((flag_spin>=1)&&(flag_rinse==0)) soft_lastspin();
  1953.    if(flag_spin==0)
  1954.    {
  1955.     f2.bit.started=0;
  1956.         f7.bit.wash_prog6=0;
  1957.         f3.bit.prog_end=1;
  1958.     }
  1959. }



  1960. void wash_program7(void)
  1961. {
  1962.    if(flag_prewash>=1) prewash();
  1963.    if((flag_wash>=1)&&(flag_prewash==0)) softwash();
  1964.    if((flag_extrinse>=1)&&(flag_wash==0)&&(flag_prewash==0)) extrinse();
  1965.    if((flag_wash==0)&&(flag_prewash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) softrinse();
  1966.    if((flag_spin>=1)&&(flag_rinse==0)) soft_lastspin();
  1967.    if(flag_spin==0)
  1968.     {
  1969.          f2.bit.started=0;
  1970.          f7.bit.wash_prog7=0;
  1971.          f3.bit.prog_end=1;
  1972.      }
  1973. }

  1974. void wash_program10(void)
  1975. {
  1976.    if(flag_spin>=1)  soft_lastspin();
  1977.    else if(flag_spin==0)
  1978.    {
  1979.     f2.bit.started=0;
  1980.         f5.bit.wash_prog10=0;
  1981.         f3.bit.prog_end=1;
  1982.     }
  1983. }

  1984. void wash_program11(void)
  1985. {
  1986.    if(flag_extrinse>=1) extrinse();
  1987.    if((flag_extrinse==0)&&(flag_rinse>=1)) softrinse();
  1988.    if((flag_spin>=1)&&(flag_rinse==0)) soft_lastspin();
  1989.    if(flag_spin==0)
  1990.    {
  1991.     f2.bit.started=0;
  1992.         f5.bit.wash_prog11=0;
  1993.         f3.bit.prog_end=1;
  1994.     }
  1995. }

  1996. void wash_program8(void)
  1997. {
  1998.   if(flag_wash>=1) softwash();
  1999.   if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  2000.   if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) softrinse();
  2001.   if(flag_rinse==0)
  2002.    {
  2003.     f2.bit.started=0;
  2004.         f7.bit.wash_prog8=0;
  2005.         f3.bit.prog_end=1;
  2006.     }
  2007. }

  2008. void wash_program9(void)
  2009. {
  2010.    if(flag_wash>=1) washing();
  2011.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  2012.    if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) rinse();
  2013.    if((flag_spin>=1)&&(flag_rinse==0)) spin();
  2014.    if(flag_spin==0)
  2015.    {
  2016.     f2.bit.started=0;
  2017.         f5.bit.wash_prog9=0;
  2018.         f3.bit.prog_end=1;
  2019.     }
  2020. }



  2021. void wash_program12(void)
  2022. {
  2023.    if(flag_wash>=1) washing();
  2024.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  2025.    if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) rinse();
  2026.    if(flag_rinse==0)
  2027.    {
  2028.     f2.bit.started=0;
  2029.         f5.bit.wash_prog12=0;
  2030.         f3.bit.prog_end=1;
  2031.     }
  2032. }

  2033. void wash_program13(void)
  2034. {
  2035.    if(flag_wash>=1)  quickwash();
  2036.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  2037.    if((flag_wash==0)&&(flag_extrinse==0)&&(flag_rinse>=1)) rinse();
  2038.    if((flag_spin>=1)&&(flag_rinse==0)) quickwash_lastspin();
  2039.    if(flag_spin==0)
  2040.    {
  2041.     f2.bit.started=0;
  2042.         f5.bit.wash_prog13=0;
  2043.         f3.bit.prog_end=1;
  2044.    }
  2045. }

  2046. void wash_program14(void)
  2047. {
  2048.    if(flag_spin>=1) quickwash_lastspin();
  2049.    if(flag_spin==0)
  2050.     {
  2051.         f2.bit.started=0;
  2052.         f5.bit.wash_prog14=0;
  2053.         f3.bit.prog_end=1;
  2054.         }
  2055. }

  2056. void wash_program15(void)
  2057. {
  2058.    if(flag_extrinse>=1) extrinse();
  2059.    if((flag_rinse>=1)&&(flag_extrinse==0)) rinse();
  2060.    if((flag_spin>=1)&&(flag_rinse==0)) quickwash_lastspin();
  2061.    if(flag_spin==0)
  2062.    {
  2063.     f2.bit.started=0;
  2064.         f5.bit.wash_prog13=0;
  2065.         f3.bit.prog_end=1;
  2066.         }
  2067. }

  2068. void wash_program16(void)
  2069. {
  2070.    if(flag_wash>=1)  quickwash();
  2071.    if((flag_extrinse>=1)&&(flag_wash==0)) extrinse();
  2072.    if((flag_rinse>=1)&&(flag_wash==0)&&(flag_extrinse==0)) rinse();
  2073.    if(flag_rinse==0)
  2074.    {
  2075.     f2.bit.started=0;
  2076.         f5.bit.wash_prog16=0;
  2077.         f3.bit.prog_end=1;
  2078.         }
  2079. }

  2080. void wash_time_control(void)
  2081. {
  2082. if((f2.bit.started==1)&&(flag_time==0))
  2083. {
  2084.   wash_t++;
  2085.   if(main_wash_time>0)
  2086.   main_wash_time--;
  2087.   else main_wash_time=0;
  2088. // if(flag_prewash==0) {main_wash_time=(main_wash_time-prewash_time); prewash_time=0;}
  2089. // if(flag_wash==0) {main_wash_time=(main_wash_time-wash_time);wash_time=0;}
  2090. //if(flag_rinse==0) {main_wash_time=(main_wash_time-rinse_time);rinse_time=0;}
  2091. //if(flag_spin==0) {main_wash_time=(main_wash_time-spin_time);spin_time=0;}
  2092.   }
  2093. }

  2094. void main_wash_prog(void)
  2095. {
  2096. if(f2.bit.started==1)
  2097. {
  2098.   if(flag_time==0)
  2099.   {
  2100.   if((f10.byte==0)&&(f11.bit.motor_erred==0))
  2101.   {
  2102.   if(f7.bit.wash_prog1==1) wash_program1();
  2103.   else if(f7.bit.wash_prog2==1) wash_program2();
  2104.   else if(f7.bit.wash_prog3==1) wash_program3();
  2105.   else if(f7.bit.wash_prog4==1) wash_program4();
  2106.   else if(f7.bit.wash_prog5==1) wash_program5();
  2107.   else if(f7.bit.wash_prog6==1) wash_program6();
  2108.   else if(f7.bit.wash_prog7==1) wash_program7();
  2109.   else if(f7.bit.wash_prog8==1) wash_program8();
  2110.   else if(f5.bit.wash_prog9==1) wash_program9();
  2111.   else if(f5.bit.wash_prog10==1) wash_program10();
  2112.   else if(f5.bit.wash_prog11==1) wash_program11();
  2113.   else if(f5.bit.wash_prog12==1) wash_program12();
  2114.   else if(f5.bit.wash_prog13==1) wash_program13();
  2115.   else if(f5.bit.wash_prog14==1) wash_program14();
  2116.   else if(f5.bit.wash_prog15==1) wash_program15();
  2117.   else if(f5.bit.wash_prog16==1) wash_program16();
  2118.    }
  2119.   else process_err();
  2120.   }
  2121. }
  2122. else out_off();
  2123. }   

  2124. void erasure_eep(void)
  2125. {
  2126.   unsigned char i;
  2127.   for(i=0;i<=250;i++)
  2128.   EEPROMwrite(addr+i, 0x00);
  2129. }

  2130. void process_power_off(void)
  2131. {
  2132.    door_off;
  2133.    out_off();
  2134.    disp0=disp1=disp2=0;
  2135.    dig1=dig2=dig3=dig4=14;
  2136.    f1.byte&=0xF0;//speed/modeselect/test
  2137.   // f3.byte&=0x08;//buz,set
  2138.   // f2.byte&=0xF0;//test1,test2,test3标志
  2139.    f2.byte=f3.byte=f4.byte=f5.byte=f7.byte=0;
  2140.    f8.byte=f9.byte=f10.byte=f11.byte=0;
  2141.    flag_time=flag_prewash=flag_wash=flag_rinse=flag_spin=flag_extrinse=0;
  2142.    time_data=0;
  2143.    buz_off;
  2144. //erasure_eep();
  2145. }

  2146. void check_test(void)
  2147. {
  2148. if(f2.bit.powered==0)
  2149. {
  2150.   if(f1.bit.tested==0)
  2151.   {
  2152.    if((f2.bit.k_test1==1)&&(f2.bit.k_test2==1)&&(f2.bit.k_test3==1))
  2153.     {
  2154.      f2.bit.k_test1=f2.bit.k_test2=f2.bit.k_test3=0;
  2155.          f1.bit.tested=1;
  2156.          f3.bit.test_buz=1;
  2157.     }
  2158.    }
  2159. else
  2160.   {
  2161.    if(( f2.bit.k_test1==1)&&( f2.bit.k_test2==1)&&( f2.bit.k_test3==1))
  2162.    {
  2163.      f2.bit.k_test1=f2.bit.k_test2=f2.bit.k_test3=0;
  2164.          f1.bit.tested=0;
  2165.    }
  2166. }
  2167. }
  2168. }
  2169. void test_prog(void)
  2170. {
  2171.         if(test_count==2)  test_step1();
  2172.         if((test_count==4)||(f11.bit.step1_end==1))  test_step2();
  2173.         if((test_count==6)||(f11.bit.step2_end==1))  test_step3();
  2174.         if((test_count==8)||(f11.bit.step3_end==1))  test_step4();
  2175.         if((test_count==10)||(f11.bit.step4_end==1))  test_step5();
  2176.         if((test_count==11)||(f11.bit.step5_end==1))
  2177.              {
  2178.                   f2.bit.k_test1=f2.bit.k_test2=f2.bit.k_test3=0;
  2179.                   test_count=0;
  2180.               f11.bit.test_prog_end=1;
  2181.          }
  2182. }


  2183. void program_control(void)
  2184. {
  2185. if(f1.bit.tested==1)
  2186.   {
  2187.    door_on;
  2188.    if(f11.bit.test_prog_end==0) test_prog(); //测试
  2189.    else  
  2190.      {
  2191.           if(f1.bit.doored==0)
  2192.            {
  2193.                   door_off;
  2194.               if(f2.bit.end_buz==0) end_buzing();
  2195.               else f1.bit.tested=0;
  2196.                 }
  2197.          }
  2198.   }
  2199. else
  2200.     {
  2201.          if(f2.bit.powered==1)
  2202.           {
  2203.           door_on;
  2204.           if(f3.bit.prog_end==0) main_wash_prog();//洗衣程序
  2205.           else
  2206.              {
  2207.               if(f1.bit.doored==0)
  2208.                   {
  2209.                   door_off;
  2210.                   if(f2.bit.end_buz==0) end_buzing();
  2211.                   else f2.bit.powered=0;
  2212.                   }
  2213.              }
  2214.           }
  2215.           else process_power_off(); // 关机
  2216.          }
  2217. }

  2218. void process_water_in(void)
  2219. {
  2220. if(f8.bit.water_in==1)
  2221. {
  2222.   if(flag_prewash==2)
  2223.   {
  2224.    if(f1.bit.water1ed==0) bumpa_on;
  2225.    else {bumpa_off;f8.bit.water_in=0;}
  2226.    }
  2227.   else if(flag_wash==2)
  2228.   {
  2229.    if(f1.bit.water1ed==0) bumpb_on;
  2230.    else {bumpb_off;f8.bit.water_in=0;}
  2231.    }
  2232.   else if(flag_rinse==2)
  2233.   {
  2234.    if(f1.bit.water1ed==0) bumpc_on;
  2235.    else {bumpc_off;f8.bit.water_in=0;}
  2236.    }
  2237. }
  2238. }


  2239. void heat_control(void)
  2240. {
  2241. if(f1.bit.heated==1)
  2242. {
  2243.   if(f9.bit.h_h_sel==1)
  2244.   {
  2245.    if(fact_water_temp<88) heat_on;
  2246.    else if(fact_water_temp>=90) heat_off;
  2247.    else
  2248.        {
  2249.             if(CHKBIT(PORTB,heat)) heat_on;
  2250.                 else if(!CHKBIT(PORTB,heat)) heat_off;
  2251.            }
  2252.   }
  2253.   if(f9.bit.h_c_sel==1)
  2254.   {
  2255.    if(fact_water_temp<58) heat_on;
  2256.    else if(fact_water_temp>=60) heat_off;
  2257.    else
  2258.        {
  2259.             if(CHKBIT(PORTB,heat)) heat_on;
  2260.                 else if(!CHKBIT(PORTB,heat)) heat_off;
  2261.            }
  2262.    }
  2263.   if(f9.bit.w_w_sel==1)
  2264.   {
  2265.    if(fact_water_temp<43) heat_on;
  2266.    else if(fact_water_temp>=45) heat_off;
  2267.    else
  2268.        {
  2269.             if(CHKBIT(PORTB,heat)) heat_on;
  2270.                 else if(!CHKBIT(PORTB,heat)) heat_off;
  2271.            }
  2272.   }
  2273.   if(f9.bit.c_c_sel==1) heat_off;
  2274. }
  2275. }


  2276. void speed_control(void)
  2277. {
  2278. if(f4.bit.motor_run==1)
  2279. {
  2280.    if(f4.bit.s_55==1)  s2=320;
  2281.    else if(f4.bit.s_93==1)  s2=645;
  2282.    else if(f4.bit.s_500==1) s2=120;
  2283.    else if(f4.bit.s_800==1) s2=75;
  2284.    else s2=0;
  2285.   
  2286.    if(s1<s2)   //S1<S2转速偏高
  2287.     {
  2288.         if(t1>120) t1=(t1-t_step);
  2289.         else t1=120;
  2290.         }
  2291.    else if(s1>s2)   //S1>S2转速偏低
  2292.     {
  2293.      if(t1<=t2) t1=(t1+t_step);
  2294.     }
  2295.     t=(0xFFFF-t1/8);
  2296.   }
  2297.   else {s2=0;t=0XFFFF;t1=120;}
  2298. }

  2299. void check_zero(void)
  2300. {
  2301. if(f4.bit.motor_run==1)
  2302. {
  2303.   if(f4.bit.zero_come==1)
  2304.    {
  2305.    if(t1_count==0)
  2306.     {
  2307.          CLI();
  2308.      TCCR1B = 0x00; //stop
  2309.      TCNT1H = t>>8;
  2310.      TCNT1L = t;
  2311.          TCCR1B = 0x03; //start Timer
  2312.          SEI();
  2313.          t1_count=1;
  2314.     }
  2315.   if(f8.bit.t1_come==1)
  2316.   {
  2317.    f8.bit.t1_come=0;
  2318.    if(t1_count==1)//设置第二次中断时间t
  2319.     {
  2320.          CLI();
  2321.          TCCR1B = 0x00; //stop
  2322.          TCNT1H = 0xFF; //setup
  2323.      TCNT1L = 0x83;
  2324.          TCCR1B = 0x03; //start Timer
  2325.          SEI();
  2326.          t1_count=2;
  2327.          motor_on;
  2328.          asm("nop");
  2329.         }
  2330.    else
  2331.       {
  2332.            t1_count=0;
  2333.            motor_off;
  2334.        f4.bit.zero_come=0;
  2335.            TCCR1B = 0x00; //stop
  2336.            //f4.bit.motor_run=0;
  2337.            if(MCUCR==0x0A) MCUCR = 0x0B;
  2338.            else MCUCR = 0x0A;
  2339.            }
  2340.          }
  2341.   }
  2342. }
  2343.   else
  2344.   {
  2345.         t1_count=0;
  2346.         f4.bit.zero_come=0;
  2347.         motor_off;
  2348.         }
  2349. }


  2350. //过零中断
  2351. #pragma interrupt_handler int0_isr:2
  2352. void int0_isr(void)
  2353. {
  2354. f4.bit.zero_come=1;
  2355. }

  2356. //电机反馈脉冲中断
  2357. #pragma interrupt_handler int1_isr:3  
  2358. void int1_isr(void)
  2359. {
  2360. s1=speed_count; //读取速度单位100us
  2361. speed_count=0;
  2362. }

  2363. #pragma interrupt_handler timer1_ovf_isr:9
  2364. void timer1_ovf_isr(void)
  2365. {
  2366. f8.bit.t1_come=1;
  2367. }

  2368. #pragma interrupt_handler timer2_ovf_isr:5
  2369. void timer2_ovf_isr(void)
  2370. {
  2371. TCNT2 = 0x9C; //reload counter value
  2372. speed_count++;
  2373. }

  2374. #pragma interrupt_handler timer0_ovf_isr:10
  2375. void timer0_ovf_isr(void)
  2376. {
  2377. TCNT0 = 0x83; //reload counter value
  2378. t_1ms=1;
  2379. }


  2380. //-----------------------------------------------------------------------------
  2381. // initialization
  2382. //-----------------------------------------------------------------------------
  2383. void port_init(void)
  2384. {
  2385. PORTA = 0xFE;
  2386. DDRA  = 0xFE;
  2387. PORTB = 0x00;
  2388. DDRB  = 0x8F;
  2389. PORTC = 0xC0; //m103 output only
  2390. DDRC  = 0xC1;
  2391. PORTD = 0x00;
  2392. DDRD  = 0xF3;
  2393. }

  2394. //Watchdog initialize
  2395. // prescale: 2048K
  2396. void watchdog_init(void)
  2397. {
  2398. WDR(); //this prevents a timout on enabling
  2399. WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
  2400. }

  2401. //TIMER0 initialize - prescale:64
  2402. // WGM: Normal
  2403. // desired value: 1mSec
  2404. // actual value:  1.000mSec (0.0%)
  2405. void timer0_init(void)
  2406. {
  2407. TCCR0 = 0x00; //stop
  2408. TCNT0 = 0x83; //set count
  2409. OCR0  = 0x7D;  //set compare
  2410. TCCR0 = 0x03; //start timer
  2411. }

  2412. //TIMER1 initialize - prescale:8
  2413. // WGM: 0) Normal, TOP=0xFFFF
  2414. // desired value: 120uSec
  2415. // actual value: 119.000uSec (0.8%)
  2416. void timer1_init(void)
  2417. {
  2418. TCCR1B = 0x00; //stop
  2419. TCNT1H = 0xFF; //setup
  2420. TCNT1L = 0x89;
  2421. OCR1AH = 0x00;
  2422. OCR1AL = 0x77;
  2423. OCR1BH = 0x00;
  2424. OCR1BL = 0x77;
  2425. // OCR1CH = $OCR1CH$;
  2426. // OCR1CL = $OCR1CL$;
  2427. ICR1H  = 0x00;
  2428. ICR1L  = 0x77;
  2429. TCCR1A = 0x00;
  2430. TCCR1B = 0x02; //start Timer
  2431. }

  2432. //TIMER2 initialize - prescale:8
  2433. // WGM: Normal
  2434. // desired value: 100uSec
  2435. // actual value: 100.000uSec (0.0%)
  2436. void timer2_init(void)
  2437. {
  2438. TCCR2 = 0x00; //stop
  2439. ASSR  = 0x00; //set async mode
  2440. TCNT2 = 0x9C; //setup
  2441. OCR2  = 0x64;
  2442. TCCR2 = 0x02; //start
  2443. }

  2444. //ADC initialize
  2445. // Conversion time: 3uS
  2446. void adc_init(void)
  2447. {
  2448. ADCSR = 0x00; //disable adc
  2449. ADMUX = 0x00; //select adc input 0
  2450. ACSR  = 0x80;
  2451. ADCSR = 0xC1;
  2452. }

  2453. //call this routine to initialize all peripherals
  2454. void init_devices(void)
  2455. {
  2456. //stop errant interrupts until set up
  2457. CLI(); //disable all interrupts
  2458. port_init();
  2459. watchdog_init();
  2460. timer0_init();
  2461. timer1_init();
  2462. timer2_init();
  2463. adc_init();

  2464. MCUCR = 0x0A;
  2465. GICR  = 0xC0;
  2466. TIMSK = 0x45; //timer interrupt sources
  2467. SEI(); //re-enable interrupts
  2468. //all peripherals are now initialized
  2469. }

  2470. void init_disp(void)
  2471. {
  2472. disp0=disp1=disp2=0;
  2473. dig1=dig2=dig3=dig4=14;
  2474. }

  2475. //-----------------------------------------------------------------------------
  2476. // main
  2477. //-----------------------------------------------------------------------------
  2478. main()
  2479. {
  2480.    
  2481.         init_devices();
  2482.         heat_select();
  2483.         speed_select();
  2484.         init_disp();
  2485.         init_tasktime();
  2486.         f3.bit.buzed=1;
  2487.        
  2488. while(1)
  2489.         {  
  2490.             check_zero();
  2491.                 if(t_1ms==1)
  2492.                 {
  2493.                  t_1ms=0;
  2494.                  check_switch();//door,water lever
  2495.                 }   
  2496.                
  2497.             if(t_3ms==0)
  2498.                 {
  2499.                  t_3ms=3;
  2500.                  scan();
  2501.                 }   
  2502.                  
  2503.             if(t_50ms==0)
  2504.                 {
  2505.                  t_50ms=50;
  2506.                  buzing();
  2507.                  ad_conv();
  2508.                 }
  2509.                
  2510.             if(t_100ms==0)
  2511.                 {
  2512.                  t_100ms=100;
  2513.                  process_key();
  2514.                  speed_control();
  2515.                 }
  2516.                
  2517.                 if(t_500ms==0)
  2518.                 {
  2519.                   t_500ms=500;
  2520.                   test_buzing();
  2521.           err_buzing();
  2522.                   disp_conv();
  2523.                   process_led_disp();
  2524.                  }
  2525.           
  2526.                 if(t_1s==0)
  2527.                 {                             
  2528.                  t_1s=1000;
  2529.                  process_water_in();
  2530.                  check_err();
  2531.                  check_test();
  2532.                  program_control();//test_prog,main_wash_prog
  2533.                  heat_control();
  2534.                  WDR();
  2535.          }
  2536.                  
  2537.                  if(t_1m==0)
  2538.                  {                
  2539.                   t_1m=60000;
  2540.                   time_on();
  2541.                   check_key_10m();//不按键>10min切断电源,进入待机状态,需重新按POWER键进入默认状态
  2542.                   wash_time_control();
  2543.                  }       
  2544.   }
  2545. }
复制代码



yqs138168 发表于 2017-6-29 20:09:22 | 显示全部楼层
RE: 滚筒洗衣机ICC源代码与详细电路图 (ATmega16芯片) [修改
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-25 09:36

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表