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

New to PIC'S and programming???

Discussion in 'Microcontrollers' started by shaneshane1, Dec 12, 2007.

  1. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    once i have everything up and running, and i have downloaded BASIC where can i obtain the code's to program the Pic, eg: output go high for 1second and then low for 1second, do i have to seach the web everytime i want to do something? or is there a site for it all, or at least most of it?
     
  2. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    :confused: Why would you want to copy code from others? You don't learn anything that way. Make your own. It's easier than you think. You can start with very simple stuff and gradually get into more complex subjects. Burn thru some tutorials and you'll be doing interesting things in no time. :D

    At the Picaxe site you can find manuals, tutorials and interfacing information on the Datasheeets page. There's help there for all kinds of kewl stuff.

    Like I said, I'm getting one too, so if you have questions I can probably assist. I used to be a heavy BASIC programmer, thousands of years ago before I switched to assembly and C.
     
  3. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    i just downloaded the Picaxe programming editor about 40minutes ago, and have been testing simple commands using the simulator, and im finding it really really easy to use, eg:

    main:
    high 1
    pause 1000
    low 1
    pause 1000
    goto main

    so when i buy the PICAXE-18A Starter Pack - USB i will have a head start on things.

    when i buy the (AXE002/030U) kit, what do all the pins on the PIC mean, i tried looking up the data sheet for it but the page is unavailable

    i know what the output pins do, and +V and 0V

    and i assume that serial in & serial out are sum what connected to the computer :confused:

    and i would assum that reset would just be like the reset on an ordinary IC :eek:

    But what about the inputs? what are they for?



    can someone help me on the matter


    futz :D
     

    Attached Files:

    • pic.PNG
      pic.PNG
      File size:
      6.6 KB
      Views:
      69
    Last edited: Dec 16, 2007
  4. dave

    Dave New Member

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


     
  5. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.

    Told ya! ;)

    Usually you would use those pins for various communications protocols like RS-232 or SPI or others, either to communicate with a PC or with another microcontroller or even a display (serial LED or LCD) or other peripheral.

    Yup.

    Those can read analog voltage levels or be used to read switches or other things like that. They allow the microcontroller to sense the outside world in various ways.
     
  6. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    So am i right in saying that if i just want to use the outputs, i can remove the PIC and connect it to a breadboard using pins +V, 0V, Reset to +V using a pullup resistor, and the outputs to my application?

    So can i use my inputs to activate an output?
    if so i assume i will need to command the infomation through BASIC to do so

    Thanks!!!
     
  7. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    You could, but why risk breaking a pin? Just leave it in the board. Install some headers and build some cables to connect the board to your breadboard.

    Something like this ribbon cable from my 18F452 board to the breadboard.

    Another reason to leave the PIC on the board is that board gives you a darlington array for outputs, allowing you to connect fairly big loads (up to 800ma per pin). The PIC's pins are only good for maximum 25ma.

    I can see you're going to have some grief though. That CHI030 board uses non-standard pin spacing (trying to cater to newbs, but in doing so just making things difficult) and you may have to solder wires individually to a header and plug into that.

    Or you can set the whole thing up on a breadboard instead. You'd have to hack together some way of plugging the programming jack into the breadboard, or do it with wires from the CHI030.

    If you're going to move the chip from board to board more than once or twice, definitely buy yourself a machine-pin IC socket. Put the PIC chip in the socket and pull the socket with chip instead of risking the IC's legs with every move. Those machine-pin sockets are tough. The PIC's pins, not so much.

    You mean push a button and the MCU sees it and turns something on? Yes you can do that, and yes, you'll have to write code to make it happen.
     
    Last edited: Dec 16, 2007
  8. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia

    What model Darlington array does it have?
     
  9. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    It's a ULN2803A
     
  10. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Just for the record I tried out one of gramo's LED examples and the free Swordfish SE BASIC Compiler on the Junebugs 18F1320. Works like a charm.
    http://users.tpg.com.au/gramo/Site/led's1.htm
    Code (text):
    // Blink the Junbug Tutor LED 1 at 1Hz
    Device = 18F1320
    Clock = 8
    Config OSC = INTIO2            // Use the Internal Oscillator
    Include "utils.bas"
    Dim LED As PORTA.0            // Assign an alias for "LED"
    // Start Of Program...
    OSCCON = $72                // Sets up the internal oscillator
    SetAllDigital                  // Make all Pins digital I/O's
    Low(LED)                      // Make the LED pin an output and set it low
    Low(PORTA.6)                // Make the LED Cathode an output and low
    While True
        LED = 1                   // Turn on the LED
        DelayMS(500)            // Delay for half a second
        LED = 0                    // Turn off the LED
        DelayMS(500)            // Delay for half a second
    Wend
     
    Last edited: Dec 16, 2007
  11. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia
    I thought it was either the UNL2803/2003, but when you said 800mA, well, I got excited for a second there hehe

    The 2803 and 2003 are rated for continuous 500mA/channel - enough for almost everything I've used aside from larger motors


    :eek:
     
  12. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    so after the PIC has been sent infomation it can be removed and placed on a breaboard using a machine pin socket to keep the pins in good order.

    and the only thing that needs connecting is +V, 0V, reset, and outputs?
     
  13. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia
    O nice, can't wait to have a closer look at one of these kits
     
  14. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I just sent you email... Did you get it?
     
  15. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia

    Sure did, just a moment ago :eek:
     
  16. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Here's your (gramo's) 1wire program running on the Junebug using the PICkit 2 UART tool I'll update the image when I find one of my DS18B20s
    PS the Junebug and many other blueroomelectronic kits are 1wire ready (the little 3pin connector on the lower left of the Junebug Tutor)
    [​IMG]
     
    Last edited: Dec 16, 2007
  17. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Pretty much. Once programmed, the chip will hold the program for... ever? (a long, long time anyway). And whenever powered up it will run the program.

    You can reprogram it right on the breadboard. No need to move the chip back and forth. It's not like you'll just program it once. You'll do it hundreds and thousands of times as you make changes to your programs and work the bugs out of them and make new programs to do new things.
     
  18. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    Ok thanks

    iv looked at the data sheet for BASIC commands and thats seems faily straight forward :eek:

    But i dont really know how to string these commands together

    eg: if i want to use an input(button) to activate a output

    i dont know where to start with things like that?
     
  19. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    I just installed the editor and am looking through the command set. Nice! Very complete. Looks like they've thought of almost everything. :) Well done! Looks like a really easy chip to use.

    Well, stringing those commands together is what programming is. You'll pick it up. When you want to get something done, try to write down on paper in english (or pseudo-code), what you want to accomplish, step by step in the order you think it needs to be done. This is called an algorithm. This will get easier with practice. Be sure to double or triple space so you can stuff in more commands you think of later to fix the stuff you never thought of on the first pass.

    You WILL crumple and throw away many poorly thought out algo's and will rewrite large sections as you write code and test it.

    Then find commands that will accomplish the steps and start typing them in, checking off things on your scratch paper as you get each part coded. You'll be useless at it at first, and you'll spend a lot of time thrashing back and forth through the manual trying to find the right commands to use. Don't get discouraged. It gets much easier with practice. After a while you'll memorize the more common commands and you'll just know how to do things.

    Don't aim too high at first. Start very small. Write lots of tiny programs. Modify them to see what happens. Get small sections of your code to work individually. After each part works, put em together.

    You can't learn programming by reading alone. You MUST write code, and lots of it, even if it's crappy code. You'll get better with practice.

    First thing is to make a "main" loop like the first LED blink demo. Inside that loop you'll "poll" (check it every time thru the loop) the input pin your switch is on with an "if/then" statement.

    Read Manual 3 to learn how to interface a switch properly. It'll need a pull-up or pull-down resistor to hold the pin electrically in the "off" position until you actually switch the switch.

    When the program sees the pin has changed and is low or high (however you've built your circuit) the "if" statement will branch to a part of the code that turns on your LED. As long as the switch is off this part of code gets skipped past.

    Am I making any sense?
     
    Last edited: Dec 17, 2007
  20. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    Yes it does make sense, thanks!!!

    i understand all of what you are saying, its just a pitty i dont have the kit yet, still waiting to get the money for it :mad:

    i can only just keep testing with the simulator, im just glad thats there to stop me going completly crazy

    and least it gives me an indication that my code works.
     
  21. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Hey shaneshane1. I got my Picaxe 18X chip today, so maybe tonight I'll get around to making it do something. :)
     

Share This Page