2
\$\begingroup\$

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: the 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 instructino).

I don't know what I am doing wrong. Any ideas?

; 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 
\$\endgroup\$
4
  • \$\begingroup\$ Instead of using numbers for registers (btfsc 3,2) I'd recommend you using the register names (btfsc STATUS, Z) for readability. \$\endgroup\$ Commented May 25, 2013 at 8:24
  • \$\begingroup\$ And use banksel for changing banks, instead of fiddling with the status bits. \$\endgroup\$ Commented May 25, 2013 at 8:51
  • \$\begingroup\$ Have to fiddle part of the assignment learning etc. Thanks for the 3 and 2 thing I have status and Z setup in the larger file but it wasn't working the above was thrown together from many files \$\endgroup\$ Commented May 25, 2013 at 9:04
  • \$\begingroup\$ There is a lot more that could be said about your code, much of which you won't like, but since you've already accepted a answer its pointless anyway. \$\endgroup\$ Commented May 25, 2013 at 15:18

1 Answer 1

2
\$\begingroup\$

You don't initialize the point register. That means it can hold any value when you start looping the nextdigit loop! Try adding a clrf point under the start label.

For debugging: in MPLAB -> View -> File Registers, you can see the value of point during runtime.

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.