• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microchip hints, bug fixes, and work arounds.

3v0

Coop Build Coordinator
Forum Supporter
Thread starter #2
MPLAB.
Error - could not find file 'c018i.o'.
The only sure way I know of fixing the C018i error is to specify the lib path from PROJECT>BUILD_OPTIONS_PROJECT
Select the DIRECTORIES tab and followed by "LIBRARY SEARCH PATH" from the drop down box "show directories for". Add the path C:\MCC18\lib
 

edeca

Active Member
#3
I recently had trouble debugging HI-TECH C code using MPLAB. The fix (and more details) are at HI-TECH Software Forums: Debugging using MPLAB

Only applies to HI-TECH C, but might be useful to someone else.

I have copied that post here
I believe I have now fixed this. To cause the problem:

1) Start a new project in MPLAB (using the wizard or not)
2) Add the source files (from the post above)
3) Rebuild

For me, this results in a build log like the first one in the attached file.

Now to "fix" the problem:

1) Click Project -> Build Options -> Project
2) Toggle a random option off then on
3) Click "Apply" then "OK"
4) Rebuild

For me this results in the second log in the attached file.

Notice how they are different:

Code:// Works
Executing: "C:\Program Files\HI-TECH Software\PICC-18\PRO\9.63\bin\picc18.exe" --pass1 C:\MPLAB2\delay.c -q --chip=18F2321 -P --runtime=default,+clear,+init,-keep,-download,+stackwarn,-config,+clib,-plib --opt=default -D__DEBUG=1 --debugger=pickit2 -Blarge --double=24 --cp=16 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"

// Doesn't work
Executing: "C:\Program Files\HI-TECH Software\PICC-18\PRO\9.63\bin\picc18.exe" --pass1 C:\MPLAB2\delay.c -q --chip=18F2321 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"

The --runtime option is different, --debugger=pickit2 is added (auto detected) and a bunch of other options are there.

I have tried this 3 times now with new projects and this is completely reproducible.
 
Last edited by a moderator:

3v0

Coop Build Coordinator
Forum Supporter
Thread starter #4
C18 compiler shortcomings.

The following was posted by Pommie in another thread.

I have today converted a project from BoostC to C18 and had a rather nasty bug. I finally tracked it down to one bit of code that wasn't working correctly. Here is that code in isolation,
Code:
#include <p18f1320.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO2

void main(){
char count;
unsigned int temp;
    OSCCON=0x60;                //Osc=4MHz
    ADCON1=0x7f;                //All digital
    count=0;
    temp=0b0000100000000000;
    while((temp&(1<<count))==0){
        count++;
    }
    while(1);
}
What this code should do is find the first non zero bit in temp and so count should contain 11 after it executes. Well, it doesn't, it contains 7. C18 works with bytes when it does 1<<count. What is even more peculiar is that temp=1<<11 will place zero in temp not 0x0800 as you would expect.

You can fix the above by doing
while((temp&((int)1<<count))==0) or adding -Oi command line option.

So, why am I telling you this. Cause it took me a long time to find it and I just had to get it of my chest. Plus, it may help others.

BTW, the above worked fine in BoostC and it is the C18 compiler that doesn't comply with ISO.

Edit, One good point about C18 is that it's free.

Mike.

and


Sure, add it to that thread. It's not really a bug but can cause some nasty bugs.

Who would have thought that writing,
Code:
 unsigned int temp=10*60;
would not be the same as,
Code:
 unsigned int temp=600;
I always assumed that constants would be treated as 32 (or even 64) bits on the PC and cast to the appropriate size during assignment.

Mike.
 
Last edited:

rsp

New Member
#5
solution

To product a C18 assembler listing (.lst) file, you need to run mp2cod.exe...

Project > Build Options > Project
custom build tab
post build options
mp2cod.exe yourfile.cof

Credit for this solution goes to Mark at edaboard.com
 
#6
Mike.

and


Sure, add it to that thread. It's not really a bug but can cause some nasty bugs.

Who would have thought that writing,
Code:
 unsigned int temp=10*60;
would not be the same as,
Code:
 unsigned int temp=600;
I always assumed that constants would be treated as 32 (or even 64) bits on the PC and cast to the appropriate size during assignment.

Mike.
Dang, that's bad! I'd have thought the same.

