www.pudn.com > plc_1.zip > process.c


#include "reg51.h" 
 
//extern void delay(unsigned int); 
extern unsigned char old_data,key,pc,intr[6]; 
sbit Inc = P1^0; 
sbit Dec = P1^1; 
sbit DA  = P1^2; 
sbit Wri = P3^2; 
bit I2c_Read(unsigned char,unsigned char); 
void On_Light(unsigned char,bit,unsigned char); 
void delay(unsigned int); 
unsigned int input(void); 
unsigned char temp,pc_bak =0 ; 
bit light_on = 0,jump,cmp_bit,time_out; 
 
void Process(void) 
{ 
      
     unsigned char i; 
	 unsigned int temp_in; 
	 pc = 0; 
	 old_data = 0x00; 
	 key = 0xff; 
 
	 while(1) 
     {  
       I2c_Read(pc++,1);  
       switch(intr[0]) { 
                        case 0x00 :  I2c_Read(pc++,1);       
						             temp = 0x80; 
									 temp = temp >> intr[0]; 
									 key = ~temp & key; 
                                     On_Light(old_data,0,key); 
									 break; 
 
                        case 0x01 :  I2c_Read(pc++,1); 
                                     temp = 0x80; 
                     				 temp = temp >> intr[0]; 
									 key = temp | key; 
									 On_Light(old_data,0,key); 
                                     break; 
 
						case 0x04 :  I2c_Read(pc++,1); 
						             old_data = intr[0]; 
									 On_Light(old_data,0,key); 
									 break; 
 
                        case 0x05 :  I2c_Read(pc++,1); 
						             if (intr[0] == 0) 
									     light_on = 0; 
									 else  
									     light_on = 1; 
									 On_Light(old_data,0,key); 
									 break; 
 
					    case 0x06 :  I2c_Read(pc++,1); 
						             old_data += intr[0]; 
									 On_Light(old_data,0,key); 
									 break; 
 
					    case 0x07 :  I2c_Read(pc++,1); 
						             old_data -= intr[0]; 
									 On_Light(old_data,0,key); 
									 break; 
 
						case 0x10 :  I2c_Read(pc++,1); 
						             pc = intr[0]; 
									 break; 
 
					    case 0x15 :  while(1); 
				   
						case 0x02 :  I2c_Read(pc++,1); 
						             temp = intr[0]; 
									 I2c_Read(pc++,1); 
									 for (i = 0;i < temp;i++) 
									 { 
    								     if (intr[0] == 0) 
										     delay(100); 
                                         else if(intr[0] == 1) 
										     delay(1000); 
										 else if(intr[0] == 2) 
										     delay(60000); 
									 } 
									 break; 
                        
                         case 0x11 : I2c_Read(pc++,1);               //SDZ N,M 
                                     if (old_data == intr[0]) 
                                     { 
                                        I2c_Read(pc++,1); 
                                        pc = intr[0]; 
                                     } 
                                     else  
                                        pc++;   
                                     break; 
 
                         case 0x12 : I2c_Read(pc++,1);               //DY N 
                                     pc_bak = pc; 
                                     pc = intr[0]; 
                                     break; 
 
                         case 0x13 : pc = pc_bak;                    //FH 
                                     break;           
        
                         case 0x09 : cmp_bit = 0; 
						             goto aaa; 
                         case 0x08 : cmp_bit = 1; 
						         aaa:jump = 0; 
						             I2c_Read(pc++,1); 
						             if (intr[0] <= 10) 
						             { 
				                        temp_in = input();  
                                        // while(1)    {  temp_in = input(); On_Light((unsigned char )temp_in ,0,0);  delay(1000); temp_in = temp_in >> 8 ;On_Light((unsigned char) temp_in,0,0);delay(1000);}                                        
									    if ((temp_in & (1 << intr[0])) == cmp_bit) 
                                           jump = 1; 
									  } 
									  else 
									     switch(intr[0]) 
										             { 
													    case 11 : if (Inc == cmp_bit) 
    									                          jump = 1; 
				             									  break; 
														case 12 : if (Dec == cmp_bit) 
														          jump = 1; 
																  break; 
														case 13 : if (DA == cmp_bit) 
														          jump = 1; 
																  break; 
														case 14 : if (Wri == cmp_bit) 
														          jump = 1; 
																  break; 
														case 15 : if (time_out == cmp_bit) 
														          jump = 1; 
																  break;														      
													  }  
   
									        if (jump == 1) 
											{ 
							                    I2c_Read(pc++,1); 
												pc = intr[0]; 
											} 
											else 
											    pc++; 
 
						                      
                        } 
         } 
 
}