//滚筒洗衣机
//www.ouravr.com
//版权声明:ourAVR网站获得了作者的授权在网上发布此资料。
//2007.04.04
//ICC-AVR application builder :
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
#include <eeprom.h>
//PA
//NTC IN
#define clk 0x02
//NC
#define com7 0x08
#define com1 0x10
#define com6 0x20
#define com2 0x40
#define com3 0x80
#define clk_h SETBIT(PORTA,clk)
#define clk_l CLRBIT(PORTA,clk)
#define com7_h SETBIT(PORTA,com7)
#define com7_l CLRBIT(PORTA,com7)
#define com6_h SETBIT(PORTA,com6)
#define com6_l CLRBIT(PORTA,com6)
#define com1_h SETBIT(PORTA,com1)
#define com1_l CLRBIT(PORTA,com1)
#define com2_h SETBIT(PORTA,com2)
#define com2_l CLRBIT(PORTA,com2)
#define com3_h SETBIT(PORTA,com3)
#define com3_l CLRBIT(PORTA,com3)
//PB
#define data 0x01
#define direct 0x02
#define wash_spin 0x04
#define heat 0x08
//DOOR IN
#define door_in 0x10
//WATER2
#define water2 0x20
//WATER1
#define water1 0x40
#define bumpa 0x80
#define data_h SETBIT(PORTB,data)
#define data_l CLRBIT(PORTB,data)
#define direct_on SETBIT(PORTB,direct)
#define direct_off CLRBIT(PORTB,direct)
#define wash_on CLRBIT(PORTB,wash_spin)
#define spin_on SETBIT(PORTB,wash_spin)
#define heat_on SETBIT(PORTB,heat)
#define heat_off CLRBIT(PORTB,heat)
#define bumpa_on SETBIT(PORTB,bumpa)
#define bumpa_off CLRBIT(PORTB,bumpa)
//PD
#define bumpb 0x01
#define bumpc 0x02
//ZERO IN
#define zero_in 0x04
//SPEED IN
#define speed_in 0x08
#define bumph 0x10
#define drain 0x20
#define door 0x40
#define motor 0x80
#define bumpb_on SETBIT(PORTD,bumpb)
#define bumpb_off CLRBIT(PORTD,bumpb)
#define bumpc_on SETBIT(PORTD,bumpc)
#define bumpc_off CLRBIT(PORTD,bumpc)
#define bumph_on SETBIT(PORTD,bumph)
#define bumph_off CLRBIT(PORTD,bumph)
#define drain_on SETBIT(PORTD,drain)
#define drain_off CLRBIT(PORTD,drain)
#define door_on SETBIT(PORTD,door)
#define door_off CLRBIT(PORTD,door)
#define motor_on SETBIT(PORTD,motor)
#define motor_off CLRBIT(PORTD,motor)
//PC
#define buz 0x01
#define key_in 0x02
//S1/SPEED SET
#define speed_set 0x04
//S2/MODE SET
#define mode_set 0x08
//S4
//S3
#define com4 0x80
#define com5 0x40
#define buz_on SETBIT(PORTC,buz)
#define buz_off CLRBIT(PORTC,buz)
#define com4_h SETBIT(PORTC,com4)
#define com4_l CLRBIT(PORTC,com4)
#define com5_h SETBIT(PORTC,com5)
#define com5_l CLRBIT(PORTC,com5)
#define k_power 1
#define k_start 2
#define k_cycle 3
#define k_fab 4
#define k_temp 5
#define k_extrinse 6
#define k_delay 7
unsigned int temp_ad;
unsigned int value,ad;
unsigned char ad_count;
unsigned char water_temp;
unsigned char fact_water_temp;
unsigned char water_temp1;
unsigned char water_temp2;
unsigned char t_1ms;
unsigned char t_3ms;
unsigned char t_10ms;
unsigned char t_50ms;
unsigned char t_100ms;
unsigned int t_500ms;
unsigned int t_1s;
unsigned int t_1m;
unsigned char t_1m_count;
unsigned int time_t_1h_count;
unsigned char time_data;
unsigned char scan_count;
unsigned char buz_count;
unsigned char end_buz_count;
unsigned char test_buz_count;
unsigned char k_power_count;//key_count
unsigned char k_start_count;
unsigned char k_cycle_count;
unsigned char k_fab_count;
unsigned char k_temp_count;
unsigned char k_extrinse_count;
unsigned char k_delay_count;
unsigned char set_count;
unsigned char key_num;
unsigned int addr;
unsigned int addr1;
unsigned int enter_water_count; //err_count
unsigned char drain_count;
unsigned char overflow_count;
unsigned char door_lock_count;
unsigned int rise_temp_count;
unsigned char motor_count;
unsigned char door_on_count;
unsigned char door_off_count;
unsigned char water1_on_count;
unsigned char water1_off_count;
unsigned char water2_on_count;
unsigned char water2_off_count;
unsigned char test_count;
unsigned char test_time_count;
unsigned char test_disp_count;
unsigned char temp_disp_count;
unsigned char delay_flash_count;
unsigned char time_flash_count;
unsigned char spin_count; //脱水计数
unsigned int low_spin_count;
unsigned char main_wash_time;
unsigned int speed_count;
unsigned char wash_time_count;
unsigned char wash_t;
unsigned char flag_prewash;//过程标志
unsigned char flag_wash;
unsigned char flag_rinse;
unsigned char flag_extrinse;
unsigned char flag_spin;
unsigned char flag_time;
unsigned char disp0,disp1,disp2,dig1,dig2,dig3,dig4;//dig为数字
unsigned int s1;//实际测得转速
unsigned int s2;//设定转速
unsigned char t2_count;
unsigned char t1_count;
unsigned int t;//定时器timer1定时常数
unsigned int t1;//可控硅延时开通起始时间,调速宽度t1/100us单位
//可控硅固定开通时间//单位100us待定
#define t2 9000
#define t0 1000
//时间步长250us
#define t_step 20
//初始速度100us #define t 0xFFFF-t1-100
#define led_h_h_on SETBIT(disp1,0x40)
#define led_h_h_off CLRBIT(disp1,0x40)
//#define led_h_h_flash disp1^=0x40
#define led_h_c_on SETBIT(disp0,0x10)
#define led_h_c_off CLRBIT(disp0,0x10)
//#define led_h_c_flash disp0^=0x10
#define led_w_w_on SETBIT(disp0,0x04)
#define led_w_w_off CLRBIT(disp0,0x04)
//#define led_w_w_flash disp0^=0x04
#define led_c_c_on SETBIT(disp0,0x02)
#define led_c_c_off CLRBIT(disp0,0x02)
//#define led_c_c_flash disp0^=0x02
#define led_mianma_on SETBIT(disp1,0x10)
#define led_mianma_off CLRBIT(disp1,0x10)
//#define led_mianma_flash disp1^=0x10
#define led_huaxian_on SETBIT(disp1,0x08)
#define led_huaxian_off CLRBIT(disp1,0x08)
//#define led_huaxian_flash disp1^=0x08
#define led_sinong_on SETBIT(disp1,0x01)
#define led_sinong_off CLRBIT(disp1,0x01)
//#define led_sinong_flash disp1^=0x01
#define led_maoliao_on SETBIT(disp0,0x80)
#define led_maoliao_off CLRBIT(disp0,0x80)
//#define led_maoliao_flash disp0^=0x80
#define led_prewash_on SETBIT(disp1,0x20)
#define led_prewash_off CLRBIT(disp1,0x20)
#define led_prewash_flash disp1^=0x20
#define led_wash_on SETBIT(disp0,0x08)
#define led_wash_off CLRBIT(disp0,0x08)
#define led_wash_flash disp0^=0x08
#define led_rinse_on SETBIT(disp1,0x04)
#define led_rinse_off CLRBIT(disp1,0x04)
#define led_rinse_flash disp1^=0x04
#define led_spin_on SETBIT(disp0,0x01)
#define led_spin_off CLRBIT(disp0,0x01)
#define led_spin_flash disp0^=0x01
#define led_extrinse_on SETBIT(disp1,0x02)
#define led_extrinse_off CLRBIT(disp1,0x02)
#define led_extrinse_flash disp1^=0x02
#define led_delay_on SETBIT(disp0,0x20)
#define led_delay_off CLRBIT(disp0,0x20)
#define led_delay_flash disp0^=0x20
#define led_door_on SETBIT(disp0,0x40)
#define led_door_off CLRBIT(disp0,0x40)
#define led_door_flash disp0^=0x40
#define colon_on SETBIT(disp2,0x50)
#define colon_off CLRBIT(disp2,0x50)
#define colon_flash disp2^=0x50
#define c_on SETBIT(disp2,0x08)
#define c_off CLRBIT(disp2,0x08)
//#define c_flash disp2^=0x08
//74LS164QG-QA QH=0数码管共阳
const unsigned char data_7seg[]={0x5F,0x48,0x73,0x79,0x6C,0x3D,0x3F,0x58,0x7F,0x7D,0x37,0x22,0x17,0x08,0x00};
// 0,1,2,3,4,5,6,7,8,9,E,R,c,度,无显示,
//-----------------------------------------------------------------------------
// A/D table -10~110度
//-----------------------------------------------------------------------------
//#