Need help with my program

Oct 16, 2003 7 Replies

I am writting a keyboard emulator for the pic microcontroller. Unfortunately, after watching it on the oscilliscope, it is not transmitting the right data. The clock signal on B1 is working correctly, however, the actual data part is not. I've included this short snipet, and the entire program, so anyone can peruse my work. Thanks for any and all help.



for (i = 0; i


DarkKobold scribbled the following on comp.lang.c:

Also, it appears that y is uninitialized when it is first used. It needs to have a value before you use it the first time. You can't assume that it starts at zero.

Yes you can, it's static. See

formatting link

Ed.

However, you want y to start at 1, so you still need to initialize it immediately before entering the for() loop.

Peter Bennett VE7CEI GPS and NMEA info and programs: http://vancouver-webpages.com/peter/index.html Newsgroup new user info: http://vancouver-webpages.com/nnq

The initialization did not appear in the extract at the top, but you'll find it right there in plain sight if you read the "complete" code later in the message.

Eric.Sosman@sun.com

I don't trust compilers to initialize variables, even if they all do. This code snippet is one good reason not to rely on the "but it's initialized!" feature. The variable y gets initialized to the wrong value and the program still won't work. Variable y should be explicitely initialized to 1 for the program [or at least this code snippet] to work properly. If it's 0 (as the compiler sets it), it will stay at 0 even with the y = Ed.

You got me there. I did not read the full code. I see enough awful code all day long doing software testing for safety critical apps. I just couldn't bring myself to continue. Sadly it looks like all too much of the "production" code that customers submit for validation.

Scott Validated Software Corp.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required