November 22, 2024, 06:57:58 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Very Basic RC-4 program

Started by shupe1, August 29, 2011, 08:53:31 AM

Previous topic - Next topic

shupe1

Hi,

I have a 'new' style RC-4 board hooked up to a Prop-1 controller, and I am trying to just play with it and see what I can do.  I'm having a hard time finding a basic 'test' program to use.  I don't quite understand all the specifics of what I need to define in my program before I can start playing.... ie - all the constants and variables.

The 'test' program that is linked on the EFX-TEK product page seems to be for a Prop-2.  Would someone mind sharing a basic program with me?  Basically I am just looking to see how to turn on and off a relay.  I will then incorporate that code into a more detailed program on my Prop-1.

Thanks everyone!

Travis

livinlowe


' =========================================================================
'
'   File....... RC-4_Test.BS1
'   Purpose.... RC-4 Features Test
'   Author..... Team EFX -- Copyright (C) 2005-2008 EFX-TEK
'   E-mail..... teamefx@efx-tek.com
'   Started....
'   Updated.... 04 NOV 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Demonstration program for the RC-4 Relay Control Board.  All commands are
' sent to the RC-4 through a serial link at 2400 baud (OT2400 baudmode).
' The use of the open baudmode allows boards to be daisy-chained for up to
' 16 relays from one I/O pin.
'
' Command syntax: "!RC4", address, cmd {, data}
' -- where 'address' is %00 to %11
' -- 'cmd' is a single character
' -- optional 'data' is a byte
'
' Valid commands:
'
'   "!RC4", address, "V"
'     -- requests version string from RC-4
'     -- should be followed by SERIN to receive three-byte string
'
'   "!RC4", address, "S", newStatus
'     -- sets outputs to lower nib (BIT3..BIT0) of 'newStatus'
'     -- a 1 bit = relay on, a 0 bit = relay off
'
'   "!RC4", address, "R", relay, newState
'     -- sets relay (1 - 4, in 'relay') to BIT0 of 'newState',
'     -- 1 = relay on, 0 = relay off
'     -- if 'relay' is out of range, command is ignored
'
'   "!RC4", address, "X"
'     -- sets all relays to off
'     -- functionally equivalent to: "!RC4", addr, "S", %0000
'
'   "!RC4", address, "G"
'     -- retrieves current relay status
'     -- should be followed by SERIN to receive one-byte status
'
'
' Note: ULN2803 interferes with serial transmission to RC-4, remove and
'       replace with ULN2003 (7 channels), leaving P7 contacts open.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Baud            = OT2400
SYMBOL  Addr            = %00                          ' %00 - %11

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  id0             = B0                            ' version string
SYMBOL  id1             = B1
SYMBOL  id2             = B2


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
  DEBUG CLS


' -----[ Program Code ]----------------------------------------------------

Main:
  SEROUT Sio, Baud, ("!RC4", Addr, "V")                 ' get version
  SERIN  Sio, Baud, id0, id1, id2
  DEBUG "RC-4 Version ", #@id0, #@id1, #@id2, CR

Test_Set:
  FOR id0 = %0000 TO %1111
    SEROUT Sio, Baud, ("!RC4", Addr, "S", id0)          ' set outputs
    GOSUB Show_Status
    PAUSE 500
  NEXT

Test_Reset:
  SEROUT Sio, Baud, ("!RC4", Addr, "X")                 ' all off
  GOSUB Show_Status
  PAUSE 500

Test_RelayCtrl:
  FOR id0 = 1 TO 4
    SEROUT Sio, Baud, ("!RC4", Addr, "R", id0, IsOn)
    GOSUB Show_Status
    PAUSE 500
  NEXT
  FOR id0 = 1 TO 4
    SEROUT Sio, Baud, ("!RC4", Addr, "R", id0, IsOff)
    GOSUB Show_Status
    PAUSE 500
  NEXT

Test_Ignore:
  ' send invalid relay number
  SEROUT Sio, Baud, ("!RC4", Addr, "R", 5, IsOn)
  GOSUB Show_Status                                     ' no change

  END


' -----[ Subroutines ]-----------------------------------------------------

Show_Status:
  SEROUT Sio, Baud, ("!RC4", Addr, "G")                 ' get status
  SERIN  Sio, Baud, id1
  DEBUG CR, "Status = ", #%id1
  RETURN


This program is for a Prop-1, which is on the product page.
Hope this helps
Shawn
Scaring someone with a prop you built -- priceless!