Sending RC5 and SONY IR codes
This application note was submitted by Ger
Langezaal.
Actually there are 2 notes. One for sending RC5 codes and one for sending
Sony.
Since BASCOM already has the GETRC5 statement, it is now easy to create an IR
remote control! Based on Ger's AN there will also be a build in SENDRC5
statement. Download botch source codes in .ZIP file
Ger is willing to asnwer some questions and of course it is also nice to send
him a 'thanks' email but before you start with questions, be sure that you have
a receiver that works ok.
You can build a simple receiver with the GETRC5 statement from BASCOM-AVR.
rc5 code
'-------------------------------------------------------------------------------
' Filename :
RC5_Tx1a.bas
' Purpose : RC5
Remote Control Transmitter
' Author : Ger
langezaal
' Controller : AT90S2313
' Compiler :
BASCOM-AVR Rev. 1.11a
'-------------------------------------------------------------------------------
'
' connections 3x4 Keypad:
'
' column 1 ------------------[470 Ohm]---> Pb.0
' column 2 | ------------[470 Ohm]--->
Pb.1
' column 3 | | ------[470 Ohm]---> Pb.2
' | | |
'
' row 1 1 2 3 ---[470 Ohm]---> Pb.4
' row 2 4 5 6 ---[470 Ohm]---> Pb.5
' row 3 7 8 9 ---[470 Ohm]---> Pb.6
' row 4 * 0 # ---[470 Ohm]---> Pb.7
'
' IR Led: +5V
<---[A Led K]---[220 Ohm]---> Pb.3
'
'-------------------------------------------------------------------------------
'
$regfile = "2313def.dat"
$crystal = 8000000
Dim Rc5_address As Byte
Dim Rc5_command As Byte
Dim Key As Byte
Dim Key_prev As Byte
Dim Rc5_bit_nr As Byte
Dim Toggle_bit As Boolean
' 36kHz carrier reload value
'Const T_oc1 = 55 'value for 4MHz
crystal
Const T_oc1 = 110 'value for 8MHz crystal
'Const T_oc1 = 138 'value for 10MHz
crystal
Const Carrier_on = &B01000000 'IR 36kHz
carrier on
Const Carrier_off = &B11000000 'IR 36kHz carrier
off
Config Kbd = Portb 'keyboard connected at Port b
Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1
Timer1 = 0
Compare1a = T_oc1 'Pb.3 = OC1 = IR carrier output 36 kHz
Declare Sub Logic_0
Declare Sub Logic_1
Tccr1a = Carrier_off
Toggle_bit = 0
'---[ set RC-5 System Address
]-------------------------------------------------
Rc5_address = 0 'TV = 0
'Rc5_address = 5 'VCR = 5
'Rc5_address = 20 'CD = 20
'---[ main program loop
]-------------------------------------------------------
Do
Key = Getkbd() 'get keyboard value
Waitms 1 'small delay
If Key <> 16 Then 'test if key is pressed else key = 16
If Key_prev <> Key Then Toggle_bit = Not
Toggle_bit 'set toggle bit
Rc5_command = Lookup(key , Rc5_commands) 'get RC-5 command
'---[ transmit Address and Command as 14 bit RC-5 code
]------------------------
Ddrb.3 = 1 'set OC1 (Pb.3) = IR carrier output
Logic_1 'first start bit
Logic_1 'second start bit
If Toggle_bit = 0 Then Logic_0 Else Logic_1 'toggle bit
For Rc5_bit_nr = 4 To 0 STEP -1 '5 bit address,
msb first
If Rc5_address.rc5_bit_nr = 0 Then Logic_0 Else Logic_1
Next
For Rc5_bit_nr = 5 To 0 STEP -1 '6 bit command,
msb first
If Rc5_command.rc5_bit_nr = 0 Then Logic_0 Else Logic_1
Next
Tccr1a = Carrier_off
Waitms 87 'frame gap delay
End If
Key_prev = Key 'save last key value
Loop
End
'-------------------------------------------------------------------------------
Sub Logic_0
Tccr1a = Carrier_on
Waitus 883
Tccr1a = Carrier_off
Waitus 884
End Sub
Sub Logic_1
Tccr1a = Carrier_off
Waitus 883
Tccr1a = Carrier_on
Waitus 884
End Sub
Rc5_commands:
Data 1 , 2 , 3 , 0 'column 4 not used (3x4 keypad)
Data 4 , 5 , 6 , 0
Data 7 , 8 , 9 , 0
Data 10 , 11 , 12 , 0
'---[ Keyboard layout example
]-------------------------------------------------
'
' key command key command key command
' 1 = 1 2 = 2 3 = 3
' 4 = 4 5 = 5 6 = 6
' 7 = 7 8 = 8 9 = 9
' * = 10 0 = 11 # = 12
'
'-------------------------------------------------------------------------------
'
' for more RC-5 Remote Control info:
' http://users.pandora.be/nenya/electronics/rc5/index.htm
' http://www.ustr.net/infrared/infrared1.shtml
'
'-------------------------------------------------------------------------------
sony code
'-------------------------------------------------------------------------------
' Filename :
Sony_RC_Tx1a.bas
' Purpose : IR
Remote Control Transmitter for SONY devices
' Author : Ger
langezaal
' Controller : AT90S2313
' Compiler :
BASCOM-AVR Rev. 1.11a
'-------------------------------------------------------------------------------
'
' connections 3x4 Keypad:
'
' column 1 ------------------[470 Ohm]---> Pb.0
' column 2 | ------------[470 Ohm]--->
Pb.1
' column 3 | | ------[470 Ohm]---> Pb.2
' | | |
'
' row 1 1 2 3 ---[470 Ohm]---> Pb.4
' row 2 4 5 6 ---[470 Ohm]---> Pb.5
' row 3 7 8 9 ---[470 Ohm]---> Pb.6
' row 4 * 0 # ---[470 Ohm]---> Pb.7
'
' IR Led: +5V
<---[A Led K]---[220 Ohm]---> Pb.3
'
'-------------------------------------------------------------------------------
$regfile = "2313def.dat"
$crystal = 8000000
Dim Key As Byte
Dim Ir_frame As Byte
Dim Ir_bit As Byte
Dim Ir_data As Word
'40 kHz carrier reload value
'Const T_oc1 = 49 'value for 4MHz
crystal
Const T_oc1 = 99 'value for 8MHz crystal
'Const T_oc1 = 124 'value for 10MHz
crystal
Const Carrier_on = &B01000000 'IR 40kHz
carrier on
Const Carrier_off = &B11000000 'IR 40kHz carrier
off
Const Ir_repeat = 3 'number code frames (at least 2)
Config Kbd = Portb 'keyboard connected at Port b
Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1
Timer1 = 0
Compare1a = T_oc1 'OC1 = IR carrier = 40 kHz
Tccr1a = Carrier_off
'---[ main program loop
]-------------------------------------------------------
Do
Key = Getkbd()
Waitms 1 'small delay
If Key <> 16 Then 'test if key is pressed else key=16
Ir_data = Lookup(key , Ir_code) 'lookup pressed key IR Remote Code
Ddrb.3 = 1 'set OC1 (Pb.3) = IR carrier output
'---[ convert and transmit Sony 12bit IR code
]---------------------------------
For Ir_frame = 1 To Ir_repeat 'number of code
frames
Tccr1a = Carrier_on
Waitus 2400 'start = 2.4mS
For Ir_bit = 11 Downto 0 '12 bit code, msb
first
Tccr1a = Carrier_off
Waitus 600 '0.6mS delay
Tccr1a = Carrier_on
Waitus 600 '0.6mS delay
If Ir_data.ir_bit = 1 Then Waitus 600 'if bit=1 then 1.2mS delay
Next
Tccr1a = Carrier_off
Waitms 25 'frame gap 25mS delay
Next
End If
Loop
'-------------------------------------------------------------------------------
End
'-------------------------------------------------------------------------------
Ir_code:
Data &H1D1% , &H9D1% , &H4D1% , &H0% 'column 4 not used (3x4 keypad)
Data &HCD1% , &H2D1% , &HB91% , &H0%
Data &H0D1% , &H8D1% , &HAD1% , &H0%
Data &HBD1% , &H7D1% , &HA91% , &H0%
'---[ Keyboard layout example for CD Player Remote Control
]--------------------
'
' key command key command key command
' 1 = stop 2 = pause 3 = play
' 4 =
<< 5 = >> 6 = continue
' 7 =
|<< 8 = >>| 9 = shuffle
' * = disc
- 0 = disc + # = power
'
'-------------------------------------------------------------------------------
'---[ SONY CD Infrared Remote Control codes (RM-DX55)
]-------------------------
'
' Hex
code Binary code
' msb lsb
' power =
&HA91 : 1010 1001 0001
' play =
&H4D1 : 0100 1101 0001
' stop =
&H1D1 : 0001 1101 0001
' pause =
&H9D1 : 1001 1101 0001
' continue =
&HB91 : 1011 1001 0001
' shuffle =
&HAD1 : 1010 1101 0001
' program =
&HF91 : 1111 1001 0001
' disc =
&H531 : 0101 0011 0001
' 1 =
&H011 : 0000 0001 0001
' 2 =
&H811 : 1000 0001 0001
' 3 =
&H411 : 0100 0001 0001
' 4 =
&HC11 : 1100 0001 0001
' 5 =
&H211 : 0010 0001 0001
' 6 =
&HA11 : 1010 0001 0001
' 7 =
&H611 : 0110 0001 0001
' 8 =
&HE11 : 1110 0001 0001
' 9 =
&H111 : 0001 0001 0001
' 0 =
&H051 : 0000 0101 0001
' >10 =
&HE51 : 1110 0101 0001
' enter =
&HD11 : 1101 0001 0001
' clear =
&HF11 : 1111 0001 0001
' repeate =
&H351 : 0011 0101 0001
' disc - =
&HBD1 : 1011 1101 0001
' disc + =
&H7D1 : 0111 1101 0001
' |<<
= &H0D1 : 0000 1101 0001
' >>|
= &H8D1 : 1000 1101 0001
' <<
= &HCD1 : 1100 1101 0001
' >>
= &H2D1 : 0010 1101 0001
'
'---[ SONY Cassette Infrared Remote Control codes
(RM-J901) ]-------------------
'Deck A:
' stop =
&H1C1 : 0001 1100 0001
' play > =
&H4C1 : 0100 1100 0001
' play < =
&HEC1 : 1110 1100 0001
' >>
= &H2C1 : 0010 1100 0001
' <<
= &HCC1 : 1100 1100 0001
' record =
&H6C1 : 0110 1100 0001
' pause =
&H9C1 : 1001 1100 0001
'Deck B:
' stop =
&H18E : 0001 1000 1110
' play > =
&H58E : 0101 1000 1110
' play < =
&H04E : 0000 0100 1110
' >>
= &H38E : 0011 1000 1110
' <<
= &HD8E : 1101 1000 1110
' record =
&H78E : 0111 1000 1110
' pause =
&H98E : 1001 1000 1110
'
'---[ SONY TV Infrared Remote Control codes (RM-694)
]--------------------------
'
' program + =
&H090 : 0000 1001 0000
' program - =
&H890 : 1000 1001 0000
' volume + =
&H490 : 0100 1001 0000
' volume - =
&HC90 : 1100 1001 0000
' power =
&HA90 : 1010 1001 0000
' sound on/off = &H290 : 0010 1001 0000
' 1 =
&H010 : 0000 0001 0000
' 2 =
&H810 : 1000 0001 0000
' 3 =
&H410 : 0100 0001 0000
' 4 =
&HC10 : 1100 0001 0000
' 5 =
&H210 : 0010 0001 0000
' 6 =
&HA10 : 1010 0001 0000
' 7 =
&H610 : 0110 0001 0000
' 8 =
&HE10 : 1110 0001 0000
' 9 =
&H110 : 0001 0001 0000
' 0 =
&H910 : 1001 0001 0000
' -/-- =
&HB90 : 1011 1001 0000
'
'-------------------------------------------------------------------------------
'
' for more SONY Remote Control info:
'
' http://www.fet.uni-hannover.de/purnhage/
'
'-------------------------------------------------------------------------------
|