IR Remote Control programs for the NEC Protocol and Variants.


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3344
Posted: 03:55am 10 Sep 2024      

By overwhelming popular demand ;-)

Now added JVC 16 bit protocol as Variant 5 to the NECsend Sub.

The NEC_Rx program in the previous post has been edited to include this.
' "NECsend with JVC16 & Samsung32 variants.bas"
'Dim Integer IRpin = MM.Info(pinno GP1) 'pin 2 for PicoMite
Dim Integer IRpin = 23 '= PA0) 'for ArmMiteF4
Dim Integer dev, key, V 'for standard NEC V = 0, or omit
'for Samsung32, LSB first -  V = 1
'for 8 bit NEC Dev code - V = 2
'for 16 bit, LSB first NEC Dev code - V = 3
'for 8 bit, LSB first NEC Dev code - V = 4
'for JVC16  LSB first - V = 5

'Alternatively those variants can instead be denoted by adding them to Dev above bit 16
'eg. for S32 (V=1) Device 5 Dev = &H10005 = 65541
Do
'Your program here.
 Input "Enter Device, Key, Variant (NEC=0, S32=1) codes "; dev, key, V
 NECsend IRpin, dev, key, V
Loop

Sub NECsend IRpin As integer, Dev As integer, Key As integer, V As integer
Local Integer word, d(1390), m, n = 1
Local Float T
Pin(IRpin) = 0
Math set 14, d() 'fill array. 13=1000/(38*2) uS - duration of a half cycle @ 38kHz

If V = 0 Then V = (Dev >> 16) ' if V missing or 0 then look for V in Dev above bit 16
Dev = Dev AND &Hffff

If V = 1 Then
  dev = ((Dev AND 255) * &H0202020202 AND &H010884422010) MOD 1023 'ensure 8 bits only &
  key = ((Key AND 255) * &H0202020202 AND &H010884422010) MOD 1023 ' reverse bit order
  word = (dev<<24) + (dev<<16) + (key<<8) + 255-key 'assemble 32 bits
  BitBang bitstream IRpin, 330, d() 'send 4.5ms start 38kHz
 Else

  If (V=2) OR (V=4) Then dev = (Dev << 8) + 255-Dev  'convert 8 bit address to 16 if required
  If (V=3) OR (V=4) Then
    key = ((Key AND 255) * &H0202020202 AND &H010884422010) MOD 1023 ' reverse Key bit order, 8 bit
    dev16 = (((dev AND 255) * &H0202020202 AND &H010884422010) MOD 1023) << 8 ' reverse Dev bit order, low byte
    dev = dev16 + ((dev >> 8) * &H0202020202 AND &H010884422010) MOD 1023  'now reverse high byte & swap bytes
  EndIf
  word = (dev<<16) + (key<<8) + 255-key ':Print Bin$(word,32) 'assemble 32 bits '16 bit address only

  If V=5 Then
    dev = ((dev AND 255) * &H0202020202 AND &H010884422010) MOD 1023 ' reverse Key bit order, 8 bit
    key = ((Key AND 255) * &H0202020202 AND &H010884422010) MOD 1023 ' reverse Key bit order, 8 bit
    word = (key + (dev<<8))<<16
  EndIf

  BitBang bitstream IRpin, 620, d() 'send 9ms start 38kHz

EndIf

T = Timer' :Print t
For m = 42 To 1386 Step 42  'load data after start sequence, step 42 = 21 cycle IR pulse
 d(m) = (((word>>(32-n)) AND 1)*2 + 1) * 560  'convert bits to duration (short = 0, long = 1)
 Inc n ':Print d(m); 'step to next data bit
Next

Do : Loop Until Timer > T+4.3 ':Print Timer-T 'less than 4.5 due processing time, adjust for CPU speed

If V<>5 Then
  BitBang bitstream IRpin, 1386, d() 'send the data
 Else
  BitBang bitstream IRpin, 698, d() 'send V5 JVC data
  Pause 33
  BitBang bitstream IRpin, 698, d() 'repeat V5 JVC data
EndIf
Pin(IRpin) = 0
End Sub
End


Edit
Edited the code above to send the JVC 16 bits twice.
I think some JVC devices may require it.
Edited 2024-09-10 15:49 by phil99