MPLABX PIC16F887A Assembly coding

Thread Starter

MisterFisk

Joined Jun 8, 2020
18
Good Day,

I am studying digital systems using Pic Trix by Pat Ellis. We need to use MPLABX to write and simulate our projects which need to be .asm files, but I am struggling to get any type coding running in the MPLabX environment. I found these examples Mplab examples for the p16F1829 but they just give errors when I try to build them.

I am hoping someone could give me advice on how to tackle figuring this out or recommend a good tutorial or something.

CODE BLINKING LED

#include <p16F1829.inc>

__CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF);
__CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF);

errorlevel -302 ;supress the 'not in bank0' warning
cblock 0x70 ;shared memory location that is accessible from all banks
Delay1 ;Define two file registers for the delay loop in shared memory
Delay2
endc

; -------------------LATC-----------------
; Bit#: -7---6---5---4---3---2---1---0---
; LED: ---------------|DS4|DS3|DS2|DS1|-
; -----------------------------------------

ORG 0
Start:
banksel OSCCON ;bank1
movlw b'00111000' ;set cpu clock speed of 500KHz ->correlates to (1/(500K/4)) for each instruction
movwf OSCCON ;move contents of the working register into OSCCON
bcf TRISC,0 ;make IO Pin C0 an output for DS1
banksel LATC ;bank2
clrf LATC ;start by turning off all of the LEDs
MainLoop:
bsf LATC, 0 ;turn on DS1

OndelayLoop:
decfsz Delay1,f ;Waste time.
bra OndelayLoop ;The Inner loop takes 3 instructions per loop * 256 loops = 768 instructions
decfsz Delay2,f ;The outer loop takes an additional 3 instructions per lap * 256 loops
bra OndelayLoop ;(768+3) * 256 = 197376 instructions / 125K instructions per second = 1.579 sec.
bcf LATC,0 ;Turn off LED C0 - NOTE: do not need to switch banks with 'banksel' since bank2 is still selected
OffDelayLoop:
decfsz Delay1,f ;same delay as above
bra OffDelayLoop
decfsz Delay2,f
bra OffDelayLoop
bra MainLoop ;Do it again...

end

ERROR

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[2]: *** No rule to make target 'build/default/production/newfile.o', needed by 'dist/default/production/Test.X.production.hex'. Stop.
make[1]: Entering directory 'C:/Users/MisterFisk/MPLABXProjects/Test.X'
make[1]: *** [.build-conf] Error 2
make -f nbproject/Makefile-default.mk dist/default/production/Test.X.production.hex
make: *** [.build-impl] Error 2
make[2]: Entering directory 'C:/Users/MisterFisk/MPLABXProjects/Test.X'
make[2]: Leaving directory 'C:/Users/MisterFisk/MPLABXProjects/Test.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/MisterFisk/MPLABXProjects/Test.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

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

atferrari

Joined Jan 6, 2004
4,770
That is a mess. Edit your post and put the code in between tags. Look for the right tool you have up in the window where you compose the post.

Without formatting nobody will like to read it.
 

jpanhalt

Joined Jan 18, 2008
11,087
Properly formatted, it assembles fine for me:

Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F1829 "blink.asm" /l"blink.lst" /e"blink.err"
Message[303] C:\USERS\JOHN ANHALT\DESKTOP\AAC CODE\BLINK.ASM 3 : Program word too large. Truncated to core size. (CFA4)
Message[303] C:\USERS\JOHN ANHALT\DESKTOP\AAC CODE\BLINK.ASM 4 : Program word too large. Truncated to core size. (DCFF)
Message[303] C:\USERS\JOHN ANHALT\DESKTOP\AAC CODE\BLINK.ASM 43 : Program word too large. Truncated to core size. (CFA4)
Message[303] C:\USERS\JOHN ANHALT\DESKTOP\AAC CODE\BLINK.ASM 43 : Program word too large. Truncated to core size. (DCFF)
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\mplink.exe" /p16F1829 "blink.o" /z__MPLAB_BUILD=1 /o"blink.cof" /M"blink.map" /W /x
I suggest you initialize your two registers, as they will come up unknown. Just "clrf Delayx" will do it.

I am not familiar with MPLabX's errors. Be sure the correct processor is selected in the configure window or its equivalent in MPLabX.
 

jpanhalt

Joined Jan 18, 2008
11,087
Here's the code formatted:

Code:
     #include <p16F1829.inc>

     __CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF);
     __CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF);

     errorlevel -302 ;supress the 'not in bank0' warning
     cblock 0x70                   ;shared memory location that is accessible from all banks
     Delay1                        ;Define two file registers for the delay loop in shared memory
     Delay2
     endc

; -------------------LATC-----------------
; Bit#: -7---6---5---4---3---2---1---0---
; LED: ---------------|DS4|DS3|DS2|DS1|-
; -----------------------------------------

     ORG 0
Start:
     banksel OSCCON                ;bank1
     movlw b'00111000'             ;set cpu clock speed of 500KHz ->correlates to (1/(500K/4)) for each instruction
     movwf OSCCON                  ;move contents of the working register into OSCCON
     bcf TRISC,0                   ;make IO Pin C0 an output for DS1
     banksel LATC                  ;bank2
     clrf LATC                     ;start by turning off all of the LEDs

     clrf Delay1
     clrf Delay2

MainLoop:
     bsf LATC, 0                   ;turn on DS1

OndelayLoop:
     decfsz Delay1,f               ;Waste time.
     bra OndelayLoop               ;The Inner loop takes 3 instructions per loop * 256 loops = 768 instructions
     decfsz Delay2,f               ;The outer loop takes an additional 3 instructions per lap * 256 loops
     bra OndelayLoop               ;(768+3) * 256 = 197376 instructions / 125K instructions per second = 1.579 sec.
     bcf LATC,0                    ;Turn off LED C0 - NOTE: do not need to switch banks with 'banksel' since bank2 is still selected

OffDelayLoop:
     decfsz Delay1,f               ;same delay as above
     bra OffDelayLoop
     decfsz Delay2,f
     bra OffDelayLoop
     bra MainLoop                  ;Do it again...

     end
When I write, I also have the operands of instructions in separate column,not just spaced.
 

Thread Starter

MisterFisk

Joined Jun 8, 2020
18
Properly formatted, it assembles fine for me:



I suggest you initialize your two registers, as they will come up unknown. Just "clrf Delayx" will do it.

I am not familiar with MPLabX's errors. Be sure the correct processor is selected in the configure window or its equivalent in MPLabX.
If I may ask. Could you maybe tell me what compilers are you using?
 

Ian Rogers

Joined Dec 12, 2012
1,136
If I may ask. Could you maybe tell me what compilers are you using?
There in lies your problem.... You need to assemble the code... XC can assemble as long as the asm code has the .as extension.
It would appear that XC is trying to compile your code.... Compilers are for high level languages.
 

Thread Starter

MisterFisk

Joined Jun 8, 2020
18
It seems I needed to add the pic information in the Linker Files in MPlab. I found this video which demonstrates how to set up the project to do assembly coding. I am posting it here just in case someone else needs a demonstration :
PIC Assembly Language Programming -
 
Top