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.

Help w/ C code.. how to clear array pointer buffer?

Status
Not open for further replies.

DanD

New Member
Hey all,

I have thoroughly confused myself. I am working with the code below:

Code:
void displaySensor(int address, char typeChar, int sensVal){
	char tmpString[5];
	
	WaitXLCD();
	SetDDRamAddr(address+6);
	WaitXLCD();
	putsXLCD(itoa(sensVal,tmpString));
}


The function displaySensor is repeatedly called from another function called from an infinite loop in main(). Basically main calls goSensor() which collects the data from the ADC and then goSensor() calls displaySensor to display the value on the LCD. sensVal is reinitialed and then reset in goSensor().

If i call goSensor() once, (outside of the main loop) it works fine. However, when i call it repeated i get some junk on the screen after the first call. So it seems to me like i need to reinitialize something.

itoa is a C18 function which converts the integer, sensVal, to a string, tmpString, and returns a pointer to this data. putsXLCD() then displays the buffer at this pointer location. I think this pointer location is getting messed up or something.

Can you guys think of a better way to do this or a way to tidy it up to avoid data corruption?

Thanks a lot
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top