Reputation: 13
Im creating an elevator system using a dragon12-plus2 board. So far everything works except for a specific branch out of range error. any help? thanks in advance
Input of the system - push button Output of the system - lcd and 7-segments
errors occur at lines 86, 88, 90, 143, 145, 147, 200, 202, 204
#include "C:\miniide\hcs12.inc"
org $2000
lcd_dat equ PORTK ; LCD data pins (PK5~PK2)
lcd_dir equ DDRK ; LCD data direction port
lcd_E equ $02 ; E signal pin
lcd_RS equ $01 ; RS signal pin
movb #$0, DDRH
movb #$FF, DDRB
movb #$FF, DDRP
lds #$2000 ; initialize stack pointer
F2T1 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$06, PTB ; display 1
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
floor1 ldab PTH
cmpb #%11111101
lbeq F1T2
cmpb #%11111011
lbeq F1T3
cmpb #%11110111
lbeq F1T4
bra floor1
F3T1 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$06, PTB ; display 1
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor1
F4T1 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$06, PTB ; display 1
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
jsr floor1
F1T2 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
floor2 ldab PTH
cmpb #%11111110
beq F2T1
cmpb #%11111011
beq F2T3
cmpb #%11110111
beq F2T4
bra floor2
F3T2 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor2
F4T2 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor2
F1T3 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
floor3 ldab PTH
cmpb #%11111110
beq F3T1
cmpb #%11111101
beq F3T2
cmpb #%11110111
beq F3T4
bra floor3
F2T3 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor3
F4T3 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #downward ; display a message (downward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor3
F1T4 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$5B, PTB ; display 2
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$66, PTB ; display 4
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
floor4 ldab PTH
cmpb #%11111110
beq F4T1
cmpb #%11111101
beq F4T2
cmpb #%11111011
beq F4T3
bra floor4
F2T4 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$4F, PTB ; display 3
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
movb #$66, PTB ; display 4
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
bra floor4
F3T4 ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCDjsr cmd2lcd ; "
ldx #upward ; display a message (upward)
jsr putsLCD
ldy #100
jsr delayby10ms
movb #$66, PTB ; display 4
movb #$FE, PTP ; using 7seg #1
ldy #100
jsr delayby10ms
jsr openLCD ; initialize the LCD
lbra floor4
upward dc.b "upward",0
downward dc.b "downward",0
#include "c:\miniide\delay.asm" ; delay routines
#include "c:\miniide\lcd.asm" ; LCD routines
end
i tried restructuring the code multiple ways, still the same branch error
Upvotes: 0
Views: 45
Reputation: 20057
You need to add structure to your assembler. Think in larger code blocks, isolate functions and procedures, clearly label entry points.
EntryXYZ: // a little bit of code
// more code
EntryYZW: // a lot of code
EntryZZZ: // a little bit of code
Between every small function you can add trampolines:
JumpPoint1: jmp Label
SmallCode: test ax,ax
bne JumpPoint1
// more code
jle skip0
jmp Label
skip: // more code
In long code one needs to use the jNOTcond skip; jmp Label; skip:
paradigm. In short code one can use the jCOND trampoline
paradigm.
Also one can place these jump points in the middle of long code as in:
bne skip:
jmp longJump
tramp1:
jmp longJumpA
tramp2:
jmp longJumpB
skip:
One more technique is to locate an earlier branch to the same target, as in
tramp_label_bne_002:
bne tramp_label_bne_001:
Code:
// max 126 bytes of code
bne tramp_label_bne002
Upvotes: 1