# Programming a PIC16F84A Microcontoller in assembly with MPLAB increment problem

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

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.

• You had to reinitialize your counter register after the delay loop. Time to use a debugger.
– Mike
Mar 25 '20 at 13:53
• Can you explain a little more clearly please? Mar 25 '20 at 14:06
• @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. Mar 25 '20 at 14:33