0
\$\begingroup\$

I'm programming a PIC16F84A microcontroller to automatically increment a number with a 1 second delay, and get it displayed on a 7 Segment Display. The 7 segment display is already set so there's no need to worry about it.

The following is the code I wrote:

COUNTERA EQU d'12'         ; delay counter1 points to register file 12
COUNTERB EQU d'13'         ; delay counter2 points to register file 13
COUNTERC EQU d'14'         ; delay counter2 points to register file 13

            ORG 0x00        ; program starts here
            BSF  STATUS, RP0; switching to Bank1
            CLRF TRISA      ; PORTA is output
            BCF  STATUS, RP0; switching to Bank0
            CLRF PORTA      ; clearing PORTA

TASK1       MOVLW D'6'
            MOVWF COUNTERC
            MOVLW D'24'
            MOVWF COUNTERB
            MOVLW D'167'
            MOVWF COUNTERA

COME_AGAIN  INCF  PORTA
            GOTO  LOOP
            GOTO  FINISH

LOOP        decfsz COUNTERA,1 ;the 1 second delay loop
            goto LOOP
            decfsz COUNTERB,1
            goto LOOP
            decfsz COUNTERC,1
            goto LOOP
            GOTO COME_AGAIN
FINISH  
            END            ; program ends here

When I run a simulation on Proteus Demo, it only increments once (goes from 1 to 2) and then it stays at 2. However, my goal is to keep it incrementing from 1 -> F, then restart it from zero.

I suspect that the code is off on the INCF PORTA line, but I don't know how to fix it.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You had to reinitialize your counter register after the delay loop. Time to use a debugger. \$\endgroup\$
    – Mike
    Mar 25 '20 at 13:53
  • 1
    \$\begingroup\$ Can you explain a little more clearly please? \$\endgroup\$
    – OmarAI
    Mar 25 '20 at 14:06
  • 1
    \$\begingroup\$ @Mike okay I got it! After zeroing the counters each time, I'm starting from 255 instead of 167, so that's why I have to reinitialize them. Thank you. \$\endgroup\$
    – OmarAI
    Mar 25 '20 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.