MPLAB assembly issue code jumps
I am having some issues with what I think to be good code, This is for a uni assignment but this is not the code I'm submitting this is a test file to understand how it all works some of this code was given in the assignment I.E. snum & binary sections.
I need to get each number in snum in turn and display the equivalent binary number on a 7 segment for a few seconds it runs in the debugger until 'call binary' then it jumps back to start after that instruction.
I don't know what I am doing wrong. any pointers?
; Directive sets processor type .............................
list p=16F84A
#include "P16F84A.INC"
; Set configuration fuses ...................................
__CONFIG _CP_OFF & _WDT_OFF &_PWRTE_ON & _RC_OSC
; Code protection off, watchdog timer off, power up timer on, RC Clock
errorlevel -302 ;No warnings, register not in Bank 0
PCL EQU 02 ; Program Counter Low
PORTB EQU 06 ; Port B Data Register
TRISB EQU 86 ; Port B Data direction register
STATUS EQU 03 ; Status register
RP0 EQU 05 ; Bank select bit
timer EQU 0C ; GPR1 used as delay counter
point EQU 0D ; GPR2 used as table pointer
org 000
goto start
snum addwf PCL,F
dt "0001035020" ;Substitute your student number
;(10 ASCII digits)
; Pattern table for seven segment display on Port B ..
binary addwf PCL,F
retlw b'00111111' ;Set display to 0
retlw b'00000110' ;Set display to 1
retlw b'01011011' ;Set display to 2
retlw b'01001111' ;Set display to 3
retlw b'01100110' ;Set display to 4
retlw b'01101101' ;Set display to 5
retlw b'01111111' ;Set display to 6
retlw b'00000111' ;Set display to 7
retlw b'01111111' ;Set display to 8
retlw b'01101111' ;Set display to 9
; Initialise Port B (Port A defaults to inputs)........
start bcf STATUS,RP0 ;Bank select 0
clrf PORTB ;Clear Port B data latches
bsf STATUS,RP0 ;Bank select 1
movlw 0x00 ;
movwf TRISB ;Set port B lines to output
bcf STATUS,RP0 ;Bank select 0
; MAIN LOOP
nextdigit movlw d'10'
subwf point,W
btfsc 3,2
goto nextdigit
movf point,W
call snum
call binary
movwf PORTB
NOP
NOP
incf point
goto nextdigit
end
I am having some issues with what I think to be good code, This is for a uni assignment but this is not the code I'm submitting this is a test file to understand how it all works some of this code was given in the assignment I.E. snum & binary sections.
I need to get each number in snum in turn and display the equivalent binary number on a 7 segment for a few seconds it runs in the debugger until 'call binary' then it jumps back to start after that instruction.
I don't know what I am doing wrong. any pointers?
; Directive sets processor type .............................
list p=16F84A
#include "P16F84A.INC"
; Set configuration fuses ...................................
__CONFIG _CP_OFF & _WDT_OFF &_PWRTE_ON & _RC_OSC
; Code protection off, watchdog timer off, power up timer on, RC Clock
errorlevel -302 ;No warnings, register not in Bank 0
PCL EQU 02 ; Program Counter Low
PORTB EQU 06 ; Port B Data Register
TRISB EQU 86 ; Port B Data direction register
STATUS EQU 03 ; Status register
RP0 EQU 05 ; Bank select bit
timer EQU 0C ; GPR1 used as delay counter
point EQU 0D ; GPR2 used as table pointer
org 000
goto start
snum addwf PCL,F
dt "0001035020" ;Substitute your student number
;(10 ASCII digits)
; Pattern table for seven segment display on Port B ..
binary addwf PCL,F
retlw b'00111111' ;Set display to 0
retlw b'00000110' ;Set display to 1
retlw b'01011011' ;Set display to 2
retlw b'01001111' ;Set display to 3
retlw b'01100110' ;Set display to 4
retlw b'01101101' ;Set display to 5
retlw b'01111111' ;Set display to 6
retlw b'00000111' ;Set display to 7
retlw b'01111111' ;Set display to 8
retlw b'01101111' ;Set display to 9
; Initialise Port B (Port A defaults to inputs)........
start bcf STATUS,RP0 ;Bank select 0
clrf PORTB ;Clear Port B data latches
bsf STATUS,RP0 ;Bank select 1
movlw 0x00 ;
movwf TRISB ;Set port B lines to output
bcf STATUS,RP0 ;Bank select 0
; MAIN LOOP
nextdigit movlw d'10'
subwf point,W
btfsc 3,2
goto nextdigit
movf point,W
call snum
call binary
movwf PORTB
NOP
NOP
incf point
goto nextdigit
end
No comments:
Post a Comment