Continue to Site

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.

  • 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.

C18 pointers

Status
Not open for further replies.

tresca

Member
I'm having the hardest time figuring out how to use pointers properly in c18.

What im trying to do is pass a pointer from a char array and read the value.

Code:
void write_lcd(char *str)
{
		char *newstr;
		int x=0;
		unsigned char y=0;
		
		int length;
	//	length=strlen(*str);
		strcpypgm2ram(*str,*newstr); //rom to ram
		while(*str)
		{
			for(x=0;x<8;x++)
			{
				y=&newstr;
				write(Font[y][x]);
			}
			str++;
		}		
	
	
}


Now my test string is
Code:
const rom char  test[]="hello world";

I keep getting a type mismatch error and a few suspicious pointer conversion warnings.
I dont see the mismatch though. Is what I'm doing really wrong ?
 
You're passing a rom pointer and your function expects a ram pointer. Change your function to,
Code:
void write_lcd(rom char *str)
There is no need to copy it to ram.

My routine to do the same (but for a character LCD) is,
Code:
void PutMessage(rom char *Message){
    while(*Message)
        WriteChar(*Message++);
}

Mike.
 
Last edited:
So I got this glcd, and im just playing around with it. I did note some strange behaviour. When I write a message, to each page (using only CS1), I see periodic ribberish on CS2 side. An example of such would be

| || | || | || | || <-- repeating on each line

I am using an ICD2 to program this, and when I hit reset, and try the program again, the a few of those lines vanish. I keep doing it about 5-6 times, all the lines disappear and I'm left the message I SHOULD see.

Any idea on whats causing the jibberish ?

A little history on this GLCD. It came from a company I used to work for. I think they were in the process of removing all lead equipement, components and what not, because they threw away alot of stuff. I managed to score some LCDS before a truck came and picked up the 'trash'. This is brand new because it is packaged, and makes me wonder why they threw it away, maybe they dont need it anymore for future products or maybe it was part of a bad batch (ie. these lines).

thoughts ?
 
This sounds like a KS0108 controller. If it is then you have to wait for it to be ready by checking the busy flag. Are you doing this? A simple test to see if this is the problem would be to insert a few ms delay after every write and see if the lines go away.

Mike.
 
That was it, I put a 50us delay between the writes and that fixed it up. I got everything working now as I want.

Thanks !

But now a new problem....

....So far, when playing with the GLCD, I've had my strings in program memory.

I'm trying to use a 1wire device, and trying to translate my value into a string.

I've tried using itoa to convert it to a string, but I keep getting the same error.

Code:
Error [1109] type mismatch in redeclaration of 'write_lcd'

My code

Code:
void write_lcd(unsigned char xPos, unsigned char yPos, rom char *str);
Code:
rom char tempLow;
rom char tempHigh;

Code:
void onewire_ConvertT()
{
	int temperature;
	int tempL,tempH;
	int temp;
	onewire_reset();
	onewire_write_byte(skipRom);
	onewire_write_byte(convertT);
	delay500ms();
	onewire_write_byte(readScratchpad);
	tempL=onewire_read_byte();
	delay1us();
	tempH=onewire_read_byte();
	delay1us();
	tempLow=itoa(tempL);
	if(onewire_reset()==0)
	{
		write_lcd(0,4,tempLow);
               write_lcd(0,5,tempHigh);
	}	
	
	
	
	
	
}



The code as it stands probably will not work, as its incomplete and im still pouring over the datasheet for timings. I would just like to know how i can go about converting an int to a string so that I can use it with my write_lcd().
 
Well, first of all, you can't write to a ROM variable. Get rid of the ROM directive and it may work. I've had far too many beers to make sense of your code. Maybe tomorrow.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top