PDA

View Full Version : Does my code need tidying up?



davewanna
- 10th December 2007, 03:33
Hi all,

I'm very new to Pic's, but I have a PHP & MYSQL coding background, and a fair bit of basic coding quite a long time ago. Also I'm a plasma and LCD TV tech, so the electronics side of things isn't too much of a struggle yet.

My project below is going to control air-conditioning in my car, and also show some stats like batt voltage etc but is far from finished. So far I have the voltage measurement working right (and adjustable for different voltage divider networks via the 4 buttons and LCD)

Also the TPS (throttle position sensor) is adjustable for different cars (throttle low - press butdn, throttle high - press butup - it then scales to 0 - 100%)

working on air temperature, but only have a very non-linear sensor currently, and will get something nicer like the BS1820 (i think?) before I convert it to degrees. (butdn records the current voltage and sets it as minimum.)

This is really my first effort at pic programming and I am completely self-taught... Just wanted to get some opinions on if there is better ways of doing things... So far my code works fine but I feel it's quite 'messy'.

Ignore any PWM stuff for now I was just testing it on a small motor... I will get round to speed regulating the thermofan based on speed/temperature/etc later.



Also I should add I have a 2-line LCD in 4 bit mode hanging off a 16F877A

Thanks in advance.

bearpawz
- 17th December 2007, 16:39
At a first quick glance it looks ok. The only recomendation I would make is to put more documentation in the code with coments on what lines do what. It may seem to make sense at the moment, but a few years from now if you ever had to go back to it you will probably be scratching your head wondering what you were doing. (Been there, done that).

davewanna
- 18th December 2007, 01:12
Thanks bearpawz,

It's been a steep learning curve for me... The forum has proved to be an invaluable resource. Just last night I managed to finally get my data to store and retrieve nicely from an external eeprom by reading the many eeprom problem threads on here. Turned out my whole issue was I had the control declared as a word, not a byte.

What you say about commenting the code is a very good point. I will endeavor to do that more.

Archangel
- 18th December 2007, 19:55
What you say about commenting the code is a very good point. I will endeavor to do that more.

Hi davewanna,
Do yourself a huge favor and do it to this code right away, while you still have direct knowledge as to what every line does, also add notes as to what did not work, so 6 months from now you will not have to reinvent the wheel.
JS