PIC16F84A -- MPLAB -- PLEASE HELP!

Thread Starter

EDSON ONCEBAY

Joined Mar 31, 2015
4
Hi there, I'm working on a project for school and it is kinda confusing so I'm here desperately for help.

Assignment: "Connect PORTB to the 8 LEDs and PORTA to switches S10 to S 14, with S14 the MSB. Read the Switch value and then multiply the switch value by the number five (5). Display the results on the LEDs. "

I came up with my code and this is what I have so far:


Code:
#include GENERAL.h    ; PIC library

COUNT EQU 0x05 
SUM EQU 0x48 
; =========================================================== 

 __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 BSF STATUS,RP0 
 MOVWF TRISB 
 BCF STATUS,RP0 
 MOVWF PORTB
 
 MOVLW 0x05 
 MOVWF COUNT 
 MOVLW 0x00
 MOVWF SUM
 
 MOVF PORTA,W
LOOP ADDWF SUM
 DECFSZ COUNT,0
 GOTO LOOP 
 
 MOVF SUM,0
 MOVWF PORTB

 
 END

I would appreciate your feedback. Thanks!!!
 

jpanhalt

Joined Jan 18, 2008
11,088
I assume this is homework. What version of MPLab are you using? I am assuming you are using MPLab 8.xx, not MPLAB X.

Before getting into the details of your code, what did that code do in MPLab SIM? Have you learned to use that tool?

For starters, you want PORTB to be all outputs, right? How do you know the contents of w that you move to TRISB? Similarly, you then move w to PORTA, which is all input. Why?

John

edit: What is 16F84a.h? Is that something provided to you as a starter? I used 16F84A.inc instead. Otherwise, please provide that hex file.

edit#2: Is register 0x05 available on the 84A as general purpose RAM?(GP RAM starts at 0x0C) Also notice that when you decrease count, you are storing the result in w, not f. Thus, the value in COUNT never decreases.
 
Last edited:

Thread Starter

EDSON ONCEBAY

Joined Mar 31, 2015
4
I assume this is homework. What version of MPLab are you using? I am assuming you are using MPLab 8.xx, not MPLAB X.

Before getting into the details of your code, what did that code do in MPLab SIM? Have you learned to use that tool?

For starters, you want PORTB to be all outputs, right? How do you know the contents of w that you move to TRISB? Similarly, you then move w to PORTA, which is all input. Why?

John

edit: What is 16F84a.h? Is that something provided to you as a starter? I used 16F84A.inc instead. Otherwise, please provide that hex file.

edit#2: Is register 0x05 available on the 84A as general purpose RAM?(GP RAM starts at 0x0C) Also notice that when you decrease count, you are storing the result in w, not f. Thus, the value in COUNT never decreases.
Thanks for your feedback. Im using MpLAB 8.1 and I was just introduced to it so bear with me here. Portb needs to be outputs and porta inputs for the next part of the lab which i didnt mention. (sorry)
Lastly, 16F84a.h is the library given by the professor with all the addresses and hex values.
 

JDT

Joined Feb 12, 2009
657
Nothing wrong with asm (on an 8-bit PIC, anyway).

Multiply by 5 hint:-
multiply input by 4 (know how to do that?).
add the original input.

I think PORT A is only 5-bits wide? Helps if it is!
 

Dodgydave

Joined Jun 22, 2012
9,936
In the Loop you have missed off the result destination like this, ADDWF SUM,f (not specified here)
the decrement should have the result in the File, DECFSZ COUNT,f

so it wont add up
 
Last edited:

atferrari

Joined Jan 6, 2004
4,276
Hola Edson,

Eu acho... your very first line seems to include the wrong file, surely for C.

Look at what I do , for Assembler, to start a project. If I am confusing you, it is possible, do not worry. When you manage to understand you will be knowing better.

The .inc file in a properly installed MPLAB is there. I had to add the .asm to it or it would not upload here.

Last suggestion (it's a MUST): use the names that the .inc file shows when referring to any register (what's the reason why each micro has its own .inc file after all).
 

Attachments

Last edited:

jpanhalt

Joined Jan 18, 2008
11,088
In the Loop you have missed off the result destination like this, ADDWF SUM,f (not specified here)
DECFSZ COUNT,f

so it wont add up
He had: decfsz count,0 That was the point of one of my edits. As advice going forward, I would advise the TS to use "f" and "w" for 1 and 0, respectively for the destination registers. It makes it easier to read.

John
 
Top