program SIRC_LCD dim MyAdd as byte MyCmd as byte txt as string[3] sub procedure Get_SIRC() dim ir_add as byte ir_cmd as byte x as byte lTime as byte StartLook: asm nop end asm ir_add = 0 ir_cmd = 0 while(portb.0) lTime = 0 wend 'wait for it to be low 'reset the counter while(portb.0 = 0) 'while the pin is low which is our pulse count Inc(lTime) 'increment every 200uS until pin is high delay_us(200) '200uS delay wend if(lTime <= 10) then goto StartLook end if 'Start too short so restart if(lTime >= 14) then goto StartLook end if 'Start too long so restart lTime = 0 for x = 0 to 6 'repeat 7 times for command ir_cmd = (ir_cmd >> 1) 'if it was skipped or is done ORing then shift over the 1 while(portb.0) lTime = 0 wend 'wait for it to be low 'reset the counter while(portb.0 = 0) 'while the pin is low which is our pulse count Inc(lTime) 'increment every 200uS until pin is high delay_us(200) '200uS delay wend if(lTime >= 6) then ir_cmd = (ir_cmd or 0x40) end if 'If its high then OR a 1 in else skip 'if its less than 6 its a 0 so dont OR it next x for x = 0 TO 4 'repeat 5 times for address/device ir_add = (ir_add >> 1) 'if it was skipped or is done ORing then shift over the 1 while(portb.0) lTime = 0 wend 'wait for it to be low 'reset the counter while(portb.0 = 0) 'while the pin is low which is our pulse count Inc(lTime) 'increment every 200uS until pin is high delay_us(200) '200uS delay wend if(lTime >= 6) then ir_add = (ir_add or 0x10) end if 'If its high then OR a 1 in else skip 'if its less than 6 its a 0 so dont OR it next x MyAdd = ir_add MyCmd = ir_cmd end sub main: cmcon = 7 trisa = %00000000 ' GP0 output, GP1 input porta = %00000000 ' make all outputs '0' trisb = %00000001 portb = 0 Lcd_Config(PORTA,3,2,1,0,PORTB,4,7,5) LCD_Cmd(LCD_CLEAR) while(1) if (portb.0 = 0 ) then Get_SIRC end if LCD_Out(1,1, "addr = ") ByteToStr(MyAdd,txt) LCD_Out(1,8, txt) ByteToStr(MyCmd,txt) LCD_Out(2,1, "comm = ") LCD_Out(2,8, txt) wend end.