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

📄 wash._c

📁 because I can not get the download rights, so I uoload this file.This is a wash program, include a c
💻 _C
字号:
// 改:不加上拉,在读时加然后去除


//ICC-AVR application builder : 2006-12-30 21:44:52
// Target : M128
// Crystal: 1.0000Mhz

#include <iom128v.h>
#include <macros.h>
#include "wash.h"

int	loop_cs,  loop_cs0; //Wash times num, First store with cs<3
int	TimeCount,  TimeCount0;		//decin Timer(100ms);
int k0, k_tim;					//Keybrd: k0 old, k_tim:press time
int KP;			  // Keybra value
int beep_num, beep_delay, beep_delay0;	//Beep Time and delay, num=num*2, if num&1 On


//call this routine to initialize all peripherals
void init_devices(void)
{
 //Init var 
 loop_cs=loop_cs0=TimeCount=TimeCount0=k0=k_tim=KP=beep_num=beep_delay=0;
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 WDTCR=0x18;   //Watch Off
 WDTCR=0;
 port_init();
 timer_init();

 MCUCR = 0x00; //No sleep
 EICRA = 0x00;  EICRB = 0x00;	 EIMSK = 0x00;	 //extended ext ints
 TIMSK = 0x02; // OCIE0timer interrupt sources /???
 ETIMSK = 0x00; //extended timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}


void port_init(void)
{
/***** Port ***************************************************
 Input:
 PA[7..5]: In/Out time	PA[4..2]:Wait time,  PA[1,0]:CiShu
 PB[2,1,0]: YeMian detect     		  		 PB[5,4]:SW for Auto
 PE[5..0]: Select line, to panel switch 
 PF[0] :KeyRight 	 PF[1]:KeyLeft
 Output:
 PB[3,6]: Light				  PB[7]:buzer
 PC[5..0]:to in SSR 		  PD[5..0]:to OFF SSR
 **************************************************************/
 PORTA = 0xFF;		 DDRA  = 0x00;		//PINA = 0x0FF;
 PORTB = 0x37;		 DDRB  = 0xC8;		//PINB = 7;
 PORTC = 0x00;		 DDRC  = 0xFF;		
 PORTD = 0x00;		 DDRD  = 0xFF;
 PORTE = 0x3F;		 DDRE  = 0x00;		//PINE=0x0FF;
 PORTF = 0x03;		 DDRF  = 0x00;		//PING=3;
 PORTG = 0x00;		 DDRG  = 0x00;
}

//IntCLK=1MHz
// desired value: timer0:10Hz   timer2:1KHz
void timer_init(void)
{
 //Setup Timer0, Use 8bit counter
 TCCR0 = 0x00; 	 	 //stop
 ASSR  = 0x00; 		 //set async mode
 TCNT0 = 0x00; 
 OCR0  = 90;   		 //OCN=f_0/(2*N*f_n)-1 {N=1024 O=46.8}
 TCCR0 = 0x0f;		 //0x0f;		 // start timer: div:1024 mode:OCR
}

void main(void)
{
  int x;
  init_devices();
  Light(1);
  Beep(1, 5);
  
  while (1) {
  	 if (loop_cs != 0) {
	     if (TimeCount==0) {
		  	 loop_cs--;
		 	 switch (loop_cs & 3) {
		 	    case 3: 
					 AddOn; 	   			
					 TimeCount=ReadPara(0); 
					 break;
				case 2: 
					 AddOff; DecOff; 	
					 TimeCount=ReadPara(1); 
					 break;
		    	case 1: 
					 DecOn; 				
					 TimeCount=ReadPara(0); 
					 break;
		    	case 0: 
					 AddOff; DecOff;		
					 TimeCount=ReadPara(3);
					 if (loop_cs==0) {
					 	Beep(10, 10);
						Light(0);
					 } 
					 break;
			 }
		 }
	 }
	 x=KP;
     if (x != 0){
	   KP=0;
	   if (x & 0x8c) 
	   	  Beep(2,1);
	   else
	      Beep(1,1);
	   if (x&8) 
	   	  DecOn;
	   if (x&4) 
	   	  AddOn;
	   if (x&2) {
	   	  loop_cs=0; 
		  AddOff; DecOff;
		  Light(1);
	   }			//stop
	   if (x&1) {
	      if (loop_cs0==0) {
		     if (loop_cs==0) {			//start
			    loop_cs = ReadPara(2)<<2;
				loop_cs0=0;
				Light(2);
			 } else {
			    loop_cs0=loop_cs; loop_cs=0;			 //Pause
				TimeCount0=TimeCount; TimeCount=0;
				AddOff;  DecOff;
				Light(3);
			 }
		  } else {
		     loop_cs=loop_cs0;  loop_cs0=0; //resume
			 TimeCount=TimeCount0;
			 Light(2);
		  }
		  KP=0;
	   }
	   if (x&0x80) {
	   	  AddOff; DecOff;
	   }
	 }
  }
}


//Key service, define in include: KBRD	 (PING & 3);
void timer0_100ms_isr(void)  //int	 key(void)
{
  int k_val;
  
  if (TimeCount!=0) TimeCount--;
  k_val = KBRD;
  
  if (k_val != 0) {
  	 //0 1 ... KAX0 ... KMAX1
	 if (k_tim < KMAX1) {
	 	k_tim++;
		if (k_tim == KMAX1) {
		   KP=0x80; 
		   k_tim=KMAX1+1;
		}
	 	if (k_tim == KMAX0)  { 
		   KP=k_val<<2; k0=0; 
		}
		if (k_tim<KMAX0) 
		   k0=k_val;
	 }
  } else {
     if (k_tim<KMAX0) 
	 	KP = k0;
	 k_tim=0;
	 k0=0;
  }
  if (beep_num != 0) {
     if (beep_delay0!=0) {
	    beep_delay0--;
	 } else {
	    beep_num--;
		if (beep_num&1) 
		   PORTB |= 0x80; 
		else 
		   PORTB &=0x7f;
		beep_delay0=beep_delay;
	 }
  } 
}

// Set freq and time, Create wave by TIMER2
void Beep(int num, int delay)
{
  beep_num=(num<<1);
  beep_delay=delay;
  beep_delay0=0;
}

/////////////////////////////////////////////////////////////
// Light (st)
// st: 1:Ready  2:Runing  3:Pause  0:Over 
void Light(int st)
{
   int mst;
   mst=0;
   if (st&1) 
   	  mst |= 0x08; 
   if (st&2) 
   	  mst |= 0x40;  
   PORTB = mst;
}

/////
// InTime:3 WaitTime:2 Cishu:2 BetOnOff:1
//
//
int ReadPara(int s)
{
   int xp;
   xp = ~PINA;
   switch (s) {
   	  case 0: //ADdOn time, x+1
	     xp = ( (xp&0xe0)>>5)+1; break;
	  case 1: //Wait time 8<<x
	     xp = 8<<((xp&0x18)>>3); break;
	  case 2: // CiShu 8<<x
	     xp = 8 << ((xp&0x06)>>1); break;
	  case 3: // Beteen add and on, x!=0 ? 40 : 4
	     if (xp&1) 
		 	xp=40; 
		 else 
		 	xp=4; 
		 break;
   }
   return(xp);
}

⌨️ 快捷键说明

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