problem with getch loop

Programming, for all ages and all languages.
Post Reply
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

problem with getch loop

Post by kubeos »

Here's my code:

Code: Select all

int getch()
{
	char timewaster[5];
	result=0;
	do{
		result=asckey;
		if(result!=0)
		{
			asckey=0;
			return result;
		}
		//memset(timewaster,0,5);
	}while(1);
}
Now, it works fine when the memset line is UNCOMMENTED.. but when I do comment it out.. it doesn't work? Does anyone who is good with C have an idea?

PS. asckey is in my kb isr, which seems to be fine.. if you want me to post that too.. i will. result and asckey are both global vars.

Thanks for any replies.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Try making asckey and result volatile.

ie

Code: Select all

volatile int asckey;
etc.
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

yes

Post by kubeos »

Wow, that fixed it... thanks!!

I'll have to see if there's a parm that I can pass to gcc to stop optimizations.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Try

Code: Select all

-O0
Post Reply