Need help with my program

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

Reply to
DarkKobold
Loading thread data ...

DarkKobold scribbled the following on comp.lang.c:

Reply to
Joona I Palaste

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.

Reply to
Not Really Me

Yes you can, it's static. See

formatting link

Ed.

Reply to
Ed Morton

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
Reply to
Peter Bennett

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
Reply to
Eric Sosman

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.

Reply to
Ben Bradley

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.
Reply to
Not Really Me

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.