MPLab syntax error

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
Good Day,

I am hoping someone could point out what is wrong with my syntax in this code. It keeps gives me a syntax error at cblock Rambank0.

Code:
#include <16f877a.cgen.inc>
    
;*******Equates*********************    
    RamBank0 equ 20H
;*******Variables*******************
    cblock RamBank0
        numb1
        numb2
        answ
    endc
;*******Main Program****************
 

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
hi,
Try adding an equ between the cblock and Ramblock.
E
I tried doing that but it then gives me syntax errors at numb1. If I am not mistaken the cblock directive is not suppose to have an equ. I am trying to follow the example but it just gives me a syntax error and I can figure out why for the life of me.
 

jpanhalt

Joined Jan 18, 2008
9,755
1) Change line 1 to #include <p16f877a.inc>
2) Put "RamBank0 in column 1

Assembled fine for me.

Edit:
Code:
#include <p16F877A.inc>
  
;*******Equates*********************  
RamBank0 equ 20H
;*******Variables*******************
    cblock RamBank0
        numb1
        numb2
        answ
    endc
;*******Main Program****************

     end
Edit#2

An equate is simply a substitution; therefore, the memory map is not what you may think it is:

1593437055540.png

Basically, you create a register named RamBank0 at 0x20, so your other registers begin after 0x20

You could do the same with this:
RamBank0 equ 0x20
numb2 equ 0x21
answ equ 0x22

What you apparently want to do is:

cblock 0x20
numb2
answ
endc
 
Last edited:

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
1) Change line 1 to #include <p16f877a.inc>
2) Put "RamBank0 in column 1

Assembled fine for me.

Edit:
Code:
#include <p16F877A.inc>
  
;*******Equates*********************  
RamBank0 equ 20H
;*******Variables*******************
    cblock RamBank0
        numb1
        numb2
        answ
    endc
;*******Main Program****************

     end
Is it possible for you to tell me how you configured your MPLabs? If I change my include file to <p16f877a.inc> it just gives me a fatal error saying that p16f877a is not found.
 
Last edited:

jpanhalt

Joined Jan 18, 2008
9,755
I use MPLab8.92.

When you set up a project, you must provide a map to the include files like this (View project window):

1593437491871.png

Right click and then "add files". Then go to where that include file is on your machine.
 

ericgibbs

Joined Jan 29, 2010
10,205
hi John,
As a quick check I edited one of my old Oshonsoft Assembler files.
Note it already has #include <p16f877.inc> as part of the header
E

Clip:
;12jan06, this pgm works ok, with the inserted Equ

list p=16f877,f=inhX32
#include <p16f877.inc>
;errorlevel -302

__config _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF


; added for testing, compiles OK.
Ramblock equ 20h
cblock equ Ramblock
numb1
numb2
answ
endc
; added
 

jpanhalt

Joined Jan 18, 2008
9,755
Hi Eric,

I'll bet numb1 is at 0x21, not 0x20 as I suspect the TS wanted.

As an added tidbit for the TS, "equate" and "#define" may be confused. They seem to do the same thing in some instances. Equate sets a name to equal a number; #define is just a substitution. It can be a number or name. Let's say you had written:

#define Rambank0 0x20

cblock Rambank0
numb1
numb2
answ
endc

Then the register memory will look like this:
1593441018291.png

To repeat, using an equ Rambank0 uses one byte of ram at 0x20 which is named Rambank0. Using #define Rambank0 0x20 simply inserts 0x20 when the string Rambank0 is encountered.

EDIT: In reviewing my post #4, I hadn't noticed that numb1 was skipped. Testing something now.
EDIT2: It's doing what I thought -- namely, the register at 0x20 has two names, numb1 and RamnBank0.

1593442338585.png

And here's a watch window:

1593442437377.png
 
Last edited:

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
I use MPLab8.92.

When you set up a project, you must provide a map to the include files like this (View project window):

View attachment 210986

Right click and then "add files". Then go to where that include file is on your machine.
I use MPLab8.92.

When you set up a project, you must provide a map to the include files like this (View project window):

View attachment 210986

Right click and then "add files". Then go to where that include file is on your machine.
I have added p16f877a.inc and the accompanying linker file, yet it still gives me that it doesn't find the include file. Could it be that I am using the incorrect compiler toolchain?
 

Attachments

jpanhalt

Joined Jan 18, 2008
9,755
Do you have the correct path for the include file?

A simple fix is to copy and paste the include file to the same folder in which the code is, which is probably your project folder.
 

ericgibbs

Joined Jan 29, 2010
10,205
hi MF,
This image shows a test asm and Oshonsoft sim output looks OK,
Compiled using MPLAB option. Ver 8.7
E
AAA 403 16.18.gif
 
Last edited:

atferrari

Joined Jan 6, 2004
4,017
Regret to tell you that you are confused and to a certain point it is reasonable.

