# PIC16F877 & MPLAB

#### Mazaag

Joined Oct 23, 2004
255
Hey guys,
I had a question with regards to programming a PIC using MPLAB. Its my first time, so bare with me.

I started a new project, added both the TEMPLATE file and the LKR files ( are there any more than I should include from the start ?) .

I removed parts of the template code ( the MAIN and DELAY etc ) and I click on BUILD ALL . The template had no errors, however I believe the LKR file has a problem. I got the following errors :

Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F877 "16f877.lkr" /l"16f877.lst" /e"16f877.err" /o"16f877.o"
Error[108] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 1 : Illegal character (/)
Error[108] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 2 : Illegal character (/)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 4 : Illegal opcode (.)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 6 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 7 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 8 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 9 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 10 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 11 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 12 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 13 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 15 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 16 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 17 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 18 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 20 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 21 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 22 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 23 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 25 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 26 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 27 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 28 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 30 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 31 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 32 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 33 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 34 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 35 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 36 : Illegal opcode (NAME)
Error[122] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 37 : Illegal opcode (NAME)
Error[129] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\LKR\16F877.LKR 38 : Expected (END)
BUILD FAILED: Mon Mar 06 20:45:46 2006

any idea ?

Thanks Guys

#### n9352527

Joined Oct 14, 2005
1,198
What version of MPLAB are you using? Did it produce errors before you delete parts of the template code?

Edited:

I've just realised that the first line of your pasted error code is the command line that instruct the assembler to assemble your linker file (executing MPAsmWin). This is the problem. Linker file is used to instruct the linker on how to link the intermediate assembled code and can not be assembled itself.

Make sure that the linker file is placed in Linker Scripts section in the project window so that it is not included in the assemble/build process.

#### Mazaag

Joined Oct 23, 2004
255
Originally posted by n9352527@Mar 7 2006, 07:50 AM
What version of MPLAB are you using? Did it produce errors before you delete parts of the template code?

Edited:

I've just realised that the first line of your pasted error code is the command line that instruct the assembler to assemble your linker file (executing MPAsmWin). This is the problem. Linker file is used to instruct the linker on how to link the intermediate assembled code and can not be assembled itself.

Make sure that the linker file is placed in Linker Scripts section in the project window so that it is not included in the assemble/build process.
[post=14746]Quoted post[/post]​
I was looking at a website which said to delete all code, and to click on BUILD ALL to check whether everything was SETUP correctly before writing the code.

Now like I mentioned earlier this is my first time, so I have no understanding as to what a LKR file is at all. I know that the template file, which the website said to include, basically contains all the directives and so on needed for configuring the PIC. I would really appreciate it if you could elaborate on the use of the LKR file for me, and the basics steps needed in order to program the PIC using MPLAB with both Assembly Language and C.

Thank You

#### n9352527

Joined Oct 14, 2005
1,198
Originally posted by Mazaag@Mar 7 2006, 07:08 PM
I was looking at a website which said to delete all code, and to click on BUILD ALL to check whether everything was SETUP correctly before writing the code.

Now like I mentioned earlier this is my first time, so I have no understanding as to what a LKR file is at all. I know that the template file, which the website said to include, basically contains all the directives and so on needed for configuring the PIC. I would really appreciate it if you could elaborate on the use of the LKR file for me, and the basics steps needed in order to program the PIC using MPLAB with both Assembly Language and C.

Thank You
[post=14756]Quoted post[/post]​
The template (or MPLAB config) has an include file, which defines the registers/peripherals names and addresses for particular micro you are using. Converting these addresses and assigning variables in the object code to physical addresses is controlled by linker file. Linker file (*.lkr) is the memory mapping file in MPLAB.

Linker file can not be assembled. Although if you right click the file in the project window, the pop-up menu allows you to assemble it. The errors that you experienced is exactly what would happen if you assembled the linker file. I have no idea why the MPLAB assembles the linker file when you clicked build all. Probably because it thinks that the linker file is part of the source code.

You could use the new project wizard to create a project. Select the tools that you have (e.g. assembler or C compiler if you have one) and the micro you are using and then add the appropriate template file and the linker file. These are all done within the wizard dialogues. Build it before you edit anything. Have a look at the help file that comes with MPLAB, it has a step by step tutorial on creating a skeleton project.

#### Mazaag

Joined Oct 23, 2004
255
Originally posted by n9352527@Mar 8 2006, 12:13 PM
The template (or MPLAB config) has an include file, which defines the registers/peripherals names and addresses for particular micro you are using. Converting these addresses and assigning variables in the object code to physical addresses is controlled by linker file. Linker file (*.lkr) is the memory mapping file in MPLAB.

Linker file can not be assembled. Although if you right click the file in the project window, the pop-up menu allows you to assemble it. The errors that you experienced is exactly what would happen if you assembled the linker file. I have no idea why the MPLAB assembles the linker file when you clicked build all. Probably because it thinks that the linker file is part of the source code.

You could use the new project wizard to create a project. Select the tools that you have (e.g. assembler or C compiler if you have one) and the micro you are using and then add the appropriate template file and the linker file. These are all done within the wizard dialogues. Build it before you edit anything. Have a look at the help file that comes with MPLAB, it has a step by step tutorial on creating a skeleton project.
[post=14783]Quoted post[/post]​
Any ideas on a free C compiler for MPLAB that I could get ?
do I have to edit the LKR file in anyway when I add it to my project files ? or is it just a matter of picking the right one for my micro and thats it ?
Is there anything else that I have to worry about before I start writing the code in C ? ( other than getting the C compiler )

Thanks

#### n9352527

Joined Oct 14, 2005
1,198
Originally posted by Mazaag@Mar 8 2006, 07:49 PM
Any ideas on a free C compiler for MPLAB that I could get ?
do I have to edit the LKR file in anyway when I add it to my project files ? or is it just a matter of picking the right one for my micro and thats it ?
Is there anything else that I have to worry about before I start writing the code in C ? ( other than getting the C compiler )

Thanks
[post=14784]Quoted post[/post]​
I don't know, I've never looked at available C compiler for PIC. I've always used assembler.

No need to edit the linker file, just pick the one for your particular PIC.Pay attention to the end letter (e.g. 877 or 877a, i denotes reserved ICD memory area and only necessary if you are using ICD).