+ Reply to Thread
Results 1 to 8 of 8

Thread: C18 pointers

  1. #1
    tresca Good tresca Good
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    194

    Default C18 pointers

    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 ?


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,808

    Default

    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 by Pommie; 11th May 2009 at 12:33 AM.

  3. #3
    tresca Good tresca Good
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    194

    Default

    Brilliant. Made the changes you suggested and it works.

    Thank you.

  4. #4
    tresca Good tresca Good
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    194

    Default

    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 ?

  5. #5
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,808

    Default

    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.

  6. #6
    tresca Good tresca Good
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    194

    Default

    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().

  7. #7
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,808

    Default

    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.

  8. #8
    tresca Good tresca Good
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    194

    Default

    I figured out the glcd part ( at least a work around to make me happy). Now I'm stuck on the actual one wire part.

    1wire DS18B20

+ Reply to Thread

Similar Threads

  1. pointers
    By aamirkhan in forum Micro Controllers
    Replies: 2
    Latest: 13th June 2008, 07:18 PM
  2. Two laser pointers
    By cannibal in forum Electronic Projects Design/Ideas/Reviews
    Replies: 28
    Latest: 24th October 2007, 04:14 PM
  3. Need some pointers please
    By compunerdy in forum Electronic Projects Design/Ideas/Reviews
    Replies: 3
    Latest: 4th February 2006, 08:23 AM
  4. Why use pointers?
    By The Real MicroMan in forum Micro Controllers
    Replies: 13
    Latest: 8th September 2005, 01:39 AM
  5. Pointers in PIC?
    By RawTechie in forum Micro Controllers
    Replies: 2
    Latest: 6th June 2003, 08:05 PM

Tags for this Thread