NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Modifing C code without knowing C

March 25, 2010
by n3ueaEMTP
n3ueaEMTP's Avatar

OK, sorry about the title, I really didn't know what else to call it. What I would like to do is create a program (for a PC) that can modify variables in my C code. My ongoing project is a Personal House System, a device that alerts volunteer fire fighters to emergency calls by sounding a bell & turning on some lights {it's at the patent office as I type :)}. What I want to be able to do is give the end user the ability to change the duration of the bell and the lights. Most hand held radios today are PC programmable and I want to be able to give users the ability to reprogram my device as well. Python and I don't really seem to get along well, I'm not sure what I'm doing wrong. Does anybody have any ideas how I can accomplish this? Thanks.

Chris B.

n3ueaEMTP

March 25, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Chris B.

I'm glad to see you are blazing ahead with your project. I'm not sure about what you are envisioning when you say allowing people to change your C variables. I suppose it would be possible to write a program in C that would go edit the C file that runs on your MCU. The user would then have to recompile and reupload the code. That seems like a dangerous thing, in general I would not allow an end user to completely reflash an end product.

I think a good solution here would be to store these configuration values on the EEPROM on the chip. You could then have a "reprogram mode" on your MCU maybe toggled by a switch, that would listen over the serial port for new values from the computer. The program that sends the values could be written in any language.

Humberto

March 25, 2010
by Chaosrider
Chaosrider's Avatar

I don't know if this will clarify anything but here goes.

The process that happens when you upload the code to your MCU is that the C file is compiled on you PC into a binary object file wich is mixed in with other objects to make your program wich is stored in a hex file if I remember right(basically at this step, it is more or less similar to assembly). Then it is this uploaded via the cable to the MCU via the bootloader in the NERDKIT case.

As stated, to change a variable, you should have your program handle it thorugh the serial port. Sending the program again is not a good practice and would allow users to have access to the whole code and possibly brick the device(from their point of view) the system.

Post a Reply

Please log in to post a reply.

Did you know that reading a double floating point variable with scanf requires "%lf" for "long float"? Learn more...