Programming using C

Thread Starter


Joined Jan 4, 2009
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.



Joined May 16, 2005
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.


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

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.


Joined Jan 9, 2009
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)

int main(void) {
while(1) {
else {

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


Joined Jan 27, 2009
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:

Microchip forum:

Thread Starter


Joined Jan 4, 2009
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