Programming using C

Thread Starter

PANSONNIC

Joined Jan 4, 2009
15
Does anyone know of a good web site where I can learn how to programme in C.
I am trying to programme a PIC microchip. I want the device to illuminate an L.E.D when an ultrasonic signal (sonar) detects an object.

Can anyone help. Any response will be much appreciated.

Pansonnic
 

thingmaker3

Joined May 16, 2005
5,083
And so we move it to the Embedded Systems Forum.:) I'm curios to know the answer to this one myself. C is a tool I don't have in my toolbox yet.
 

mik3

Joined Feb 4, 2008
4,843
If you want to learn the basics of C++ have a look here:

www.cplusplus.com

To learn programming a PIC with C it's a different story. You might use C to write the code but you need to define other things related to the operation of the PIC too. Search in google for PIC C tutorials.
 

Skeebopstop

Joined Jan 9, 2009
358
In this simple application you will just want a comparator toggling a digital input from your sonar signal. You can poll that input to detect when triggered and set a digital output to illuminate LED all in your main loop.

On a PIC you should get away with driving one LED directly, don't go stringing 3 or 4 up or you'll burn it up, unless lower power LEDs limited to a few mA, rather than the normal 20-30mA.

#define LED_ON (GpioDataRegs.GPIOSETA.GPIOA1 = 1)
#define LED_OFF (GpioDataRegs.GPIOCLRA.GPIOA1 = 1)
#define SONAR_INPUT GpioDataRegs.GPIODATAA.GPIOA1

int main(void) {
while(1) {
if(!SONAR_INPUT) {
LED_ON ;
}
else {
LED_OFF ;
}
}
}

Just using TI DSP notation here, hopefully you can read between the lines of the different chipsets register sets.
 
Last edited:

Dutar

Joined Jan 27, 2009
13
Depends on the type of PIC you wish to use. If you are using dsPIC's I think the best option is to go for the C compiler by MICROCHIP. If you know some c programming, just spend couple of hours on the programmers reference manual to get familiar with inbuilt functions. The fully functional student version is free, and the only difference from the commercial version (about 500 USD) is after 90 days some optimizations disappear. But with large programming memory available with them (such as 128k in a chip that costs around 7USD) this is realy OK.

Link for compiler:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en534868

Microchip forum:
http://forum.microchip.com/
 

Thread Starter

PANSONNIC

Joined Jan 4, 2009
15
I want to be able to drive to L.E.D's in various sequences.

e.g flash L.E.D 1 on then two seconds later flash L.E.D 2 on. Then change the sequence so they both come on at the same time.

Thanks for your help
 
Top