Help for a newbie, simple edge detection program
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php