Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F84A - Loop not working on MPLAB

Status
Not open for further replies.

dannyelloko20

Newbie level 5
Joined
Mar 25, 2015
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
65
I need to sum and subtract two hex values as it is shown in my code below. However, when I export the hex file to Pickit2 and then to my board, it will not go to SUM for some reason. Can you guys give me a hint as to why this is not working?
Thank you!

Code:
***********************************************************************
		#include <GENERAL.H>
; ================	EQUATES  =========================================
 
 NUM1		EQU		0x5A	
 NUM2		EQU		0x39

 REG1       EQU     0x40
 REG2       EQU     0x41
; =======================================================================				

		__CONFIG	0X3FF2		;This is the control bits for CONFIG register
		ORG			0X0000		;RESET or WDT reset vector
		GOTO		START
		ORG			0X0004		;Regular INT vector RESERVE THIS SPACE.  DON'T USE IT
		RETFIE


START 	    				
                CLRW
                BSF      STATUS,RP0
                MOVWF    TRISB
                BCF      STATUS,RP0 
                MOVWF    PORTB

        
                BTFSC   PORTA,0			        ;skip next instruction if RA0 = 0 and go to SUM
		GOTO     SUM 

                CLRW
		MOVLW    NUM2				;put NUM2 in W
		SUBLW    NUM1				;subtract NUM2 in W from NUM1  
		MOVWF    REG1				;save the result in REG1
		MOVF     STATUS,W			;copy the STATUS register value to W (not necessary but requested by professor)
		MOVWF    REG2				;and then to REG2 (not necessary but requested by professor)
                MOVWF    PORTB
                GOTO     DONE
    
SUM		
                CLRW
                MOVLW    NUM1				;put NUM1 in W
		ADDLW    NUM2				;add NUM2 with the result in W
		MOVWF    REG1				;save the result in REG1
		MOVF     STATUS,W			;copy the STATUS register value to W
		MOVWF    REG2				;and then to REG2
                MOVWF    PORTB

DONE
		END
 

When you jump to the "DONE" label, what are you expecting the device to do?
Remember that there is not operating system for the program to exit to.
Almost without exception, code for embedded devices operate in an infinite loop.
How do you know that it is not taking the path you expect?
By the way, you really should write to the LAT registers - the general rule (to avoid the read-modify-write problem) is to read from the PORT and write to the LAT.
Susan
 

Please refer back to where the answer is already given.

Dannyelloko20 - If you wish to add to an ongoing thread please add your new post to it instead of starting a new one. It lets us see the history of what you have done so we don't go over the same issues again.

Susan - No LAT registers in the 16F84A :shock:

Brian.
 

Susan - No LAT registers in the 16F84A :shock:
Brian.
My bad - I saw the "Data Latch" label in the data sheet and "just assumed"!!! Sigh
However it means the OP needs to be even more careful about the RMW problem!
Susan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top