better way


Closed Thread
Results 1 to 9 of 9

Thread: better way

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    I haven't tested it, and it can surely be done more elegantly, but this should be a little closer to what you are attempting....I did not check to see if you are initializing the registers correctly.

    SYMBOL HORN = GPIO.0 'FAULT HORN
    SYMBOL CT = GPIO.2 'CT PIN 5 (TRIPS LOW)
    SYMBOL LED = GPIO.5 'LED PIN 2

    A VAR WORD
    EVENT VAR BYTE

    HORN =0
    LED =0
    EVENT =0


    MONTIOR:
    IF CT = 0 Then FAULT
    GoTo MONTIOR

    FAULT:
    LED = 1
    Pause 5000
    LED = 0
    CHECK:
    For A = 0 TO 60000
    Pause 1

    IF CT = 0
    GOSUB FAULT_AGAIN
    ENDIF

    Next A

    EVENT = 0
    GOTO MONITOR

    FAULT_AGAIN:
    EVENT = EVENT + 1
    IF EVENT = 2 THEN THR

    SEC:
    LED = 1
    Pause 5000
    LED = 0
    RETURN

    THR:
    HORN = 1
    Pause 5000
    HORN = 0

    EVENT = 0

    GoTo MONTIOR
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Although I haven't tried it, the following code should work.
    It uses no pauses whatsoever.


    ' Set up timer1 for /8 prescaler

    T1CON = %00110001

    TOP:
    IF PIR1.0 = 1 THEN
    PIR1.0 = 0
    TMR1H = $D
    TMR1L = $CF
    Hcounter = Hcounter + 1
    IF Hcounter.0 = 0
    GOSUB DOTHEWORK
    ENDIF
    ENDIF

    If Button1 = 0 THEN SecCounter = 60
    IF Button2 = 0 THEN BTN2 = 1
    IF Button3 = 0 THEN BTN3 = 1

    GOTO TOP


    DOTHEWORK: ' Gets here exactly once per second


    IF BTN2 = 1 AND SecCounter > 0 THEN
    LEDFLAG = 1
    ENDIF
    IF BTN3 = 1 AND BTN2 = 1 AND SecCounter > 0 THEN
    HORN = 1
    ENDIF
    IF LEDFLAG = 1 THEN
    TOGGLE LED
    ENDIF
    IF SecCounter > 0
    SecCounter = SecCounter -1
    ENDIF


    Return

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts