Examples | Shop
 
TV Remote Control with BX 24
 
This example application demonstrates how to interface a BX 24 microcontroller to a Total Robots Infra Red Control Module (IRCM) in order to receive data from button presses on a TV Remote Control.
Communication from the BX 24 to the IRCM is via I2C, so this has been implemented within the code, as the BX 24 does not have set commands for I2C. It is, however, very simple to implement.
When the project is up and running, you will be able to point your TV remote control at the IRCM and read the data on your PC’s Basic-X debug window. This example can then be taken further and be used on robotics projects such as an inexpensive way of remotely controlling your robot.
Connections are as follows:
In this example we have used the BX 24 development boards prototyping area to solder connectors for the IRCM and inserted pull up resistors on the SDA and SCL lines (as can be seen in the schematic). This is needed for successful I2C communication otherwise communication can be disrupted by noise.
Using the development board (from the development kit) also allows easy connection to your PC’s serial comms port so data can be printed to the debug window.

Download the code here.

 

'**************************************************************************
'**************************************************************************
'IRCM Communications with a TV remote control
'
'This example application demonstrates how to communicate via I2C from the BX24 ‘to the Total Robots IRCM (Infra Red Control Module). You can then use a remote ‘control to send data to the IRCM which is in turn read by the BX24 and displayed on the debug window.
'
'Created: 15/08/03 Compiler 2.1 Beta 1
'Written By: Total Robots Ltd
'Revision 1.0 TRBX24IRCM
'
'**************************************************************************
Const SCL as byte = 11 'Serial Clock Line on Pin 11
Const SDA as byte = 12 'Serial Data line on pin 12
Const IRCM_Write as byte = bx11000000 'This is the write address command
Const IRCM_Read as byte = bx11000001 'This is the Read address command
Dim Reg As byte 'This is a byte to select the register to read
Dim Readbyte(1 to 6) As byte 'Array to read data into
Dim Ack As byte 'Acknowledge byte
'********************************************************************
Public Sub Main()
Call Delay (1.0) '1 second delay
debug.print "IRCM & BX24 Example Application" 'Print to debug window
debug.print "Reading data from a TV remote control."'print to debug window
Call Delay (4.0) '4 second delay
Reg = bx00011100 'Register address. In this example Reg 28

Do 'Start of a Do.....Loop construct
Call Start() 'Call the start routine
Call OutByte() 'Call the outbyte routine
Call Read_Byte() 'Call the readbyte routine
Call StopByte() 'Call the stop byte routine
'Print the values to the PC debug window
debug.print "Read Register= "; CStr (Readbyte(1)); " Remote Control= "; CStr (Readbyte(2)); " Data 1= "; CStr (Readbyte(3)); " Data 2= "; CStr (Readbyte(4)); " Data 3= "; CStr (Readbyte(5)); " Data 4= "; CStr (Readbyte(6))
Call Delay (1.0) '1 second delay
Loop
End Sub
'********************************************************************
'This routine issues the start sequence for the I2C communication
'********************************************************************
Sub Start()

Call Putpin (SDA, bxOutputHigh) 'SDA put high
Call Putpin (SCL, bxOutputHigh) 'SCL put high
Call Putpin (SDA, bxOutputLow) 'SDA put low
Call Putpin (SCL, bxOutputLow) 'SCL put low
End Sub
'********************************************************************
'This routine sends the address and commands to the IRCM in order to read from
'the remote control registers.
'********************************************************************
Sub Outbyte()

Call ShiftOut(SDA, SCL, 8, IRCM_Write) 'Send out the write address
Ack = ShiftIn (SDA, SCL, 1) 'Clock in the ACK bit from the IRCM
Call Putpin (SCL, bxOutputLow) 'SCL put low

Call ShiftOut (SDA, SCL, 8, Reg) 'send register address
Ack = ShiftIn (SDA, SCL, 1) 'Clock in the ACK bit from the IRCM
Call Putpin (SCL, bxOutputLow) 'SCL put low

Call Start() 'Call the start routine again

Call ShiftOut(SDA, SCL, 8, IRCM_Read)
'Send out the address with read bit set
Ack = ShiftIn (SDA, SCL, 1) 'Clock in the ACK bit from the IRCM
Call Putpin (SCL, bxOutputLow) 'SCL put low

End Sub
'********************************************************************
'This routine reads the values of the registers from 28 to 33 from the IRCM
'and stores them in the Readbyte array.
'********************************************************************
Sub Read_Byte()

Call Putpin (SCL, bxOutputLow) 'SCL put low
Readbyte(1) = ShiftIn (SDA, SCL, 8) 'Read in the first byte (Reg 28)
Call ACK_Bit() 'Call the acknowledge routine

Readbyte(2) = ShiftIn (SDA, SCL, 8) 'Read in the second byte (Reg 29)
Call ACK_Bit() 'Call the acknowledge routine

Readbyte(3) = ShiftIn (SDA, SCL, 8) 'Read in the third byte (Reg 30)
Call ACK_Bit() 'Call the acknowledge routine

Readbyte(4) = ShiftIn (SDA, SCL, 8) 'Read in the fourth byte (Reg 31)
Call ACK_Bit() 'Call the acknowledge routine

Readbyte(5) = ShiftIn (SDA, SCL, 8) 'Read in the fifth byte (Reg 32)
Call ACK_Bit() 'Call the acknowledge routine

Readbyte(6) = ShiftIn (SDA, SCL, 8) 'Read in the sixth byte (Reg 33)
Call NACK_Bit() 'Call the acknowledge routine

End Sub
'********************************************************************
'This routine sends the acknowledge sequence from the BX to the IRCM
'to acknowledge receipt of the data.
'********************************************************************
Sub ACK_Bit()
Call Putpin (SCL, bxOutputLow) 'SCL put low
Call Putpin (SDA, bxOutputLow) 'SDA put low
Call Putpin (SCL, bxOutputHigh) 'SCL put high
Call Putpin (SCL, bxOutputLow) 'SCL put Low
End Sub
'********************************************************************
'This routine sends the Not-Acknowledge sequence from the BX to the IRCM
'to terminate data receipt.
'********************************************************************
Sub NACK_Bit()
Call Putpin (SCL, bxOutputLow) 'SCL put low
Call Putpin (SDA, bxOutputHigh) 'SDA put high
Call Putpin (SCL, bxOutputHigh) 'SCL put high
Call Putpin (SCL, bxOutputLow) 'SCL put Low
End Sub
'********************************************************************
'This routine sends the sequence to terminate I2C communications to the IRCM.
'********************************************************************
Sub StopByte()
Call Putpin (SDA, bxOutputLow) 'SDA put low
Call Putpin (SCL, bxOutputHigh) 'SCL put high
Call Putpin (SDA, bxOutputHigh) 'SDA put high
End Sub
'**************************************************************************
'**************************************************************************


Examples | Shop