Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 2nd April 2008, 10:50 AM   (permalink)
Default PIC C18 Compiler Issues: Pointers, Function Prototypes

I am working on a new project with the C18 compiler. For the most part things are going well, but I have ran into a few glitches that I cannot figure out.

One small thing that I can't figure out is that everytime I compile I get:

"Warning [2058] call of function without prototype"

Even though the function being called does have a prototype. For instance, on the line where the function initializeLCD() is called, it gives me that warning, however in my header file I have the line:

void initializeLCD();

and the header file is included in the project. Anyone know what the deal with this is?

Also, I can't seem to get pointers working in C18. I am trying to have a globally addressable array of text that I can read to or write from any function. Any attempt at this has failed. Here is a snippet of where I define my variables:

Code:
char dataArray[] = "Text Array";
char *pData;

void main (void)
{	
	OSCCON = 0b01110000; //8MHz Clock
	pData = dataArray;
Then in a later function I set:

pData = "Testing";

But when I try to pull up pData[0] I get a 0 instead of a T. Also, dataArray is still equal to text array. I've tried a combination of & and * but I just can't seem to get it. Any help would be greatly appreciated!
Fred.Amoson is offline  
Reply With Quote
Old 2nd April 2008, 11:31 AM   (permalink)
Default

Quote:
Originally Posted by Fred.Amoson
I am working on a new project with the C18 compiler. For the most part things are going well, but I have ran into a few glitches that I cannot figure out.

One small thing that I can't figure out is that everytime I compile I get:

"Warning [2058] call of function without prototype"

Even though the function being called does have a prototype. For instance, on the line where the function initializeLCD() is called, it gives me that warning, however in my header file I have the line:

void initializeLCD();

and the header file is included in the project. Anyone know what the deal with this is?
Use the 'void' type when you declare functions with no arguments; that should fix the problem.

Code:
void initializeLCD(void);
eng1 is offline  
Reply With Quote
Old 2nd April 2008, 12:27 PM   (permalink)
Default

Thanks, that fixed the first problem!
Fred.Amoson is offline  
Reply With Quote
Old 2nd April 2008, 08:40 PM   (permalink)
Default

Quote:
Originally Posted by Fred.Amoson
...
Also, I can't seem to get pointers working in C18. I am trying to have a globally addressable array of text that I can read to or write from any function. Any attempt at this has failed. Here is a snippet of where I define my variables:

Code:
char dataArray[] = "Text Array";
char *pData;

void main (void)
{	
	OSCCON = 0b01110000; //8MHz Clock
	pData = dataArray;
Then in a later function I set:

pData = "Testing";

But when I try to pull up pData[0] I get a 0 instead of a T. Also, dataArray is still equal to text array. I've tried a combination of & and * but I just can't seem to get it. Any help would be greatly appreciated!
It's a Ha'va'd architecture man. There are two memory types. Program memory is as wide as the instruction word and techniques vary as to how a "constant character string" is packed into program memory. Then there is data memory which is as wide as the registers, typically 8 bits. Now a pointer to a constant character string in Program memory is a very different animal from a pointer to a character string in data memory.

I would look for keywords that help the compiler determine what kind of memory the pointer is pointing at.

I went to Princeton and we treat all memory the same. We don't have such problems.
__________________
We never have time to do it right; but we always have time to do it over.
Papabravo is offline  
Reply With Quote
Old 3rd April 2008, 01:50 AM   (permalink)
Default

Thanks for the info Papabravo, that helps a lot, I will post back when I figure it out!
Fred.Amoson is offline  
Reply With Quote
Old 3rd April 2008, 02:04 AM   (permalink)
Default

Pointers on a pic are one of the most confusing things I've come across. The only way to get a string from ROM into RAM is to copy it manually.

Here's my understanding of how to manipulate strings.
Code:
ram char dataArray[20]="Test Data";
ram char *pData;

//copy string from rom to ram.
void SetString(ram char* RamString,rom char* RomString){
    do{
        *RamString++=*RomString;
    }while(*RomString++!=0);
}

//in main you can then have,
static rom char HW[]="Hello world";

//You can then do,
    SetString(dataArray,(rom char*) "Hello World");
//or
    SetString(dataArray,HW);

//you can also do,
    pData=dataArray;
    chr=*pData;
    SetString(pData,(rom char*) "Somert else.");
You have to remember that the compiler wants (has) to treat all strings as constants and stick them in ROM.

Mike.

Last edited by Pommie; 3rd April 2008 at 08:27 AM.
Pommie is offline  
Reply With Quote
Old 3rd April 2008, 08:25 AM   (permalink)
Default

So are "ram" and "rom" the keyword qualifiers in the C18 compiler?
__________________
We never have time to do it right; but we always have time to do it over.
Papabravo is offline  
Reply With Quote
Old 3rd April 2008, 08:27 AM   (permalink)
Default

Quote:
Originally Posted by Fred.Amoson
Thanks for the info Papabravo, that helps a lot, I will post back when I figure it out!
No problem -- glad to be of assistance.
Good Luck
__________________
We never have time to do it right; but we always have time to do it over.
Papabravo is offline  
Reply With Quote
Old 3rd April 2008, 08:47 AM   (permalink)
Default

Quote:
Originally Posted by Papabravo
So are "ram" and "rom" the keyword qualifiers in the C18 compiler?
Kind of, there are actually four different types of pointer, and there not interchangeable.
near rom
far rom
near ram
far ram

But generally you can just use rom and ram.

Mike.
Pommie is offline  
Reply With Quote
Old 12th April 2008, 11:45 PM   (permalink)
Default

Thanks a lot Pommie, your code has really saved me a lot of time. I would have never figured that out.
Fred.Amoson is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
C18 compiler. struct issues. HerbertMunch Micro Controllers 7 31st December 2007 01:43 AM
Problem setting up timer Interrupt using C18 compiler elec123 Micro Controllers 4 14th November 2007 10:59 AM
Best Pic Basic Compiler ... simrantogether Micro Controllers 12 29th October 2007 07:51 AM
Compiler for pic PicForge info ? ZEPHIR Micro Controllers 0 23rd October 2007 08:35 AM
Hash Function for PIC pikstart Micro Controllers 15 8th September 2007 01:07 PM



All times are GMT. The time now is 08:05 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.