Shop OBEX P1 Docs P2 Docs Learn Events
Nubie question — Parallax Forums

Nubie question

LanceRLanceR Posts: 8
edited 2008-04-10 19:57 in General Discussion
I have a remote device that outputs 5v as long as the remote button is held.· There's 4 buttons.

For the moment, I'm simply trying to trip an led on for each button while its pressed to know its being pressed.· I split off the output of the buttons to the SX to go to another set of LED's to know the remote is actually firing ok.· I only really programmed for one button just to see what was going on.

The LED's from direct, fire great.· The SX, however, doesn't seem to fire them properly.·· Script as follow.


Input/Suggestions welcome.





' =========================================================================
'
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
ID············· "KEYPAD"
'
' IO Pins
'
KeyA··········· VAR···· RC.0··················· ' Remote receiver A
KeyB··········· VAR···· RC.1··················· ' Remote receiver B
KeyC··········· VAR···· RC.2··················· ' Remote receiver C
KeyD··········· VAR···· RC.3··················· ' Remote receiver D
PLP_Keys······· VAR···· PLP_C
LED9··VAR ·RC.7
LED8··VAR ·RC.6

'
' Constants
'
Yes············ CON···· 0······················ ' active low input
No············· CON···· 1
'
' Variables
'
theKey········· VAR···· Byte··················· ' from keypad, 0 - 16
tmpB1·········· VAR···· Byte··················· ' subroutine work vars
tmpB2·········· VAR···· Byte
tmpW1·········· VAR···· Word
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
GET_KEY········ SUB···· 0······················ ' get key from pad
DELAY·········· SUB···· 1, 2··················· ' delay in milliseconds
'
' Program Code
'
Start:
INPUT RC = %00001111
LVL_C = %00001111
ST_C = %00001111
'PLP_C = %00001111
OUTPUT LED9
OUTPUT LED8
LOW LED9
LOW LED8
Main:
· theKey = GET_KEY····························· ' get a key
· IF theKey > 0 THEN·················· ' was a key pressed?
··· HIGH LED9··
··· DELAY 100
··· LOW LED9··
· ELSE
··· HIGH LED8
··· DELAY 100
··· LOW LED8
· ENDIF
· GOTO Main
'
' Subroutine Code
'

'
' Use: aByte = GET_KEY
' -- scans keyboard and places key value into 'aByte'
GET_KEY:
· tmpB1 = 0···································· ' reset value
· KeyA = 1····································· ' activate·Remote
· KeyB = 1····································· ' activate Remote
· KeyC = 1····································· ' activate Remote
· KeyD = 1····································· ' activate Remote
· PLP_Keys = %00001111·························· ' pull-up input pins
·
· IF KeyA = Yes THEN
·TmpB1 = 1
· ENDIF
· IF KeyB = Yes THEN
·TmpB1 = 2
· ENDIF
· IF KeyC = Yes THEN
· ·TmpB1 = 3
· ENDIF
· IF KeyD = Yes THEN
· ·TmpB1 = 4
· ENDIF

·RETURN tmpB1
'
' Use: DELAY ms
' -- 'ms' is delay in milliseconds, 1 - 65535
DELAY:
· IF __PARAMCNT = 1 THEN
··· tmpW1 = __PARAM1··························· ' save byte value
· ELSE
··· tmpW1 = __WPARAM12························· ' save word value
· ENDIF
· PAUSE tmpW1
· RETURN
' =========================================================================
' User Data
' =========================================================================

·

