Sony Kumanda Sinyallerini Okuma Uygulaması

Bu işlemi yapacak program PICBasic Pro dili ile yazıldı. Kod aşağıdaki gibi.
Include "Modedefs.Bas"
TRISA=%00000000
PORTA=0
TRISB=%10000000
PORTB=0
Header Var Word ' Header pulse length
Packet Var Word ' 12-bit IR information
P_Val Var Byte ' The bit length 60us = 0, 120us = 1
IR_But Var Byte ' The BUTTON code returned
IR_Dev Var Byte ' The DEVICE code returned
Sony_LP Var Byte ' Temporary loop variable
IR_Sensor Var PortB.7 ' Assign the IR Sensor to this pin
i var byte
ANADONGU:
Gosub IRIN ' Receive an IR signal
If IR_Dev = 255 then goto ANADONGU ' Check if header was valid
If IR_Dev <> 1 then goto ANADONGU ' If not a TV DEVICE code then look again
Serout PortB.2, N9600, [#IR_But] ' Transmit the 2 bytes serially
Pause 150 ' Delay for 100ms
Goto ANADONGU ' Do it forever
IRIN:
IR_Dev=255
IR_But=255
Pulsin PortB.7,0,Header ' Measure the header length.
If Header < 210 then Return ' Verify a good header
If Header > 270 then Return ' If not valid then exit
For Sony_Lp=0 to 11 ' Do 12-bits
Pulsin PortB.7,0,P_Val ' Receive the IR bit pulse
If P_Val >= 90 then ' If it's >= 90 then we've received a 1
Packet.0[Sony_Lp]=1 ' So set the appropriate bit of PACKET
Else ' Else
Packet.0[Sony_Lp]=0 ' Clear the appropriate bit of PACKET
Endif13.10.2008ket & %01111111 ' Mask the 7 BUTTON bits
IR_Dev=(Packet >>7) & %00011111 ' Move down and mask, the 5 DEVICE bits
Return
END