PIC programming

Hey,
I have searched and searched but cannot find any real definitive site that goes over the basics for programming a PIC in C++. I have found sites that tell me how to program in C++ (like this lovely site), and sites that have some example code (in C usually), but nothing that goes over, say, defining bits for PICs and the syntax of, for example, turning an I/O port from on to off. Can anyone direct me to a good site? Thanks in advance!
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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++, and may have to use C. I keep running into examples that use C in PIC programming, so if you know that C++ won't work please let me know. 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.

Again, thanks for any help you could offer.
Last edited on
I haven't programmed a lot is a PIC but I think that working with C is enough. After all you need just a way to implement assembly with your PIC so C would do just fine.

I used to program in assembly but in C it should be more fun and more easily. Anyway in assembly setting and clearing bit was easy so I guess you have to find the necessary command. Have you read the manual of your PIC? You need extra information? If you have caught the mentality of programming a microprocessor you can do a lot of things if you have some imagination.

The site of Microchip is not satisfactory enough?
http://www.microchipc.com/
Well, I read the datasheets for the PIC and there wasn't much of anything on the commands to set the various ports up. Especially on how that relates to C. I may be posting in the wrong forum. Anyway, again, any help would be wonderful.
Last edited on
Topic archived. No new replies allowed.