help with programming please


(this request is a duplication of the newsgroup alt.microcontrollers !!!)
Hi,
I'm having trouble getting my head around programming a pic (from scratch)
Basically i want it to do :-
Loop
look at 3 inputs (not analogue)
compare with the inputs that were stored in the last loop around
if they are the same wait say .5 sec
then loop again
if the inputs are different then output (for a relay) for .5 sec
this project, i thought would be fairly easy or so i thought.
Anyone willing to help me write a program if it is that easy.
Any help would be most appreciated or am i getting too old for this
technology !!
Andy Sutton
Reply to
Andy Sutton
Loading thread data ...
Andy,
Maybe specify in more detail what you need help with:
- programming itself
- the programming language you intend to use (you didn't specify)
- (the pic) microcontrollers (setting up I/O etc)
- technical aspects of getting your program compiled and onto the pic
- all of the above :-)
Unfortunately, I'm not familiar with the pic as a microcontroller nor the BASIC language that is often used to program it, but I decided that won't keep me from trying to help :-)
Your main loop, in a C-style language, could look something like this:
int main(void) { InitializeHardware(); int previousBits = 0; int currentBits = 0; int firstTime = 1;
for(;;) { currentBits = GetInputs();
if(currentBits != previousBits) { if(!firstTime) { ActivateRelay(500); } } else { MsDelay(500); } firstTime = 0; previousBits = currentBits; }
return 0; }
Disclaimer: this is from the top of my head and untested in any way, form or fashion.
I'm assuming that you do NOT want to trigger on the first time around in the loop, since there is no known/specified "previous value". If there is, remove the firstTime variable and its if statement (but not the call to ActivateRelay), and initialize previousBits to that specified inital value.
I've left out the pic-specific bits above - InitializeHardware should set up your three inputs as such, and the relay bit as output.
GetInputs should read from the port where your three inputs are connected. (I assume they are connected to the same port)
Make sure that you filter out any other input lines on that same port by using the AND operator and a bit mask. In C, assuming your inputs are on e.g. bit 0, bit 4, and bit 7 of an 8 bit port, you'd do something like this:
int filterMask = (1
Reply to
Gilles Kohl

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.