⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icc(atmega16).c

📁 滚筒洗衣机AVR(ATmega16芯片) c源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
//滚筒洗衣机
//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度
//----------------------------------------------------------------------------- 
//#pragma data:data
const unsigned int adtable[]=
{
 //0x3F1,0x3BD,0x3BA,0x3B7,0x3B0,0x3A8,0x3A2,0x39F,0x39D,0x398,
 0x393,0x38F,0x387,0x385,0x382,0x380,0x378,0x371,0x366,0x360,
 0x35E,0x355,0x34D,0x340,0x33E,0x338,0x330,0x327,0x31F,0x31C,
 0x30F,0x307,0x305,0x303,0x300,0x2E6,0x2E0,0x2D5,0x2C7,0x2C0,
 0x2BF,0x2B1,0x2A2,0x29B,0x290,0x27F,0x27B,0x278,0x267,0x260,
 0x258,0x24C,0x23F,0x238,0x22F,0x21F,0x218,0x20E,0x203,0x1FC,
 0x1F0,0x1E7,0x1E0,0x1D8,0x1C7,0x1C0,0x1BD,0x1B0,0x1A3,0x19E,
 0x18F,0x187,0x182,0x180,0x170,0x167,0x160,0x158,0x14F,0x144,
 0x13F,0x138,0x130,0x127,0x11F,0x11C,0x110,0x106,0x103,0xFF,
 0xFC,0xF8,0xF0,0xE7,0xE3,0xE0,0xD8,0xCF,0xC9,0xC6,                                         
 0xC3,0xC0,0xB8,0xB5,0xB0,0xA7,0xA5,0xA2,0x9F,0x9C,
 0x98,0x94,0x8F,0x8D,0x8A,0x7F,0x7C,0x7A,0x78,0x75,
 };

void buzing(void)//一次130-150ms
{
 if( f3.bit.buzed==1)//按键
 {
  buz_count++;
  buz_on;
  if(buz_count>=3)
  {
  buz_count=0;
  buz_off;
  f3.bit.buzed=0;
  }
 }
}

void end_buzing(void)
{
  end_buz_count++;
  PORTC^=buz;
  if(end_buz_count>=12)
  {
   end_buz_count=0;
   buz_off;
   f2.bit.end_buz=1;
  }
}

void test_buzing(void)
{
 if(f3.bit.test_buz==1)
 {
  buz_off;
  PORTC^=buz;
  test_buz_count++;
  if(test_buz_count>=3) 
  {
   buz_off;
   test_buz_count=0;
   f3.bit.test_buz=0;
  }
 }
}

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


void disp_test(void)
{
   if(test_count==0) {dig1=dig2=dig3=dig4=0;colon_flash;}
   if(test_count==2) {dig1=dig2=dig3=dig4=1;colon_flash;} 
   if(test_count==4) {dig1=dig2=dig3=dig4=2;colon_flash;}
   if(test_count==6) {dig1=dig2=dig3=dig4=3;colon_flash;}
   if(test_count==8) {dig1=dig2=dig3=dig4=4;colon_flash;}
   if(test_count==10) {dig1=dig2=dig3=dig4=5;colon_flash;}
 }

void disp_delay_time(void)
{
   c_off;
   dig1=time_data/10;
   dig2=time_data%10;
   dig3=dig4=0x00;
   if(f2.bit.started==1) colon_flash;
   else colon_on;
}

void disp_time(void)
{
    c_off;
	if(f2.bit.started==1) colon_flash;
	else colon_on;
    dig1=0;
	dig2=main_wash_time/60;
	dig3=(main_wash_time-dig2*60)/10;
	dig4=main_wash_time-dig2*60-dig3*10;
}

void disp_temp(void)
{
    colon_off;
	c_on;
	dig1=0;
	dig2=water_temp/10;
	dig3=water_temp%10;
	dig4=12;//data_7seg[12];C
}

void disp_time_temp(void)
{
 if(f8.bit.time_disp==0)
   {
     disp_time();
	 temp_disp_count++;
	 if(temp_disp_count>8)
	  {
	   temp_disp_count=0;
	   f8.bit.temp_disp=1;
	   f8.bit.time_disp=1;
	   }
    }
   else
    {
	 if(f8.bit.temp_disp==1)
	 {
	  disp_temp();
      temp_disp_count++;
	  if(temp_disp_count>8)
	  {
	   temp_disp_count=0;
	   f8.bit.temp_disp=0;
	   f8.bit.time_disp=0;
	  }
	  } 
     }
}

