Shop OBEX P1 Docs P2 Docs Learn Events
Newbie SX/B timer question — Parallax Forums

Newbie SX/B timer question

edlikestoboogieedlikestoboogie Posts: 71
edited 2006-11-26 04:35 in General Discussion
Hi guys.. I just finished writing my first SX/B program on a SX28
and of course..I have problems..

The program is suppose to be a simple timer with an ON time and an OFF time to control an LED on RA.0
2 - eight position rotary switches would be used for input

one 8 position, 1 pole rotary switch would be connected to RB.0 through RB.7 and VSS for the ON time
AND
one 8 position, 1 pole rotary switch would be connected to RC.0 through RC.7 and VSS for the OFF time


When I debug the program.. I put the rotary switch on at RB.0 and RC.0..
The program runs as if RB.2 is set... which it isn't... its strange

Anybody understand what's wrong.. just by checking out my app.. did I forget something?

Here is the simple BASIC program:


'
' Program Description
'
'
' Demonstrates the use of the SX comparator and controlling RB.0 for
' external circuitry.

'
' Device Settings
'

DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000

'
' IO Pins
'

LED VAR RA.0

SWITCHA0 VAR RB.0
SWITCHA1 VAR RB.1
SWITCHA2 VAR RB.2
SWITCHA3 VAR RB.3
SWITCHA4 VAR RB.4
SWITCHA5 VAR RB.5
SWITCHA6 VAR RB.6
SWITCHA7 VAR RB.7

SWITCHB0 VAR RC.0
SWITCHB1 VAR RC.1
SWITCHB2 VAR RC.2
SWITCHB3 VAR RC.3
SWITCHB4 VAR RC.4
SWITCHB5 VAR RC.5
SWITCHB6 VAR RC.6
SWITCHB7 VAR RC.7

'
' Variables
'
TEMP VAR byte

' =========================================================================
PROGRAM Start
' =========================================================================

WAITON SUB 0
WAITOFF SUB 0
WAITMIN SUB 1

'
' Program Code
'

Start:

'Setup inputs and outputs
TRIS_A = %1110 ' RB.0 is output

'setup inputs for rotary switch
TRIS_B = %11111111
TRIS_C = %11111111

'setup pull up resistors
PLP_A = %0001
PLP_B = %00000000
PLP_C = %00000000

Main:

'turn light on
LED = 0
WAITON

'turn LED off
LED = 1
WAITOFF

GOTO Main

WAITON:

'check input
IF SWITCHA0 = 1 THEN
PAUSE 1000 '10000
ENDIF
IF SWITCHA1 = 1 THEN
PAUSE 2000 '20000
ENDIF
IF SWITCHA2 = 1 THEN
PAUSE 30000
ENDIF
IF SWITCHA3 = 1 THEN
PAUSE 45000
ENDIF
IF SWITCHA4 = 1 THEN
PAUSE 60000
ENDIF
IF SWITCHA5 = 1 THEN
WAITMIN 4
ENDIF
IF SWITCHA6 = 1 THEN
WAITMIN 10
ENDIF
IF SWITCHA7 = 1 THEN
WAITMIN 30
ENDIF

RETURN

'off time
WAITOFF:

'check input
IF SWITCHB0 = 1 THEN
PAUSE 3000 '15000
ELSEIF SWITCHB1 = 1 THEN
PAUSE 5000 '30000
ELSEIF SWITCHB2 = 1 THEN
PAUSE 60000
ELSEIF SWITCHB3 = 1 THEN
WAITMIN 4
ELSEIF SWITCHB4 = 1 THEN
WAITMIN 10
ELSEIF SWITCHB5 = 1 THEN
WAITMIN 15
ELSEIF SWITCHB6 = 1 THEN
WAITMIN 30
ELSEIF SWITCHB7 = 1 THEN
WAITMIN 60
ENDIF

RETURN


'this sub waits x minutes
WAITMIN:

'Wait 60 secs for every minute
FOR TEMP = 0 TO __PARAM1
PAUSE 60000
NEXT

RETURN

Comments

  • BeanBean Posts: 8,129
    edited 2006-11-26 04:35
    Your switches will be equal to zero not one when they are active.
    So all your conditions should say "IF SWITCHxx = 0 THEN"

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
Sign In or Register to comment.