+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Default PIC BASIC command query

    HI,
    I'm a beginner wanting to program PIC chips using BASIC. I have downloaded the Amicus stuff, but also bought the PIC book by Chuck Hellebuyck, who uses the MELabs free compiler PBC.
    I am completely baffled by one of his I/O commands for the direction register.
    To control the PORT direction , Microchip use the convention 0 = output; 1 = input. Of course, that is in Assembler.

    In Hellebuyck's book he attempts to flash an LED using PIC 16F876 (pp135-6 in my copy).
    To set the direction he uses a command DIRS ( that isnt DIR$, BTW ).
    There are 2 problems:
    1. the command is %00000001 to set RB0 as output. Well, he may be right, but it makes no sense to me.
    2. There is no reference to this command anywhere in the book, or, for that matter, in another website I looked at with a long list of 150 BASIC commands. Duh!

    Can any kind soul explain this one to me?

    bruce

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,914

    Default Re: PIC BASIC command query

    If you use PicBasic from Melabs, just look in the pdf manual. That is the only manual to trust.

    And in there, TRIS is the direction command. 0 for Output, 1 for Input, just like the initials of the direction.

    Ioannis

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    442

    Default Re: PIC BASIC command query

    Poriet,
    So which PIC are you using? Is it the 18F25K20 that is on the(my) Amicus?

    Which ever one you are using... (and whenever you use a new PIC) ALWAYS download the .pdf datasheet for that PIC (google the PIC partnumber and "datasheet"). Then spend some time looking through it... Look for the section that summarizes the various "Registers" in the PIC... this section is KEY to setting up the PIC pins to be what ever you want them to be. (input, output, analog, pulse width modulation, etc)

    Understanding how to reference the datasheet as you set up your PIC is probably one of the hardest(for me) and yet one of the most critical and necessary steps. The "TRIS" register is where you set a pin to be 1=input or 0=output.

    Take a look at some of the example programs in the "wiki" section of this fourm and pay attention to the comments in the various programs and you will be able to learn how others set up the PICs to function as they need them to.

    I seem to remember that "DIRS" could be a throwback to the BASIC STAMP as the PIC Basic language is quite similar and an attempt was made to have PBP be compatible to the basic stamp.

    From an older version of the PBP manual...
    The BASIC Stamp variable names Dirs, Dirh, Dirl and Dir0-Dir15
    are not defined and must not be used with the PICBASIC PRO Compiler.
    TRIS must be used instead, but has the opposite state of Dirs.

    This does not work in PICBASIC PRO:
    Dir0 = 1 ‘ Doesn’t set pin PORTB.0 to output

    Do this instead:
    TRISB.0 = 0 ‘ Set pin PORTB.0 to output
    Hope this helps...
    Don't give up once you get over the initial hurdle of setting up your PIC and learning how the set the registers it is very rewarding.

    Keep asking questions if you need more guidance...
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Nov 2011
    Posts
    2

    Default Re: PIC BASIC command query

    Hello guys and thanks,
    I dont have a chip yet, but the grand idea is to get an 18F25K22 ( thats the 5V version IIRC ).
    I intend to make my own breadboard with chip, periperals and program it with my PICKIT2.
    I aim to use the Amicus IDE and program in BASIC (PBC).
    Fifty quid to flash a LED; it's called progress.

    MElabs have removed the pdf of the PBC and only now do the PBP3 ( BASIC Pro ). I did feel that taking on the Pro version now was premature. However, I found some PBC tutorials in the Amicus18 document folder. I didnt realise it was a set of tutorials because it has a very silly name: "Amicus IDE" - hardly obvious.

    I think I have the answer to the question. Chuck Hellebuyck has made an almighty cock-up in his book, which has remained unchallenged, or uncorrected, for 10 years. Which I think is bad. He has used the DIRS command to set the direction of the PORT pin. But that command is an old BASICSTAMP command. Theres absolutely no other reference to it in PICBASIC and, worse, even in his own book.
    I also made a cock-up: I didnt realise that the BASIC command "HIGH, pin" does two things, ie it pulls the pin high and makes it an output. So, I dont need to bother with the direction register; yet. The DIRS command is for the Pro compiler and, confusingly, to set a pin as an output, the command is a 1, or HIGH, the absolute opposite of Microchips PIC convention. You couldnt make it up.
    I also noticed that you recommend I get the datasheet. Well, of course, but it's 500 pages. That's longer than "War and Peace".

    bruce

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    442

    Default Re: PIC BASIC command query

    Hey Bruce,

    I also noticed that you recommend I get the datasheet. Well, of course, but it's 500 pages. That's longer than "War and Peace".
    True, but that is the beauty of the .pdf and the computer. You can ignore 80% of the datasheet and only refer to the important stuff.

    If I have read it once on this forum... I have read it a hundred times. "The datasheet is your friend"
    That is no joke... that is FACT. Once you learn how to search the datasheet for what ever part of the PIC you are working on and interpret the register setting information to configure the port.pin for your needs, you are well on your way to success with the PIC.

    As far as which PBP to buy... If you are serious about programming the PIC in BASIC rather than C or some other language... I would go for some level of the PRO version of PIC Basic. There is a hobby version that covers just a sub-set of the PIC models that is less expensive than the full blown version, yet it is still a "PRO" compiler.

    If you are using the PICkit2 (I have that one and it is excellent) then you probably do not need to mess with the amicus IDE. Just use the free MicroCodeStudio IDE (MCS). I believe the only reason to try and impliment the amicus IDE would be to program via the onboard USB chip and the bootloader on the amicus board.

    There is also another good free IDE called FineLine that you might want to try.

    stay determined and you will be rewarded...
    Last edited by Heckler; - 25th November 2011 at 15:47.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,259

    Default Re: PIC BASIC command query

    Hi,
    Just a couple of random notes.
    PBC is now discontinued so if you don't already have it it's probably not something to persue. You said PBC is free - I didn't know that, did you get it with the book? Anyway, it's an old product and it's harder (quite a bit harder) to use and less capable than PBP, besides I'm pretty sure it doesn't support ANY of the newer PIC like the 18F25K22 (I haven't checked that though).

    I don't think you can use the Amicus IDE with any other compiler than the one that comes with the IDE. That compiler is a special version of the Proton compiler "only" supporting the 25K20 and 25K22 devices. There are a lot more differences between the two chips besides the operating voltage range by the way.

    If you DO intend to use MELABS compiler their Experimenter Edition costs $49 and supports 25K22 as well as a couple of others. A popular IDE for the PBP compiler is MicroCodeStudio. On the other hand the AmicusIDE and compiler are free... However this forum is not targeting that compiler so if you're going down that route questions would be better suited on the Amicus forum.

    DIRS is not for the PRO compiler, ie MELABS PBP and TRIS is not a command, it's a name of a register in the PIC. The TRIS register is what controls the "direction" of the I/O pin as you've discovered. To set it you can do (for example) TRISB=%10101010 or TRISB=170 which both results in the same thing. With PBC however you can't do that because it doesn't allow access to registers in that way, you have to take the datasheet, find at which adress in memory in memory the TRIS register is located and then use the POKE command to assign a value to that adress. But again, I don't think you can even use PBC for the PIC you're targeting.

    /Henrik.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts