MPLAB Assembly language issues

Discussion in 'Programmer's Corner' started by luebangs, Mar 21, 2014.

  1. luebangs

    Thread Starter New Member

    Mar 21, 2014
    Hello everyone,
    I am having some issues building this code and understanding whats wrong. I am using the PIC16F84A in MPLAB in absolute compile. The bottom is my code and the attachment is my error messages which i don't understand what to change. Essentially i am trying to build a code that has three switches and six LED's. Three LED's are suppose to be the complements of the other three LED's. Please help me!

    Code ( (Unknown Language)):
    2. ;Flashing Lights Project 1
    3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    4. ;Define Labels
    5. status equ 03; status changes from bank 1 to 0 and vice versa
    6. porta  equ 05; 05h file address
    7. portb  equ 06;
    8. trisa  equ 85;
    9. trisb  equ 85;
    10. mem1   equ 0 ;
    11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    12. ;Macro Setup
    13. ;
    14. START  bsf status,5 ;
    15.        movlw b'00011111' ;
    16.        movwf trisa;
    17.        movlw b'00000000'
    18.        movwf trisb;
    19.        bcf status,5;
    20.        clrf  portb;
    21. mend
    22.                                                           CLRF PORTB;
    23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    24. ;Start of Program
    25.        movlw b'00000101'; must double check
    26.        movwf mem1
    27.        movf portb;
    28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    29. ;Complements
    30.        btfss portb,0
    31.        bsf   portb,3
    32.        btfss portb,1
    33.        bsf   portb,4
    34.        btfss portb,2
    35.        bsf   portb,5
    36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    37. ;I/O
    38. begin  bsf portb,0;
    39.        bsf portb,1;
    40.        bsf portb,2;
    41.        bsf portb,3;
    42.        bsf portb,4;
    43.        bsf portb,5;
    44. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    45. ;reset portb
    46.        bcf portb,0;
    47.        bcf portb,1;
    48.        bcf portb,2;
    49.        bcf portb,3;
    50.        bcf portb,4;
    51.        bcf portb,5;
    53. end
    Last edited by a moderator: Mar 21, 2014
  2. MaxHeadRoom


    Jul 18, 2013
    If you click on the error line it will show you the respective line it does not like.
    Your end directive is in column1 tab it over.
    If you define your ports it in lower case then it must be declared in L.C., CLRF PORTB in caps! line 21.
    Instead of defining everything, use the PIC16F84A INC include file.
    The Bank0 errors often come up if not defined just as a warning.
    Also download or consult the MPLAB assembly manual and operators guide for all the errors etc.
    Last edited: Mar 21, 2014
  3. JohnInTX


    Jun 26, 2012
    What MAX said plus:

    You need ORG 0 at the top to ensure that the code begins at the reset point.

    Message [305] for line 26 means you should specify an explicit destination for the movf either
    Code ( (Unknown Language)):
    1.  MOVF PORTB,W  ;to move to WREG - OR -
    2.  MOVF PORTB,F   ; to move it to itself
    You probably didn't want to do the second one. I recommend you ALWAYS specify the destination for clarity, even if its the default.

    You can suppress Message [302] by adding
    at the beginning of the program. Its a pretty useless message, particularly when the code gets bigger as it can obscure useful warnings.

    Macro Setup and mend do nothing. Did you intend to use macros at all? The proper syntax for a simple macro is:
    Code ( (Unknown Language)):
    1. macro_name  macro
    2.   (instructions)
    3.   endm
    Code ( (Unknown Language)):
    2.  movlw b'00000101'; must double check
    3.  movwf mem1      
    4.  movf portb;
    This doesn't do anything useful plus it has a serious bug. movwf mem1 writes W to wherever FSR is pointing - KABOOM. That's because mem1 equ 0 above.
    If you use the header file as MAX says, you'll be much less likely to make such errors and many will actually be flagged for you.

    What is the default radix? Hex? Decimal? I don't know either (OK, actually I do but..) always specify the radix explicitly when declaring memory locations or other constants. For example
    20 can evaluate to 20, 32 or 16 depending on what the current radix is. The default radix can be changed on the assembler command line which would be a disaster if you picked the wrong one. So when you want 20hex, specify 20h. Specify .20 for 20 decimal etc. Same rule as above, don't rely on defaults, be explicit.

    Finally, you have no loop construct to keep the code from running off into space after the last statement. In C, running off out of main would restart the code. In assembler, what you see is what you get. This one runs to the end of the program memory space (assuming the memory is all NOP) then returns to the top when the PC wraps around.
    Last edited: Mar 21, 2014
  4. luebangs

    Thread Starter New Member

    Mar 21, 2014
    Thanks to all who helped. This is my new build and i will have to continue to tweak and make it more concise and functional . I believe my ports are complemented correct for three on and three off but i will have to still check the datasheet.

    Code ( (Unknown Language)):
    2.  ;Flashing Lights Project 1
    3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    4. ;Define Labels
    5. status equ 03h; status changes from bank 1 to 0 and vice versa
    6. porta  equ 05h; 05h file address
    7. portb  equ 06h;
    8. trisa  equ 85h;
    9. trisb  equ 85h;
    10. mem1   equ 0  ;
    11. rpo    equ 5h ;
    12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    13. ;Macro Setup
    14. Bank0  macro
    15.        bcf status,rpo; clear rpo bit
    16.        endm
    17. Bank1  macro
    18.        bsf status,rpo; set rpo bit
    19.        endm
    20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    21. ;Start of Program
    22.        movlw b'00000101'; must double check
    23.        movwf mem1
    24.        movf portb,w;
    25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    26. ;Complements
    27.        btfss portb,0
    28.        bsf   portb,3
    29.        btfss portb,1
    30.        bsf   portb,4
    31.        btfss portb,2
    32.        bsf   portb,5
    33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    34. ;I/O
    35. begin  bsf portb,0;
    36.        bsf portb,1;
    37.        bsf portb,2;
    38.        bsf portb,3;
    39.        bsf portb,4;
    40.        bsf portb,5;
    41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    42. ;reset portb
    43.        bcf portb,0;
    44.        bcf portb,1;
    45.        bcf portb,2;
    46.        bcf portb,3;
    47.        bcf portb,4;
    48.        bcf portb,5;
    49. loop nop
    50.        goto loop
    52.     end
    Last edited by a moderator: Mar 23, 2014
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    Compare what you believe is a macro with mine:

    Code ( (Unknown Language)):
    5.         LED_GREEN_ON
    6.         DELAY_300_MILI
    7.         LED_GREEN_OFF
    8.         CALL DELAY_300_MILI
    10.         [COLOR="red"]ENDM[/COLOR]
    For MPLAB to know that what follows IS a macro, you have to be explicit.
    For MPLAB to know that the macro ended here, you have to be explicit.

    You have to MEND your code. Pun intended. :p

    Buena suerte