void disp_err(void)
{
  if(f10.bit.enter_water_erred==1) {dig1=10;dig2=dig3=11;dig4=1;colon_off;c_off;} //显示ERR1
  if(f10.bit.drain_erred==1) {dig1=10;dig2=dig3=11;dig4=2;colon_off;c_off;} //显示ERR2
  if(f10.bit.overflow_erred==1) {dig1=10;dig2=dig3=11;dig4=3;colon_off;c_off;}
  if(f10.bit.door_lock_erred==1) {dig1=10;dig2=dig3=11;dig4=4;colon_off;c_off;}
  if(f10.bit.rise_temp_erred==1) {dig1=10;dig2=dig3=11;dig4=5;colon_off;c_off;}
  if(f10.bit.abnormality_temp_erred==1) {dig1=10;dig2=dig3=11;dig4=6;colon_off;c_off;}
  if(f10.bit.sensor_erred==1) {dig1=10;dig2=dig3=11;dig4=7;colon_off;c_off;}
  if(f11.bit.motor_erred==1) {dig1=10;dig2=dig3=11;dig4=8;colon_off;c_off;}
}

void disp_conv(void)  //数码管显示处理
{
 if(f1.bit.tested==1) disp_test();//测试显示
 else
 {
 if(f2.bit.powered==1)
 { 
    if(f2.bit.started==1)//程序运行显示
     {
      if((f10.byte!=0)||(f11.bit.motor_erred==1)) disp_err();
      else
      { 
       if(flag_time>=1) disp_delay_time();//定时显示
       else   disp_time(); //洗涤时间显示
	  }               
     }
    else                   //程序暂停显示
     {
	  if(f3.bit.set==0)         //暂停状态
	  {
        if(flag_time>0) 
		{
	     if(flag_time==1) disp_delay_time();
		 else    //显示闪烁
	     {
		 delay_flash_count++;
		 if(delay_flash_count==1) {dig1=dig2=dig3=dig4=14;disp2=0;}
	     else {delay_flash_count=0;disp_delay_time();}
		 }
	    }
		else
	     {
         time_flash_count++;
         if(time_flash_count==1) {dig1=dig2=dig3=dig4=14;disp2=0;}
	     else {time_flash_count=0;disp_time();}               //洗涤时间显示闪烁
         }
	  }
	  else                    //设定状态
	   {
		 if(flag_time==!0) disp_delay_time();
	     else
		   { 
		    if((f0.bit.k_fab_pushed==1)||(f0.bit.k_cycle_pushed==1)||(f0.bit.k_extrinse_pushed==1))
			{
			 f0.bit.k_temp_pushed=0;
			 disp_time();
			 set_count++;
			 if(set_count>=3) 
			 {
			 set_count=0;
			 f0.bit.k_fab_pushed=0;
			 f0.bit.k_cycle_pushed=0;
			 f0.bit.k_extrinse_pushed=0;
			 }
			}
			else if(f0.bit.k_temp_pushed==1) 
			{
			 f0.bit.k_fab_pushed=0;
			 f0.bit.k_cycle_pushed=0;
			 f0.bit.k_extrinse_pushed=0;
			 disp_temp();
			 set_count++;
			 if(set_count>=3) 
			 {
			 set_count=0;
			 f0.bit.k_temp_pushed=0;
			 }
			}
			else disp_time_temp();
		   }
       }
     }
   }
 }
}

void led_disp_test(void)
 {
   if(f11.bit.test_prog_end==0)
   {
   test_disp_count++;
   disp0&=0x40;disp1=0;
   if(test_disp_count==1) {led_delay_off;led_extrinse_on;}
   if(test_disp_count==2) {led_extrinse_off;led_h_h_on;}
   if(test_disp_count==3) {led_h_h_off;led_h_c_on;}
   if(test_disp_count==4) {led_h_c_off;led_w_w_on;}
   if(test_disp_count==5) {led_w_w_off;led_c_c_on;}
   if(test_disp_count==6) {led_c_c_off;led_prewash_on;}
   if(test_disp_count==7) {led_prewash_off;led_wash_on;}
   if(test_disp_count==8) {led_wash_off;led_rinse_on;}
   if(test_disp_count==9) {led_rinse_off;led_spin_on;}
   if(test_disp_count==10) {led_spin_off;led_mianma_on;}
   if(test_disp_count==11) {led_mianma_off;led_huaxian_on;}
   if(test_disp_count==12) {led_huaxian_off;led_sinong_on;}
   if(test_disp_count==13) {led_sinong_off;led_maoliao_on;}
   if(test_disp_count==14) {led_maoliao_off;led_delay_on;test_disp_count=0;}
   }
   if(f11.bit.test_prog_end==1)
	 { 
	    if(f1.bit.doored==1) led_door_flash;
	    else led_door_off;
	 }
   else 
     {
	  if(test_count>=2) {if(f1.bit.doored==1) led_door_on;}
     }
 }

