Re: Global Variables Being Overwritten
- From: "Steve at fivetrees" <steve@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 May 2006 21:53:27 +0100
"jgurtner" <jgurtner@xxxxxxxxxxx> wrote in message
news:1148964547.983744.326300@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is there a better way of doing this:
LCDWrite("This is a test");
void LCDWrite(char *buffer)
{
while(*buffer) /* loop until buffer is empty */
{
PortC = *buffer; /* write data to LCD data port */
LCDEnable(); /* clock the LCD to accept data */
buffer++; /* increment the pointer to the next character */
}
}
This works fine but it seems that if I use this function a too many
times it starts to overwrite some of my global variables I have
declared in "main" for an interrupt routine I am using.
The above was written in C with Code Warrior for use on an 8 bit
Freescale 68HC08 microcontroller.
It should be fine - unless there's something in LCDEnable() that's doing it.
The code you're showing has precisely one variable that gets written to
(char *buffer), and that's an automatic variable. I'm also assuming that the
definition of "PortC" has no side-effects.
Some suggestions:
- Check your stack placement. Make sure it's not colliding with data
space.
- Look for instances of incrementing write pointers (the above is an
incrementing read pointer). Be sure you're ending where you think you are.
- If you have a debugger, watch the variables that are getting hit to
narrow down what's clobbering them.
In other circumstances, I'd also say "avoid global variables", but a bug
like the one you describe is a bug - it'd still break something.
HTH,
Steve
http://www.fivetrees.com
.
- Follow-Ups:
- Re: Global Variables Being Overwritten
- From: jgurtner
- Re: Global Variables Being Overwritten
- References:
- Global Variables Being Overwritten
- From: jgurtner
- Global Variables Being Overwritten
- Prev by Date: Re: what's wrong with a pic ?
- Next by Date: Re: Logic Analyzer Vs. Oscilloscope
- Previous by thread: Global Variables Being Overwritten
- Next by thread: Re: Global Variables Being Overwritten
- Index(es):
Relevant Pages
|