Most, if not all, contributing here about PIC micros are working with MPASM, a traditional Assembler by Microchip.

Starting with MPLABX 5.40, MPASM was left behind. What you read.

Now, with XC8 v 2.20 (that you have to download because it does not come bundled with MPLABx, as in the past), you get included, the new assembler pic-as v2.20.

IOW, adiós MPASM. Please no rant, please.

If you are interested to move ahead, I suggest you complete your current project with MPASM to have it up and running and when you are decided to bite the bullet, do the porting to pic-as 2.20.

Since long time ago I learnt that ranting gets you no help, forget how bad it is for you (it is not) and start learning how the new one works. There is more than nothing the unavoidable rewriting which is pure clerical work plus understanding relocation (adiós absolute mode - not a big drama).

If you, at any moment want me to tell all what I learnt (?) to help you in the transition, open a new thread and I will tell all I know, there.

Right now on my desk, my project (micro communicating with PLX-DAQ Excel sheet, via serial port), is working like a charm. When I started with pic-as 2.20 it was already half developed with MPASM. Sincerely I enjoyed all this.

You tell me.

PD: and yes, kiss goodbye CBLK; it's gone. ;)
 
Last edited:

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
Regret to tell you that you are confused and to a certain point it is reasonable.

Most, if not all, contributing here about PIC micros are working with MPASM, a traditional Assembler by Microchip.

Starting with MPLABX 5.40, MPASM was left behind. What you read.

Now, with XC8 v 2.20 (that you have to download because it does not come bundled with MPLABx, as in the past), you get included, the new assembler pic-as v2.20.

IOW, adiós MPASM. Please no rant, please.

If you are interested to move ahead, I suggest you complete your current project with MPASM to have it up and running and when you are decided to bite the bullet, do the porting to pic-as 2.20.

Since long time ago I learnt that ranting gets you no help, forget how bad it is for you (it is not) and start learning how the new one works. There is more than nothing the unavoidable rewriting which is pure clerical work plus understanding relocation (adiós absolute mode - not a big drama).

If you, at any moment want me to tell all what I learnt (?) to help you in the transition, open a new thread and I will tell all I know, there.

Right now on my desk, my project (micro communicating with PLX-DAQ Excel sheet, via serial port), is working like a charm. When I started with pic-as 2.20 it was already half developed with MPASM. Sincerely I enjoyed all this.

You tell me.

PD: and yes, kiss goodbye CBLK; it's gone. ;)
Sorry if I don't understand what you are saying. But if I understand it you correctly, you are telling me that I should rather code using the pic-as v 2.20. Which to my understanding (which might be incorrect) is a mix of c and assembly. I would agree with you that writing in c would be easier, however my project requires me to have it in pure assembly.
 
Last edited:

jpanhalt

Joined Jan 18, 2008
9,755
I just went through the users manual called "pic-as v 2.20," and your assessment agrees with mine. Coding the 16F877A does not require it, and I cannot see that if offers any advantage.

Once you get your program in Assembly working, presumably non-relocatable version (aka absolute), then you might try writing relocatable code as a bridge.
 

atferrari

Joined Jan 6, 2004
4,017
Sorry if I don't understand what you are saying. But if I understand it you correctly, you are telling me that I should rather code using the pic-as v 2.20. Which to my understanding (which might be incorrect) is a mix of c and assembly. I would agree with you that writing in c would be easier, however my project requires me to have it in pure assembly.
To clarify / simplify:

a) You working in C - nothing to say myself. I am not conversant in C.

You working in Assembly

b) If you need just to complete the project - stay with MPASM.

c) If you decide to move forward starting with pi-as 2.20 (pure Assembly, not a mix) make sure you got b) done before. Eventually, reread my previous again.

Just a warning I wish I had from somebody prior to start: don't waste your time selecting XC8. Do select pic-as 2.20 as the toolchain. One full day struggling because of that.

Buena suerte!

PD: and yes again; kiss goodbye absolute; to any practical purpose it is also gone.;);)

pic-as 2.20.png
 

Thread Starter

MisterFisk

Joined Jun 8, 2020
12
To clarify / simplify:

a) You working in C - nothing to say myself. I am not conversant in C.

You working in Assembly

b) If you need just to complete the project - stay with MPASM.

c) If you decide to move forward starting with pi-as 2.20 (pure Assembly, not a mix) make sure you got b) done before. Eventually, reread my previous again.

Just a warning I wish I had from somebody prior to start: don't waste your time selecting XC8. Do select pic-as 2.20 as the toolchain. One full day struggling because of that.

Buena suerte!

PD: and yes again; kiss goodbye absolute; to any practical purpose it is also gone.;);)

View attachment 211040
Thanks a lot for your help. I downloaded MPlab X v5.35 which still has MPASM and the code started to work. I will follow your advice in the future and convert to pic-as when I know what I am doing.:)
 
Top