Would this compile correctly?

Code:
       unsigned int temp = (int)10 * (int) 60;
not that it should be necessary.
 
#7
Hello,

I just recently had a very frustrating problem with HI-TECH for the PIC18 series (Lite version). The I2C routines were giving me strange errors:

Code:
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.66\bin\picc18.exe" --pass1 "C:\Users\Austin Schaller\Documents\MPLAB Projects\MPLAB C Projects\I²C_18LF4520_HT.c" -q --chip=18F4520 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 

Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.66\bin\picc18.exe" -oI²C_18LF4528_HT.cof -mI²C_18LF4528_HT.map --summary=default --output=default I²C_18LF4520_HT.p1 --chip=18F4520 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 

HI-TECH C PRO for the PIC18 MCU Family  V9.66

Copyright (C) 1984-2011 HI-TECH SOFTWARE

licensed for evaluation purposes only

this licence will expire on Sat, 15 Oct 2011

Advisory[1233] Employing 18F4520 errata work-arounds:

Advisory[1234]  * Corrupted fast interrupt shadow registers

Error   [499] ; 0. undefined symbol:

	_WriteI2C(I²C_18LF4528_HT.obj) 



********** Build failed! **********
Here is the simple code:

Code:
/************************************************************************

*

* Module:       	I²C_18LF4520_HT.C

* Description:  	Code to determine I²C functionality with the HI-TECH

*				compiler.

* Line length:  	120 characters [only if the length is longer than 80 chars]

* Functions:    	See Below

*

* Date:			Authors:					Comments:

* 24 Aug 2011   	Austin Schaller    			Created

*

************************************************************************/



#include <htc.h>

#include <stdio.h>

#include "peripheral\i2c.h"



__CONFIG(1, MCLRE_ON & CP0_OFF & BOREN_OFF & WDT_OFF & PWRT_ON & OSC_INTIO67);



void main()

{

	unsigned char data = 0xFF;

	

	OSCCON = 0x70;		// OSC = 8 MHz

	

	StartI2C();

	WriteI2C(data);

	StopI2C();

}
The fix:

As quoted from the peripheral libraries manual (section 1.2)

In order to use the supplied Microchip-compatible peripheral library functions, the user must ensure

the --runtime=+plib option is passed to the driver on the command line, or "Link in Peripheral

Libraries" is selected in the "Runtime Options" section of the Project Build Options in MPLAB.

The user need not include <plib.h> directly, as including <htc.h> will automatically include

<plib.h> when the above option is used, or the macro _PLIB is defined.
In other words, do the following:

1) Navigate to: Project -> Build Options -> Project -> Linker
2) Under "Runtime options" select "Link in Peripheral Library"
3) Celebrate your triumph!

I just hope none of you have to go through the pain that I did!

Austin
 
Last edited:

DerStrom8

Super Moderator
Most Helpful Member
#8
Ok, the other night I was having some trouble with a program. I kept getting the following error:

Code:
MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.udata_c018i.o' can not fit the section. Section '.udata_c018i.o' length=0x0000000a
Errors    : 1

Link step failed.
After trying out a few different options, I figured out that my program was larger than the 256 byte RAM could handle. The way to fix this error (can be different from ".udata_c018i.o"--the fix is the same) is to cut down as much as you can on the code. Get rid of any extra arrays, especially, as they take up a lot of space. Also cut down on your ints as much as possible. This will hopefully allow your program to "fit".

Der Strom
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#9
Hey DS8 the other way is to Initialise a few variables... then they are compiled in the idata section as well as the udata section... Microchip didn't figure on folks like us declaring ALL of the variables un-initialised.... There is a couple of banks reserved for both..
 

DerStrom8

Super Moderator
Most Helpful Member
#10
Hey DS8 the other way is to Initialise a few variables... then they are compiled in the idata section as well as the udata section... Microchip didn't figure on folks like us declaring ALL of the variables un-initialised.... There is a couple of banks reserved for both..
Hey Ian, thanks. Could you elaborate a bit more? I'm not sure I quite follow what you're saying....
 
Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#11
I had a program that run out of udata ( un-initialised data ) ie.
Code:
  long var1,var2,var3;
Changed ALL the variables to idata ( initialised data )
Code:
  long var1 = 0, var2 = 0, var3 = 0;
