this be easier to read


Code:
 GetIRcode:
     
     TRISIO        = %00111111     ' setup input=1,output=0 GPIO.0 = 1 to input 
     PULSIN GPIO.0,1,Leader        ' get leader high pulse time value in on GPIO.0   
    IF Leader < 400 tHEN return    ' look for 4500us high pulse  below 4000us  then its 2nd key area pulse  or data/ address bits
    IF Leader > 480 tHEN return    ' above 4800us  then it no sig
   
  FOR X = 0 TO 31                  ' grab 32 incoming pulses
      PULSIN GPIO.0,1,BtnVal(X)    ' now measuring high-going pulse widths
  NEXT X
      
      z = 0                            ' Z points to start range of byte 
      S = 7                            ' S points to end range of byte 
      X = 0                            ' start X at 0 to line up with BtnVal array
  for Y = 1 to 4                       ' Get in Array and decode 4 bytes from 32 bit pulses 
        T = 7                          ' Set T to 7 so that it puts BtnVal(0) in to D7 location  
        FOR X = Z TO S                 ' sort 8 pulses of byte
    
          IF BtnVal[X]  > 150 THEN     ' > 150 x 10uS = > 1.5mS pulse period = 1
             DByteTmp = DByte[Y]       ' get into temp var
       
              DByteTmp.0[T]=1          ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte 
            ELSE
              DByteTmp.0[T]=0
           ENDIF
  
          DByte[Y] = DByteTmp           ' get it back into DByte(y)
          T = T - 1                     ' T points to next MSB on loop
        NEXT X
    
      Z = x                             ' Z = X (0,8,16,24) points to start of next byte
      S = 7 + X                         ' S  (7,15,23,31) points to End of next DByte BtnVal offset to X
  next Y                                ' loop for 4 bytes
 
  
   ' only save code if it differnat to stored IR code 
    
    for x = 1 to 4 
      if  DByte[x] <> STDByte[x] then 
          wrITE x,DByte[x]     
      endif    
    next x  
   
   Return