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
    awsome!!!

    let us know how it went, and if you end up using a input to activate a output, can you post a simple BASIC example?
     
  2. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Here's a SwordFish BASIC example (running on Junebug)
    Code (text):
    // JUNEBUG lights LED 3 when pushbutton 2 is pressed
    Device = 18F1320
    Clock = 0.031250          // default 31250 KHz Osc
    Config OSC = INTIO2         // Use the Internal Oscillator
    Dim     Switch As PORTB.2,
            LED As PORTA.6      //
    Low(PORTA.7)                // LED 3 Gnd
    INTCON2.7 = 0               // enable PORTB input pullups
    Input(Switch)

    Loop:
    If Switch = 0
            Then    High(LED)
            Else    Low(LED)
        EndIf
    GoTo Loop
    End
     
     
    Last edited: Dec 17, 2007
  3. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia
    I like the use of aliasing the port pins for more "understandable terms

    Code (text):
    Dim     Switch As PORTB.2,
            LED As PORTA.6  

    Just pointing it out because its something that when used on a larger scale, makes projects that much easier to maintain - that and I was just explaining it to a mate here.

    eg, you had a program with 1500 lines of code, and reffered to "Switch" in 10 different locations. By aliasing you only need to change the declaration
     
  4. dave

    Dave New Member

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


     
  5. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada

    They're based on your (gramo) examples. I've been wanting to use Swordfish with the Mongoose kit PIC18F2525. Too bad no debug support though but it seems like a very nice compiler. I use Swordfish's own editor and the PICkit 2 standalone software (program on push button works like a charm :) )

    I guess what I'm trying to say to shaneshane1 is the PICAxe is interesting and certainly better than a BASIC Stamp but a good PIC compiler like Swordfish beats them both.

    [​IMG]
     
    Last edited: Dec 17, 2007
  6. Leftyretro

    Leftyretro New Member

    Joined:
    Mar 11, 2007
    Messages:
    1,420
    Likes:
    13
    Location:
    Hercules, California
    I agree and hope to someday to invest in Swordfish/Pickit2 as my hobby applications may require the speed and power of those tools.

    However for a someone just starting out and wanting to try simple things to see if they really are going to like this stuff, then it's hard to beat the bang per buck that the Picaxe series can provide and I will continue to recommend it to raw beginners. Sometimes the journey of starting and learning with simple tools and working ones way up to more powerful tools is a better method to grow then starting with the latest state of the art tools and systems.

    Lefty
     
    Last edited: Dec 17, 2007
  7. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Went fine. It's a PIC 16F88 with a bootloader, so it's a pretty trivial thing for me to get working. I soldered up a programming cable, which you can see in this picture.

    Here's a bit more of a closeup. You can see the huge old 1/2 watt resistor I still use for LEDs. Had those since I was a kid.

    Now I guess I'll see if I can find a switch...
     
  8. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Yup. Here ya go. :)
    Code (text):
    main:
        if pin1 = 1 then blink
        goto main

    blink:  high 4
        pause 50
        low 4
        pause 50
        if pin1 = 0 then
            goto main
        else
            goto blink
        endif
    Pretty basic little program. If you press the button the LED blinks until you stop pressing it.

    Here's an incredibly exciting 2.6MB movie of the program in action! Don't fall off your chair. ;)

    The blinky thing in the background is my new (unfinished) PIC 12F683 board blinkin a couple LEDs.
     
    Last edited: Dec 18, 2007
  9. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Remember this post?
    I had another look, and if you haven't already ordered, I'm going to change my recommendation to the AXE002/035X. It's a better chip and it's cheaper because you're not buying a USB to serial adapter with it (and it's the chip I have, so if you're asking questions I can help easier). Check if your computer has a DB9 serial connector on the back first. Almost all computers do.

    If you use a laptop then you need the USB one. In that case look at the AXE002/035XU or AXE002/030XU. The 030 is the CHI030 board with darlington array. The 035 comes with a socket for a L293D motor driver. I think that might be more interesting than the darlington board. Besides, darlington arrays are dirt cheap. Add your own later if you want one.
     
    Last edited: Dec 18, 2007
  10. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    Thanks futz

    I ran your BASIC code through the simulator, and i understand it :D

    doesnt seem like it will be to hard to work out, i use to use a program called LUA, it was a program for the PSP (Playstation Portable) and it seems like BASIC and LUA are on the same level.

    so where you have put the text >>main<< in the code, you can change that to whatever you want as long as its the same through out the code.

    eg: replacing main with >>Start<< ???

    and replacing Blink with >>flash<< ???

    and so on.

    I had a look at your pics and your video, and it has put things into prospective for me, thanks!!!


    And as for your reply about the kit, i think i might stick with the AXE002/030U as its the lowest price at $73.65 (I need USB for Laptop)
     
  11. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Those are just labels, or symbols, and they can be almost anything as long as you don't use BASIC's reserved words (commands). You'll find a reserved word list in the manuals.

    I would definitely switch that to a AXE002/030XU then. The X chip has lots more memory. Makes things easier and it's only another five bucks.

    Here's how those model numbers work: AXE002 is the starter kit. 030/035 tells you which project board (CHI030 or CHI035). X tells you it's an 18X model. If there's no X then it's an 18A. And U means USB. No U means serial.
     
    Last edited: Dec 18, 2007
  12. shaneshane1

    shaneshane1 New Member

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

    I will go with the AXE002/030XU, more memory :D
     
  13. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I guess I'm missing something? What's wrong with using a free compiler like Swordfish SE or Great Cow BASIC and a standard PIC programmer?
     
  14. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    Nothing wrong with using them, i guess.

    Im just starting out with this subject, and the picaxe programming editor is really easy to use

    eg: I created this code for a toggle on/off switch and the code is very small and easy to understand

    Code (text):
    main:
        if pin1 = 1 then
                             light
                    goto main

    light:  
          high 4
          if pin2 = 1 then
             low 4
             goto main
             endif
          goto light
     
    Whats the equivalent in the code you use???
     
    Last edited: Dec 18, 2007
  15. gramo

    gramo New Member

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

    Code (text):
    [B]Device [/B]= 18F452
    [B]Clock [/B]= 20

    [B]Dim [/B]Switch [B]as [/B]PORTC.0
    [B]Dim [/B]LED [B]as [/B]PORTC.1

    // Make the Switch pin an input
    [B]Input[/B](Switch)

    // Main program loop;
    [B]While [/B][B]True
        If [/B]Switch = 1 [B]Then[/B]
            [B]High[/B](LED)
        [B]Else
            Low[/B](LED)
        [B]Endif
    Wend[/B]
    ** Note that "//" denotes the line is a comment, not code


    The above program will simply mimic the status of the switch. It could be simplified too;

    Code (text):
    [B]Device [/B]= 18F452
    [B]Clock [/B]= 20

    [B]Dim [/B]Switch [B]as [/B]PORTC.0
    [B]Dim [/B]LED [B]as [/B]PORTC.1

    // Make the Switch pin an input
    [B]Input[/B](Switch)

    // Make LED and output and set it low
    [B]Low[/B](LED)

    // Main program loop;
    [B]While True[/B]
        LED = Switch
    [B]Wend[/B]
     
    Last edited: Dec 18, 2007
  16. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Hehehe! :p I did try to push him (gently) into a Junebug. But after a while I realized that he was a complete newb and thought that a Picaxe might be (as I said earlier) "a kinder and gentler intro".

    Once he has a handle on the basics, like simple programming and interfacing, and wants more power he can get a real programmer and dig in to slightly more advanced PIC use.

    The Picaxes are SO easy to use that I think they'd bore me. Took me all of 2 minutes to get a 18B20 working on this thing last night. Ultra simple. But I didn't learn a damn thing. :D BASIC hides all the complexity from me. There's no challenge for someone like me.

    On the other hand, that kind of simplicity is great for newbs. They don't get bogged down in complexity. They learn a bit about programming and interfacing. And they get some early success, which is good. Pretty soon maybe they find they need more speed and/or control and step up to the "real thing".
     
  17. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    well ill keep using this until i need something bigger and better and harder to understand :rolleyes:

    I dont need complex code that is harder to understand, when i have something that is easy to understand, and does more than i need it to do anyway.

    for me at the moment, this is a huge space saver, it cuts down on the amount of IC'S im use to using to do the same job a PIC can do.
     
  18. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,216
    Likes:
    640
    Location:
    Derbyshire, UK
    The thing is you don't need a programmer with a PICAXE, it's very cheap and very easy to use.

    Downside is it's fairly slow as it's interpreted, and they only have limited program size.
     
  19. shaneshane1

    shaneshane1 New Member

    Joined:
    Feb 14, 2007
    Messages:
    414
    Likes:
    6
    Location:
    NSW,Australia
    I have one more question that i think i already know the answer to,

    on all my inputs, im assuming i need to put 10K pulldown on all my inputs for normal operation?
     
  20. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,216
    Likes:
    640
    Location:
    Derbyshire, UK
    No, why would you do that?.
     
  21. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Then what do you get for $73 that you don't need? A USB to RS232 is $14
     

Share This Page