IR

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 CMM2

Syntax:
IR dev, key , int
IR CLOSE
IR SEND pin, dev, key

Description:

IR dev, key , int
Decodes NEC or Sony infrared remote control signals.
An IR Receiver Module is used to sense the IR light and demodulate the signal. It should be connected to the IR pin (see the pinout tables). 
This command will automatically set that pin to an input.
The IR signal decode is done in the background and the program will continue after this command without interruption. 
'dev' and 'key' should be numeric variables and their values will be updated whenever a new signal is received
('dev' is the device code transmitted by the remote and 'key' is the key pressed).
'int' is a user defined subroutine that will be called when a new key press is received or when the existing key is held down for auto repeat. 
In the interrupt subroutine the program can examine the variables 'dev' and 'key' and take appropriate action.

IR CLOSE
The IR CLOSE command will terminate the IR decoder and return the I/O pin to a not configured state.


Note that for the NEC protocol the bits in 'dev' and 'key' are reversed. For example, in 'key' bit 0 should be bit 7, bit 1 should be bit 6, etc. 
This does not affect normal use but if you are looking for a specific numerical code provided by a manufacturer you should reverse the bits. 
See the manual chapter "Special Hardware Devices" for more details.

 ' recieve NEC IR codes
 dim integer IRdev, IRkey, revIRkey
 IR IRdev, IRkey , IRint
 
 do
   if IRrec = 1 then
     revIRkey = bitReverse(IRkey, 8)
     print hex$(IRdev,4);" ";hex$(IRkey,2);" ";hex$(revIRkey,2)
     IRrec = 0
   endif
 loop until inkey$ <>""
end
 
sub IRint
 if ((IRdev>>8)and &hFF)  = (inv(IRdev) and &hFF) then ' we have an 8 bit device code.
   IRdev = IRdev>>8 and &hFF
 endif
 IRrec = 1 ' set a flag to indicate reception of code
end sub
 
function bitReverse(x!, k!) as integer
 local integer n
 for n = 1 to k!
   bitReverse = (bitReverse << 1) + ((x! >> n) and 1)
 next n
end function

IR SEND pin, dev, key
Generate a 12-bit Sony Remote Control protocol infrared signal.
'pin' is the I/O pin to use. This can be any I/O pin which will be automatically configured as an output and should be connected to an infrared LED.
Idle is low with high levels indicating when the LED should be turned on.
'dev' is the device being controlled and is a number from 0 to 31, 'key' is the simulated key press and is a number from 0 to 127.
The IR signal is modulated at about 38KHz and sending the signal takes about 25mS.

 

To send NEC codes, you can use BITBANG BITSTREAM

 

Last edited: 29 September, 2020