PICs: Where to start....?

Discussion in 'Embedded Systems and Microcontrollers' started by DerStrom8, Apr 2, 2011.

  1. DerStrom8

    Thread Starter Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Good day, everyone!
    I recently started playing around with programming PICs in MPLAB IDE. I have written a couple of very simple programs in Assembly that flash LEDs in specific patterns, but I would like to be able to do more than that. I just bought a PICkit2 and a couple of PIC18F1330s and downloaded the C18 compiler from the Microchip website. So, here's my question: What should I do next? I would like to learn C, but I have yet to find a full C tutorial for an 18F uC. I am also somewhat clueless as to the circuitry needed to program the chip, namely the oscillator, power supply, etc. I know that the PICkit2 is capable of ICSP, which I plan to use, and I would like to have the target chip on my solderless breadboard so that I can do some prototyping. So, can anyone point me toward a good C tutorial and some basic setup circuits for my uC?
    I thank you for any help in advance. I appreciate it.
    Best regards,
    Der Strom
     
  2. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Hi there,

    Have you actually programmed a chip and set it up working? If not, do that with the LED flash programs you've made before you do anything else.

    I can't help you with C as I've just started out a few days ago and have been making LEDs flash with asm too :)

    As for a basic circuit — you've chosen a PIC well, as it doesn't have too many pins and has an internal oscillator. For the circuit, try this (assuming you have 18 pin model — if other, see datasheet):

    +V -> Pin 14
    Gnd -> Pin 5
    +V needs to be connected to Pin 4 (MCLR), I suggest via a diode so that the higher ICSP voltage that's applied to that pin during programming doesn't affect the rest of the circuit.

    Oh, and don't forget the 0.1uF (104) capacitor between +V and Gnd.

    If you set up the internal oscillator correctly, that should be a fairly effective base circuit. If I've forgotten anything I'm sure others will fill in. I have only been doing this for 5 days!

    Thanks, good luck,
    Barnaby
     
  3. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    761
    Keep in mind that the data sheet has to be with you all the time.
     
  5. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Agreed! And make sure you know what all the pins do.
     
  6. someonesdad

    Senior Member

    Jul 7, 2009
    1,585
    141
    Go find the PICDEM Lab tutorial on the Microchip website; I think it is part number 41369A (at least that's the number on my copy). It has some C code lessons in it. When a friend visited, we did the last lesson in the book and it worked well.
     
  7. DerStrom8

    Thread Starter Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Thank you all very much for the replies!

    I have not yet been able to actually program the chip. I did not completely understand how to set up the oscillator, etc., hence this thread.
    Thank you for all the connection information. It will help a lot :)

    That looks very useful. I'll have to read that soon. Thanks!

    I have already downloaded the datasheets and put them in a specific folder on my computer, so they will always be right there when I need them. :)

    Thank you, someonesdad. I will have to look that up.

    I appreciate everyone's help in this matter :)
    Best regards,
    Der Strom
     
  8. BillO

    Well-Known Member

    Nov 24, 2008
    985
    136
    Okay, here's a project for you. Build a programmable function generator.

    Pick one of two methods, function maps or better still, inverse furrier transform and composite sinusoids.

    Get it right and you could sell the design.
     
  9. DerStrom8

    Thread Starter Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    :D Thanks, BillO, but I'm still trying to build the circuit so I can program the chip! :D Maybe I'll be able to find some time to think about it, but there are no guarantees ;)
    I appreciate all the help, everyone!
    Der Strom
     
  10. mjhilger

    Member

    Feb 28, 2011
    119
    16
    If you would like to learn "C", C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie (Apr 1, 1988). These guys invented the language. Their original book "C" is the best one, but you will probably have trouble finding it for any better price than the one I have listed. I only have the original book, which is not very many pages, maybe 140 or so. It describes the language philosophy and is very concise. The main language has very few built in functions. The functions are compiler specific, though ANSI C has many predefined which are included in all ANSI C compilers. The C18 users manual/reference guide lists the functions specific to the PIC18 chips, Timers, ADC, PWM, etc. You will still need your specific chip users manual for certain information.

    My suggestion is once you have written and programmed your basic LED blinking program, implement interrupts and a timer. One of the example programs included with the C18 is one for this purpose. I find that implementing a timer tic of 1mS, 5mS, or 10 mS is very handy for many purposes. You can then set a global variable (defined outside main()) which you can set in the main program loop to a value and decrement down to 0 in the interrupt. You can check each loop within main to determine when your timeout has occured without using a delay routine. This allows processing to continue with other tasks while waiting.
     
  11. BillO

    Well-Known Member

    Nov 24, 2008
    985
    136
    Have you considered a PICAXE to get you started? No support hardware needed to get going and the BASIC like language will introduce you to to the concepts in an easy and intuitive way. I built a PICAXE 08M experimenter board for my son the other day. Took 4 hours from concept to final product. If your interested I could pass some info on to you. It was so simple I did not even create a schematic, but a picture of it and a description might help you get started.

    Just let me know.
     
  12. DerStrom8

    Thread Starter Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Sorry I haven't replied in a while. I've been perusing several different tutorials, and have gotten enough information to set up my programmer and target chip. I have successfully programmed the chip several times, with a simple LED flasher, 4 LED chaser, and am currently working on audio modulation. I thank you all for your help!
    Best regards,
    Der Strom
     
Loading...