void process_led_disp(void)
{ 
 if(f1.bit.tested==1) led_disp_test();//测试显示
 else
 {
 if(f2.bit.powered==1)
 {
   if(f9.bit.h_h_sel==1) led_h_h_on; else led_h_h_off;
   if(f9.bit.h_c_sel==1) led_h_c_on; else led_h_c_off;
   if(f9.bit.w_w_sel==1) led_w_w_on; else led_w_w_off;
   if(f9.bit.c_c_sel==1) led_c_c_on; else led_c_c_off;
   
   if(f9.bit.maoliao_sel==1) led_maoliao_on; else led_maoliao_off;
   if(f9.bit.sinong_sel==1) led_sinong_on; else led_sinong_off;
   if(f9.bit.huaxian_sel==1) led_huaxian_on; else led_huaxian_off;
   if(f9.bit.mianma_sel==1) led_mianma_on; else led_mianma_off;
  //显示洗衣状态和过程 
   
   if(flag_time==0)
    {
    if(flag_prewash==1) led_prewash_on;
    else if(flag_prewash==2)
	 {
	 if(f2.bit.started==1) led_prewash_flash;
	 else led_prewash_on;
	 }
    else led_prewash_off;
//	-------------------------------------
    if(flag_wash==1) led_wash_on;
    else if(flag_wash==2)
	{
	 if(f2.bit.started==1) led_wash_flash;
	 else led_wash_on;
	}
    else led_wash_off;
//---------------------------------------
	 if(flag_extrinse==1) led_extrinse_on;
    else if(flag_extrinse==2)
	 {
	  if(f2.bit.started==1) led_extrinse_flash;
	  else led_extrinse_on;
	  }
    else led_extrinse_off;
//	---------------------------------------
	if(flag_rinse==1) led_rinse_on;
    else if(flag_rinse==2)
	 {
	 if(f2.bit.started==1) led_rinse_flash;
	 else led_rinse_on;
	 }
    else led_rinse_off;
//--------------------------------
	if(flag_spin==1) led_spin_on;
    else if(flag_spin==2)
	{
	 if(f2.bit.started==1) led_spin_flash;
	 else led_spin_on;
	 }
    else led_spin_off;
//	--------------------------------
    }
   else
    {
	 if(flag_prewash==0) led_prewash_off;
	 else  led_prewash_on;
	 
	 if(flag_wash==0) led_wash_off;
	 else  led_wash_on;
	 
	 if(flag_extrinse==0) led_extrinse_off;
	 else  led_extrinse_on;
	
	 if(flag_rinse==0) led_rinse_off;
	 else  led_rinse_on;
	
	 if(flag_spin==0) led_spin_off;
	 else  led_spin_on;
	 }
   
    if(flag_time==1) led_delay_on;
    else if(flag_time==2) 
	 {
	  if(f2.bit.started==1) led_delay_flash;
	  else led_delay_on;
	  }
    else led_delay_off;
   
  
   if(f2.bit.started==1)
    {
     if(f3.bit.prog_end==1)
     {
      if(f1.bit.doored==1) led_door_flash;
      else led_door_off;
     }
	else 
	 {
	  if(f1.bit.doored==1) led_door_on;
	  else led_door_off;
	  } 
    }
  }
 }
} 

void out_off(void) //
{
   bumpa_off;
   bumpb_off;
   bumpc_off;
   bumph_off;
   drain_off;
   motor_off;
   wash_on;
   direct_off;
   heat_off;
}

void check_k_power(void)
{
      if(f6.bit.key_power_push==0)
	     {
		    if(!CHKBIT(PINC,key_in))
		     f6.bit.key_power_push=1;
		  }
	  else 
	     {
		  if(CHKBIT(PINC,key_in))
		  {
		  key_num=k_power;
		  f6.bit.key_power_push=0;
		  f3.bit.buzed=1;
		  f3.bit.set=1;
		  }
		 }
}

void check_k_start(void)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -