PIC16F84A -- MPLAB -- PLEASE HELP!

Discussion in 'Homework Help' started by EDSON ONCEBAY, Mar 31, 2015.

  1. EDSON ONCEBAY

    Thread Starter New Member

    Mar 31, 2015
    4
    0
    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 (Text):
    1.  
    2.  
    3. #include GENERAL.h    ; PIC library
    4.  
    5. COUNT EQU 0x05
    6. SUM EQU 0x48
    7. ; ===========================================================
    8.  
    9.  __CONFIG 0X3FF2 ;This is the control bits for CONFIG register
    10.  ORG 0X0000 ;RESET or WDT reset vector
    11.  GOTO START
    12.  ORG 0X0004 ;Regular INT vector RESERVE THIS SPACE. DON'T USE IT
    13.  RETFIE
    14.  
    15. START BSF STATUS,RP0
    16.  MOVWF TRISB
    17.  BCF STATUS,RP0
    18.  MOVWF PORTB
    19.  
    20.  MOVLW 0x05
    21.  MOVWF COUNT
    22.  MOVLW 0x00
    23.  MOVWF SUM
    24.  
    25.  MOVF PORTA,W
    26. LOOP ADDWF SUM
    27.  DECFSZ COUNT,0
    28.  GOTO LOOP
    29.  
    30.  MOVF SUM,0
    31.  MOVWF PORTB
    32.  
    33.  
    34.  END
    35.  

    I would appreciate your feedback. Thanks!!!
     
  2. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    Hello,
    you want in asm lang only?
    can't do in C?
     
  3. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,676
    899
    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: Apr 1, 2015
  4. EDSON ONCEBAY

    Thread Starter New Member

    Mar 31, 2015
    4
    0
    Yes it needs to be asm
     
  5. EDSON ONCEBAY

    Thread Starter New Member

    Mar 31, 2015
    4
    0
    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.
     
  6. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    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!
     
  7. Dodgydave

    Distinguished Member

    Jun 22, 2012
    4,969
    744
    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: Apr 1, 2015
  8. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,647
    759
    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).
     
    Last edited: Apr 1, 2015
  9. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,676
    899
    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
     
    Dodgydave likes this.
Loading...