Domi
Domi

Reputation: 9

MPLAB X IDE v2.35 Assembler Code, can't assemble (PIC16F84A)

It is my first try to program in assembly. May you can help me with this errors. Here is the code I used, you can find the error messages below. As said in the title, the IDE is MPLAB X IDE v2.35 and I use the Michrochip PIC16F84A.

    ;******************************************************************************
;  File Name    : main.asm
;  Version      : 1.0
;  Description  : Test Program
;  Author       : Me
;  Last Updated : 20 April 2015
; *******************************************************************


    list p=16f84
    radix hex

;   Register
STATUS      equ     0x03
OPTION_REG  equ     0x81
PORTA       equ     0x05
PORTB       equ     0x06
TRISA       equ     0x85
TRISB       equ     0x86

;   STATUS Register Bits
RP0         equ     0x05    ; 0 = Bank 0 0x00 - 0x7F, 1 = Bank 1 0x80 - 0xFF


;_________________________________________________________________
;Mainprogram

    BSF STATUS,RP0         ;   Change to RAM Bank 1
    BSF TRISB,2            ;   Set RB2 output to 1
    BCF STATUS,RP0         ;   Change to RAM Bank 0
    BCF PORTB,2            ;   Define RB2 as output

    end

This is the error message I got from MPLAB:

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/xxx/MPLABXProjects/Test.X'
make  -f nbproject/Makefile-default.mk dist/default/production/Test.X.production.hex
make[2]: Entering directory 'C:/Users/xxx/MPLABXProjects/Test.X'
make[2]: *** [build/default/production/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
"C:\Program Files (x86)\Microchip\MPLABX\mpasmx\mpasmx.exe" -q -p16f84a -l"build/default/production/main.lst" -e"build/default/production/main.err" -o"build/default/production/main.o" "main.asm" 
Warning[203] C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 29 : Found opcode in column 1. (BSF)
Error[152]   C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 29 : Executable code and data must be defined in an appropriate section
Warning[203] C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 30 : Found opcode in column 1. (BSF)
Message[302] C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 30 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Error[152]   C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 30 : Executable code and data must be defined in an appropriate section
Warning[203] C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 31 : Found opcode in column 1. (BCF)
Error[152]   C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 31 : Executable code and data must be defined in an appropriate section
Warning[203] C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 32 : Found opcode in column 1. (BCF)
Error[152]   C:\USERS\xxx\MPLABXPROJECTS\TEST.X\MAIN.ASM 32 : Executable code and data must be defined in an appropriate section
nbproject/Makefile-default.mk:95: recipe for target 'build/default/production/main.o' failed
make[2]: Leaving directory 'C:/Users/xxx/MPLABXProjects/Test.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/xxx/MPLABXProjects/Test.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 806ms)

Upvotes: 0

Views: 3049

Answers (1)

Grossu Iulian
Grossu Iulian

Reputation: 275

You are missing the .inc file for that processor, you must include it like this:

list p=16f84
#include "p16f84A.inc"

If you do this you do not need to declare SFR registers like you did and you must remove the following code to avoid conflicts:

;   Register
STATUS      equ     0x03
OPTION_REG  equ     0x81
PORTA       equ     0x05
PORTB       equ     0x06
TRISA       equ     0x85
TRISB       equ     0x86

It is also a good idea to specify the program's entry point and interrupt vector, they should be like this for your processor:

ORG 0x00
goto Main_Program
ORG 0x04 
goto Main_Program    ; If you are not using interrupt routines

Main_Program
    <your code here>
    end

In addition to all that you are also missing the config directives. Here is a general program template:

        PROCESSOR  16F84A
        #include   "p16f84A.inc"
        __CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF

;-- Definitions ------------------------------------------------
#define OUT1 PORTB,0        ; 
;-- variables --------------------------------------------------    
temp0   equ 20h             ; 
;---------------------------------------------------------------                                          
        org     0x00
        goto    init
        org     0x04
        goto    init

init

    <pheriperal and port configuration> 

main

    <your program here>

    goto main

    end

In MPLABX you can see what configuration bits you have available for your processor from the menu strip under: Window > PIC Memory Views> Configuration Bits Add them to the config under this form

Upvotes: 1

Related Questions