program sirc_lcd; var lTime, MyAdd, MyCmd, MainAdd, MainCmd, IsSet : byte; var progStat : boolean; txt : string[3]; label MainApp; procedure GetSIRC; var ir_add, ir_cmd, x : byte ; label StartLook; begin StartLook: ir_add := 0; ir_cmd := 0; while(portb.0) do lTime :=0; //wait for it to be low //reset the counter while(portb.0 = 0)do //while the pin is low which is our pulse count begin Inc(lTime); //increment every 200uS until pin is high delay_us(200); //200uS delay end; if(lTime <= 10) then goto StartLook; //Start too short so restart if(lTime >= 14) then goto StartLook; //Start too long so restart lTime := 0; for x :=0 to 6 do //repeat 7 times for command begin ir_cmd := (ir_cmd shr 1); //if it was skipped or is done ORing then shift over the 1 while(portb.0) do lTime := 0; //wait for it to be low //reset the counter while(portb.0 = 0) do //while the pin is low which is our pulse count begin Inc(lTime); //increment every 200uS until pin is high delay_us(200); //200uS delay end; if(lTime >= 6) then ir_cmd := (ir_cmd or 0x40); //If its high then OR a 1 in else skip //if its less than 6 its a 0 so dont OR it end; for x :=0 TO 4 do //repeat 5 times for address/device begin ir_add := (ir_add shr 1); //if it was skipped or is done ORing then shift over the 1 while(portb.0) do lTime := 0; //wait for it to be low //reset the counter while(portb.0 = 0) do //while the pin is low which is our pulse count begin Inc(lTime); //increment every 200uS until pin is high delay_us(200); //200uS delay end; if(lTime >= 6) then ir_add := (ir_add or 0x10); //If its high then OR a 1 in else skip //if its less than 6 its a 0 so dont OR it end; MyAdd := ir_add; MyCmd := ir_cmd; end; begin cmcon := 7; // comparator off, digital I/O trisa := %00000000; // GP0 output, GP1 input porta := %00000000; // make all outputs '0' trisb := %00000001; portb := 0; IsSet := 0; Lcd_Config(PORTA,3,2,1,0,PORTB,4,7,5); LCD_Cmd(LCD_CLEAR); MainApp: while(1) do begin if (portb.0 = 0 ) then GetSIRC; 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); end; end.