Shop OBEX P1 Docs P2 Docs Learn Events
Help for a newbie, simple edge detection program — Parallax Forums

Help for a newbie, simple edge detection program

MCassidyMCassidy Posts: 7
edited 2009-01-18 16:55 in General Discussion
Hi,
I'm writing a very simple program that work fine on SXSim, but does not work when I download it to the SX Tech board.
The program is very simple:
Wait for an edge on rb.0 or rb.1
Sound a buzzer on rb.2
Light an LED on rb.3 or rb.4 corresponding to the detected edge on rb.0 or rb.1
Wait for a reset
I think it's all wired correctly, because if I connect Vdd to rb.3 or rb.4, the LED lights.

Any ideas?· Thanks!

;Code for scout game
;the code detects an edge on rb.0 or rb.1, then sounds a buzzer on rb.2
;and a corresponding LED on rb.3 or rb.4
;the program then waits in this state until reset
;LEDs,buzzer connected to Vss with resistors
;
LIST Q = 37
DEVICE· SX28L, TURBO, STACKX, OSCHS2
IRC_CAL IRC_FAST
FREQ·4_000_000
org $200
; Clear all data memory
· clr······ fsr
ClearData
· sb····· fsr.4
··· setb· fsr.3
· clr···· ind
· ijnz··· fsr, ClearData
RESET·· Main

WKPND_B_W· equ $09 ; mode to swap pending bit into w
WKPED_B· equ $0a ;mode for edge detection
WKPEN_B· equ $0b ;mode to enable edge detection
PLP_B····· equ $0e ;mode to activate pull-up resistors
TRIS_B···· equ $0f ;mode to set direction

org $000 ;ISR routine, detect edge then jump to appropriate section
mode·· WKPND_B_W
clr··· w
mov··· !rb, w
and··· w, #%00000011
jmp pc+w· ;-detect which lane caused interrupt
nop
jmp LaneA
jmp LaneB
LaneA
· setb·· rb.2 ;sound buzzer
· setb·· rb.3 ;light LaneA LED
· jmp Quit ;wait for reset
LaneB
· setb·· rb.2 ;sound buzzer
· setb·· rb.4 ;light LanB LED
Quit
·jmp Quit ;wait for· reset

org $100
Main
· mode·· TRIS_B
· mov··· !rb, #%11100011 ;Set Direction
· mode·· PLP_B
· mov··· !rb, #%11111111 ;Played with this to no avail
· mode·· WKPED_B
· mov··· !rb, #%11111100 ;set edge detection
· mode·· WKPEN_B
· mov··· !rb, #%11111100; Interrupt enable
· clrb·· rb.2 ;turn buzzer off
· clrb·· rb.3 ; turn LaneA LED off
· clrb·· rb.4 ;turn LaneB LED off
Loop
· jmp··· Loop ;wait for interrupt

Comments

  • ZootZoot Posts: 2,227
    edited 2009-01-18 16:55
    Do you have to do this in an interrupt? You'll probably check faster in the mainline, and there is nothing in particular that *requires* an interrupt here. E.g.



    
    ioByte EQU $30
    
    Reset:
      ' initi pins here, etc
     
    
    Main:
    
    
    Check_Incoming:
       BANK ioByte
       MOV ioByte, RB ' capture all pins at once for best accuracy
    
    check_rb0:
       JNB ioByte.0, @check_rb1
       setb   rb.2 ;sound buzzer
       setb   rb.3 ;light LaneA LED
       JMP @ Wait_For_Restart
    
    check_rb1:
      JNB ioByte.1, @Main  
      setb   rb.2 ;sound buzzer
      setb   rb.4 ;light LanB LED
      JMP @ Wait_For_Restart
    
    
    Wait_For_Restart:
       ' say you have an active low button on RA.0; either button push or reset will start you over
       JB RA.0, @Wait_For_Restart
       JMP @Main
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.