I am somewhat new to programming, and very new to C. I have been teaching myself C++, and have learned that it's inapplicable to my PIC project. I need help with a project that is pretty in nature and I think I am pretty close to getting most of the code, at least intellectually.
Ok, so to give you an idea of what I am working on, I am trying to build a circuit that will turn a fan on for a specified amount of time. The circuit will incorporate a rotary switch, a general on/off switch, and, of course, the fan. The following code is what I have so far, any and all comments and insight would be appreciated.
Code:#include <iostream> void main () TRISA=0 // not really sure which pin this turns to output, // but it needs to be the one the fan is connected to // and I also need to know how to turn the ports // the rotary switch is connected to to input PORTA=1 // this feels wrong, but I need to have the Vcc pin turned to input // so I can regulate it with a switch in the circuit if PORTA=1 { if PORT1=1 // this is the port that the first pin of the rotary switch is connected to { delay_ms(6*10e3) // one minute of fan time, and I know the delay cmd is wrong, // but is there something similar that will turn the port } // on for x amount of milliseconds? else if PORT2=1 { delay_ms(12*10e3) } // here the 'on' time would be for two minutes else if PORT3=1 // this syntax may be wrong to designate the RA1-7 ports, // but it's the best I can do for the moment { delay_ms(30*10e3) //five minutes this time } else if PORT4=1 // you get the idea.... } return(0)
I know there is a bunch I am leaving out, but it feels close to right, but am not sure how to phrase it properly in C. Also, it would be nice to use the switch/case cmd to clean it up a bit, but the if/else if works for now. I have read the datasheets for the PIC I am using, and a reviewed a bunch of websites that have example code in C, but have yet to find a definitive source for specific command use for programming PICs. By the by, I am using a p16f88 uC.
Thanks for any help you could offer.



4Likes
LinkBack URL
About LinkBacks
. I need help with a project that is pretty in nature and I think I am pretty close to getting most of the code, at least intellectually. 



