Csub NECSend for the PicoMite


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3321
Posted: 06:07am 10 Feb 2024      

Here is a NECsend Sub that works with all the devices I have that use the NEC protocol. Boith 16 bit and 8 bit address devices work.

The main difference with the CSub is it uses 2 pins for the output, one for data and the other for 38kHz modulation. The driver transistor combines them.
Diagnostic Print statements can be removed.

The demo program is a simple repeater with a 2 second delay to distinguish the original and repeated signals.
' NEC IR Remote Control repeater.
Dim integer dev, key  'codes for Device (address) and Button (data)
Const IRpin = MM.Info(pinno gp1)  'output pins, change as needed
Const kHz38 = MM.Info(pinno gp3)  'also change PWM channel to match (3 places)
SetPin IRpin, dout : Pin(IRpin) = 0 ' IR code output
SetPin kHz38, pwm                   ' IR carrier frequency
PWM 1,38000,,5

SetPin gp6,ir            ' IR receiver input, change as needed
IR dev, key , int

Sub int                  ' get IR codes
 Print dev,Bin$(dev,8), key,Bin$(key,8)
 Pause 2000
 NECsend IRpin,dev,key  ' call transmitter sub
End Sub

Do : Loop

End


Sub NECsend IRpin As integer, dev As integer, key As integer
 Print dev,Bin$(dev,8), key,Bin$(key,8)
 Local integer word, c(73), i

 word =  (dev<<16) + (key<<8) + ((255 Xor key )And 255) 'assemble 32 bits

 Pin(IRpin) = 0
 PWM 1,38000,,50

 Print "Data to convert " Bin$(word,32)

 Math set 1, c()
 c(0)=16 : c(1)=8    ' start pulse time units - 1 unit = 562µS

 For i = 2 To 66 Step 2
  c(i)= ((word>>(32-i/2)) And 1)*2 + 1 'decode 32 bit word to bit time units
 Next

 Print
 c(66)=1    'end pulse time units
 c(67)=72 : c(68)=16 :c(69)=4 :c(70)=1 :c(71)=172

 Math scale c(), 562, c() 'restore time values to uS
 Math V_PRINT c() 'print the bitstream

 Device bitstream IRpin, 67, c() 'send the data
 Pause 100
 Pin(IRpin) = 0
 PWM 1,38000,,0.1
End Sub


Edited 2024-02-11 07:01 by phil99