|
I am a professional programmer (for about 40 years now) and I would like to put you on the right track.
The main goal for a good program is not "It Works!". If it doesn't work, its not a program at all, a piece of wood doesn't work eather.
So what are the kriteria for a "good" program?
Here are some of mine:
Cheap - Programmed and tested in a short time
Cheap - Re-usable code from former projects
Cheap - Flexible programming adopts easily to different hardware
Cheap - Make the program human readable as much as possible
You can add yours here...
Reading directly in your program from a specific pin violates some of the above kriteria, saving the initialization part has the downgrade that there IS NO initialization part. HAVING an initialization part makes it easy to pre-check some external situations before the program really runs (or deny the running with an error-message.
All my PSoC-programs have the following structure which make it easy to look up, control or change the appropiate part:
Title of the Program, date, version and what it should perform
#includes
#defines
Global Variables (but only a few!)
void InitializeHardvare(void
{
Yes, exactly that, nomen est omen...
}
void main(void)
{
InitializeHardware();
Here goes the initialization of the software
while(forever) // #define forever 1 helps readability
{
The main task, normally calling some functions defined in other files
}
// NO FINALIZATION, forever is forever, this code will never be reached
Happy coding
Bob
|