Comments

  • BeanBean Posts: 8,129
    edited 2008-04-10 11:22
    Lance,
    · I would suggest using PIN instead of VAR when defining the SX pin aliases.
    · Try something like this:
    ' ======================================================================
    '
    '
    ' ======================================================================
     
    ' ----------------------------------------------------------------------
    ' Program Description
    ' ----------------------------------------------------------------------
     
    ' ----------------------------------------------------------------------
    ' Device Settings
    ' -----------------------------------------------------------------------
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
    ID "KEYPAD"
     
    ' ----------------------------------------------------------------------
    ' IO Pins
    ' ----------------------------------------------------------------------
    KeyA  PIN RC.0 INPUT SCHMITT PULLUP       ' Remote receiver A
    KeyB  PIN RC.1 INPUT SCHMITT PULLUP       ' Remote receiver B
    KeyC  PIN RC.2 INPUT SCHMITT PULLUP       ' Remote receiver C
    KeyD  PIN RC.3 INPUT SCHMITT PULLUP       ' Remote receiver D
    LED9  PIN RC.7 OUTPUT
    LED8  PIN RC.6 OUTPUT
    
    ' ----------------------------------------------------------------------
    ' Constants
    ' ----------------------------------------------------------------------
    Yes             CON     0                       ' active low input
    No              CON     1
     
    ' ----------------------------------------------------------------------
    ' Variables
    ' ----------------------------------------------------------------------
    theKey          VAR     Byte                    ' from keypad, 0 - 16
    tmpB1           VAR     Byte                    ' subroutine work vars
    tmpW1           VAR     Word
     
    ' ======================================================================
      PROGRAM Start
    ' ======================================================================
     
    ' ----------------------------------------------------------------------
    ' Subroutine Declarations
    ' ----------------------------------------------------------------------
    GET_KEY         SUB     0                       ' get key from pad
    DELAY           SUB     1, 2                    ' delay in milliseconds
     
    ' ----------------------------------------------------------------------
    ' Program Code
    ' ----------------------------------------------------------------------
    Start:
    LOW LED9
    LOW LED8
    Main:
      theKey = GET_KEY                              ' get a key
      IF theKey > 0 THEN                   ' was a key pressed?
        HIGH LED9   
        DELAY 100
        LOW LED9   
      ELSE
        HIGH LED8
        DELAY 100
        LOW LED8
      ENDIF
      GOTO Main
     
    ' ----------------------------------------------------------------------
    ' Subroutine Code
    ' ----------------------------------------------------------------------
    
    '
    ' Use: aByte = GET_KEY
    ' -- scans keyboard and places key value into 'aByte'
    GET_KEY:
      tmpB1 = 0                                     ' reset value
      IF KeyA = Yes THEN 
        TmpB1 = 1
      ENDIF
      IF KeyB = Yes THEN 
        TmpB1 = 2
      ENDIF
      IF KeyC = Yes THEN 
        TmpB1 = 3
      ENDIF
      IF KeyD = Yes THEN 
        TmpB1 = 4
      ENDIF
     
     RETURN tmpB1
     
    ' ---------------------------------------------------------------------
    ' Use: DELAY ms
    ' -- 'ms' is delay in milliseconds, 1 - 65535
    DELAY:
      IF __PARAMCNT = 1 THEN
        tmpW1 = __PARAM1                            ' save byte value
      ELSE
        tmpW1 = __WPARAM12                          ' save word value
      ENDIF
      PAUSE tmpW1
      RETURN
     
    ' ======================================================================
    ' User Data
    ' ======================================================================
    
    
    

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • LanceRLanceR Posts: 8
    edited 2008-04-10 19:45
    Thanks Bean!

    I'll give that a whirl!

    ·
  • LanceRLanceR Posts: 8
    edited 2008-04-10 19:57
    A question.

    What I'm doing is (I think) pretty simple.

    Two things:

    1) Manage the buttons from the remote to do things, which the original question was.

    2)·Having serial data at 4800 baud come in at TTL (GPS) and then passed right back out on another pin at CMOS level. No manipulation of the data.·· I may, down the road, grab the data to show on a display, but priority at the moment is to essentially use the SX instead of a Max222 / Level converter, etc.

    I know there will be a miliseconds of delay from the GPS in to back out.· But that's livable.

    Is that something feasable and anything that you can point me to assist?

    Lance
Sign In or Register to comment.