Jari Viitanen

New C-user need help with "indexed" port pin selection.

Discussion created by Jari Viitanen on Jun 8, 2010
Latest reply on Jun 14, 2010 by Mark Hotchkiss

/* How to define / use RELE[Ch]  == PTED[Ch]??   instead of program below?       */

/* to get program shorted and more flexible */

/*      #define RELE[Ch] PTED_PTED[Ch]  ???*/

/* Where Ch can have value 0 to 3 and examble RELE[1] drive port E pin PTED1 and RELE[2] drive  pin PTED2 */

 

/****************************************************/
/* OptoTest     with        QE128                            */
/* Opto active Low      */
/* If OptoLow[Ch] value is bigger than OffTime[Ch]  then set Port E pin 1 high */

 

/* Ch = Channel (for input , output and memory locations */
/* RELE can have value ON ==1 or OFF==0*/

 

 

 


void OptoTest(void) {
  if (Ch==1){
    
    if (RELE1 == OFF){
       
       if (OptoLow[Ch] >= OffTime[Ch]){
          //OffTime =Measured pulse time
          RELE1 = ON ;
          OptoLow[Ch] = 0;
       }
       
       if (OPTO[Ch] == OFF) {
          OptoLow[Ch]++ ;
       }
    }
  }
  if (Ch==2){
    
    if (RELE2 == OFF){
       
       if (OptoLow[Ch] >= OffTime[Ch]){
          //OffTime =Measured pulse time
          RELE2 = ON ;
          OptoLow[Ch] = 0;
       }
       
       if (OPTO[Ch] == OFF) {
          OptoLow[Ch]++ ;
       }
    }
  }
     
  else OptoLow[Ch] = 0;
}
   
 
/****************************************************/

Outcomes