MPLAB Assembly language issues

Thread Starter

luebangs

Joined Mar 21, 2014
2
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!

Rich (BB code):
;Flashing Lights Project 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Define Labels
status equ 03; status changes from bank 1 to 0 and vice versa
porta  equ 05; 05h file address
portb  equ 06;
trisa  equ 85; 
trisb  equ 85;
mem1   equ 0 ; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Macro Setup
;
START  bsf status,5 ;
       movlw b'00011111' ;
       movwf trisa; 
       movlw b'00000000'
       movwf trisb;
       bcf status,5;
       clrf  portb;
mend
                                                          CLRF PORTB; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Start of Program
       movlw b'00000101'; must double check
       movwf mem1
       movf portb;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Complements
       btfss portb,0
       bsf   portb,3
       btfss portb,1
       bsf   portb,4
       btfss portb,2
       bsf   portb,5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;I/O
begin  bsf portb,0;
       bsf portb,1;
       bsf portb,2;
       bsf portb,3;
       bsf portb,4;
       bsf portb,5;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;reset portb
       bcf portb,0;
       bcf portb,1;
       bcf portb,2;
       bcf portb,3;
       bcf portb,4;
       bcf portb,5;

end
 

Attachments

Last edited by a moderator:

MaxHeadRoom

Joined Jul 18, 2013
28,617
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.
Max.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
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
Rich (BB code):
 MOVF PORTB,W  ;to move to WREG - OR -
 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
ERRORLEVEL -302
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:
Rich (BB code):
macro_name  macro
  (instructions)
  endm
Rich (BB code):
 movlw b'00000101'; must double check
 movwf mem1      
 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:

Thread Starter

luebangs

Joined Mar 21, 2014
2
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.

Rich (BB code):
 ;Flashing Lights Project 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Define Labels
status equ 03h; status changes from bank 1 to 0 and vice versa
porta  equ 05h; 05h file address
portb  equ 06h;
trisa  equ 85h; 
trisb  equ 85h;
mem1   equ 0  ;
rpo    equ 5h ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Macro Setup
Bank0  macro
       bcf status,rpo; clear rpo bit
       endm
Bank1  macro
       bsf status,rpo; set rpo bit
       endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Start of Program
       movlw b'00000101'; must double check
       movwf mem1
       movf portb,w;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Complements
       btfss portb,0
       bsf   portb,3
       btfss portb,1
       bsf   portb,4
       btfss portb,2
       bsf   portb,5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;I/O
begin  bsf portb,0;
       bsf portb,1;
       bsf portb,2;
       bsf portb,3;
       bsf portb,4;
       bsf portb,5;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;reset portb
       bcf portb,0;
       bcf portb,1;
       bcf portb,2;
       bcf portb,3;
       bcf portb,4;
       bcf portb,5;
loop nop
       goto loop

    end
 
Last edited by a moderator:

atferrari

Joined Jan 6, 2004
4,764
Rich (BB code):
;Macro Setup
;
START  bsf status,5 ;
       movlw b'00011111' ;
       movwf trisa; 
       movlw b'00000000'
       movwf trisb;
       bcf status,5;
       clrf  portb;
mend
Compare what you believe is a macro with mine:

Rich (BB code):
FLASH_LED_GREEN MACRO
        
        LED_GREEN_ON
        DELAY_300_MILI
        LED_GREEN_OFF
        CALL DELAY_300_MILI

        ENDM
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
 
Top