Programming using C

Discussion in 'Embedded Systems and Microcontrollers' started by PANSONNIC, Jan 22, 2009.

  1. PANSONNIC

    Thread Starter Member

    Jan 4, 2009
    15
    0
    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
     
  2. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
  3. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    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.
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  5. PANSONNIC

    Thread Starter Member

    Jan 4, 2009
    15
    0
    Thanks for your help.
     
  6. Skeebopstop

    Active Member

    Jan 9, 2009
    358
    3
    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: Jan 26, 2009
  7. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
  8. Skeebopstop

    Active Member

    Jan 9, 2009
    358
    3
    ick, my formatting got lost :(
     
  9. Dutar

    Member

    Jan 27, 2009
    13
    0
    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/
     
  10. PANSONNIC

    Thread Starter Member

    Jan 4, 2009
    15
    0
    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
     
Loading...