That was it!!! Tons more memory. (well a bit anyway)
 

DerStrom8

Super Moderator
Most Helpful Member
#12
I had a program that run out of udata ( un-initialised data ) ie.
Code:
  long var1,var2,var3;
Changed ALL the variables to idata ( initialised data )
Code:
  long var1 = 0, var2 = 0, var3 = 0;
That was it!!! Tons more memory. (well a bit anyway)
That's what I thought you were saying, and I just couldn't believe it would save that much space :D
Thanks for posting!
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#13
I think the ram pages are 256 byte in size.. When I last had this problem, the compiler complained about the udata ( basically it can't allocate any more).. When I looked at the memory usage gauge there was loads of ram left.. That's when I did the investigation. There was about 170 bytes of idata free. Ta da!!
 

3v0

Coop Build Coordinator
Forum Supporter
Thread starter #14
TIMER0 confusion

This is not a question but an observation.

When you step through the code with a PICkit2 SFR TMR0H can not be written to. If you run it works. The chip in this example is the PIC18F330 but I it should exist in other PICs with the same TIMER0 hardware. You will not see it using MPLAB SIM.


Code:
	T0CONbits.TMR0ON = 1;	// start timer0
	while(1)
	{	
		Nop(); 	
		Nop();
		Nop();
		TMR0H = h++;  // if you step these 2 lines it does not work 	
		TMR0L = l++;
		result = TMR0L;
		result += ((unsigned int) TMR0H)<<8;
		Nop();  // set BP here
		Nop();
		Nop();
		TMR0H = 0x00;    // if you step these 2 lines it does not work
		TMR0L = 0x00;	
		result0 = TMR0L;
		result0 += ((unsigned int) TMR0H)<<8;		
	}
}
 

Attachments

Last edited:

Pommie

Well-Known Member
Most Helpful Member
#15
3v0,

When you step and monitor the register it won't work. Try stepping without monitoring them and it should work. This is due to the fact that TMR0H is not a real register but a buffer register and so after the write to TMR0H the update will latch the existing value of the real TIMER0H. See 11.4 in the data sheet for an explanation.

Mike.
 

Pommie

Well-Known Member
Most Helpful Member
#17
I realised you weren't asking a question, I was just explaining why it happened.

Keeping it clear of questions is a good idea. Feel free to tidy up this thread by deleteing this and the previous 2 posts.

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#18
In the latest version Datasheet " DS40039E " on page 19 It lists the procedure to initialize PORTA as digital IO....

The Register value to turn off the comparator modules is 07H, and not 05H as in the listing.
 

be80be

Well-Known Member
#19
I was going to post that 0x05 doesn't work on that chip It should be 0x07
But I had to look to make sure who ever wrote the data sheet may of wrote one that did use 0x05 at the same time.
Cant trust them data sheets LOL
 

ClydeCrashKop

Well-Known Member
#20
This is from the PIC16(L)F1826/27 data sheet.
They say just copy and paste

;This code block configures the ADC
;for polling, Vdd and Vss references, Frc
;clock and AN0 input.
;Conversion start & polling for completion
; are included.
BANKSEL ADCON1 ;
MOVLW B’11110000’ ;Right justify, Frc clock
MOVWF ADCON1 ;Vdd and Vss Vref
BANKSEL TRISA ;
BSF TRISA,0 ;Set RA0 to input
BANKSEL ANSEL ;
BSF ANSEL,0 ;Set RA0 to analog

On build it said ANSEL is undefined. That's because the 16F1827 has ADC on PORTB as well. So you need to use ANSELA and ANSELB. I found those in the 16F1827.inc file.

I am also finding a snag using code for one chip on a different chip.
If the compiler complains about things being undefined, check the .inc or .h files for that chip. Just lately I found these varieties and a couple more for the ADC.

GODONE = 1; // pic16F876 start conversion
GO_DONE = 1; // 16F88 start conversion
BSF ADCON0,ADGO ; 16F1827 Start conversion in asm
GO_nDONE =1; // 16F1827 start conversion

.inc files are in C:\Program Files\Microchip\MPASM Suite
.h files are in C:\Program Files\HI-TECH Software\PICC\9.83\include
 

Latest threads

EE World Online Articles

Loading

 
Top