1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

[Help] Starting to use PICs

Discussion in 'Microcontrollers' started by amando96, Jul 19, 2010.

  1. amando96

    amando96 Guest

    Hi, been in the world of micro controllers for little over a year, been programming only arduinos so far, but I want to start using PICs
    I bought myself a PIC 16F628, I followed this tutorial to build a programmer, I have a serial port on my old XP computer.
    I intend to download Mplab.

    Now, Are all these compatible with each other? can that PIC be programmed with that programmer, and can that programmer be used by that software?

    Also, is this wiring perfectly correct just to test if it's working with this code?
    [​IMG]

    Also, any other things to take into consideration before attempting to burn the code?

    Thanks a lot.
     
  2. Aussie Susan

    Aussie Susan New Member

    Joined:
    Jan 5, 2010
    Messages:
    52
    Likes:
    4
    I've no experience with that PIC programmer, but I would recommend that you consider buying the PICKIT 2 (or 3) programmer (or clone - there are several versions around, some in kit form, others already made up). They are really not that expensive and they will let you program all sorts of PIC devices as your experience grows. Also it lets you debug the program through the MPLAB software as well as program the device.

    Also, this will let you think about the PIC itself and you programming, not your programmer, when things go wrong (as they always do - its the "fun" part of the learning curve)!

    Susan
     
  3. colin55

    colin55 Well-Known Member

    Joined:
    Feb 14, 2009
    Messages:
    3,534
    Likes:
    82
    Location:
    Melbourne Australia
    The article mentioned above is very difficult to follow.
    Here is a circuit diagram of a simple PIC programmer using just 12 parts:
    [​IMG]
    Or you can make a USB programmer for less than $25.00
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA

    Neither of the serial port programmers shown in this thread will work with MPLAB. I am with Susan on this one. For $35 you can buy a picKit2 from MicrochipDirect. It also acts as an In Circuit Debugger (for testing) and a simple logic analyzer.

    Collin you know that programmers using the serial port to generate VPP are a crap shoot. If you are going to suggest one how about a design with an external VPP supply. It may take a bit of effort to scrounge a 12V wall wart or other supply but it would be worth not having to mess with methods used to get 12V where not exists.
     
  6. amando96

    amando96 Guest

    The picaxe software has a PIC programmer, it doesn't program only picaxes apparently, i'll try to use that too.

    The other option is Winpic.

    I really can't afford a pickit right now.
     
  7. colin55

    colin55 Well-Known Member

    Joined:
    Feb 14, 2009
    Messages:
    3,534
    Likes:
    82
    Location:
    Melbourne Australia
    I have programmed hundreds of PIC chips with a simple programmer and not had any trouble.
    I also have a USB programmer as mentioned above. You can build the simple programmer and burn an 18F2550 for the USB programmer. Even the PICkit2 constantly can't find the chip and fails to program. I don't know where the fault lies with the PICkit2.
    I think my USB programmer is about 50% better than the PICkit2 and I am using it constantly now. The PICkit2 is far better than the serial-port programmer in performance and feedback. It recognises the chip for a start.
    I think Microchip charge $15.00 shipping for the programmer.
     
    Last edited: Jul 20, 2010
  8. amando96

    amando96 Guest

    I might be just delirious, but would it possible to program them with this It would be quite cool...

    A USB programmer would be simpler, wouldn't need two machines to be on simultaneously.
     
  9. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Collin you need to look past your own personal experience and think about the problems other people have.

    I agree that the picKit2 is not perfect but it works. None of the solutions you suggest can do ICD. As people move past using other peoples hex files and into more complex programs ICD is a real plus.
     
  10. amando96

    amando96 Guest

    I successfully burned this .HEX file with the latest version of WinPic and the led is blinking :D
    [​IMG]
    So now I'm downloading MPlab, With MPlab for what I understand will let me write my own code, and compile it to .HEX? I want to write my own code, Don't just want to use other people's codes...
     
    Last edited by a moderator: Jul 20, 2010
  11. amando96

    amando96 Guest

    Hi, successfully burned some more codes onto the PIC, this time I only changed which pins blinked, Now I have pin RA1 blinking.

    Now what I'm not understanding is, how do I calculate the frequency/delay of the blinking LED?

    I found this calculator, but after calculating I get this What exactly do I have to replace with that code to be able to alter the delay?
     
    Last edited by a moderator: Jul 21, 2010
  12. Mickster

    Mickster Well-Known Member

    Joined:
    Feb 24, 2008
    Messages:
    1,084
    Likes:
    57
    Location:
    BDA
    Code (text):

    ; ---------------
    ; DELAY 250 MSEC
    ; ---------------
    ;
    delay
          MOVLW 250
          MOVWF Loop1
    Outer
          MOVLW 200
          MOVWF Loop2
    Inner
          NOP
          NOP
          DECFSZ Loop2,F
          GOTO Inner ; Inner loop = 5 usec.
          DECFSZ Loop1,F
          GOTO Outer
          RETURN
     
    Basically, the delay loop above loads W with 250 and then transfers it to 'Loop1' register.
    Next, it loads W with 200 and then transfers that to 'Loop2' register.
    At the label 'Inner', 'Loop2' register is decremented by 1 and stored back in 'Loop2'. DECFSZ means 'DECrement File, Skip if Zero.
    This operation takes 5 uSeconds and is started again by 'GOTO Inner' at which point 'Loop2' register now contains 199.
    200 loops of 'Inner' will take 200 X 5 uSeconds = 1 mSecond.
    Once the 'Inner' loop register 'Loop2' reaches zero (after 1 mSecond), 'GOTO Inner' is skipped.
    The routine then decrements register 'Loop1' by 1 and stores it back in 'Loop1'. 'Loop1' register now contains 249. (249 mSeconds to go...)
    Next, the delay loop then gets directed to the 'Outer' loop again, by 'GOTO Outer'.
    The 'Outer' loop register (Loop2) was previously at zero, but is now reloaded with 200 to start the whole process again.

    So......now you know the inner loop takes 5 uSecs and 200 X 5 = 1 mSecond, you can quickly tailor the outer loop to provide from 1 mSec to 255 mSecs just by editing the 'MOVLW 250'

    If you need to provide a longer delay than 250 mSecs, you can simply call the delay routine more than once.

    Say you need a 400 mSec delay, you would change the initial 'MOVLW 250' in the delay loop, to 'MOVLW 200' and call the routine twice:

    Code (text):

    Main
          BSF PORTA,1 ; Turn on LED connected to RA1
          CALL delay
          CALL delay  
          BCF PORTA,1 ; Turn off LED connected to RA1
          CALL delay
          CALL delay  
          GOTO Main
     
    Frequency/delays....
    The original example you posted above (post #10) flashes the LED at 2Hz. (twice per second)
    That is because the LED is switched on, kept on for 250 mSec, switched off and kept off for 250 mSec = 500 mSec = 0.5 Seconds = 2 Hz.
    If you call the original delay loop twice as in my example above, the LED will flash more slowly at 1Hz.
    That is because the LED is switched on, kept on for 250 mSec, kept on for another 250 mSec, switched off and kept off for 250 mSec, kept off for another 250 mSec = 1000 mSec = 1 Second = 1 Hz.

    HTH.
     

Share This Page