Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC code to C — Parallax Forums

PBASIC code to C

StingzLDStingzLD Posts: 2
edited 2010-07-18 05:47 in BASIC Stamp
Hey guys,

I am still pretty novice in this big and fantastic world, but I feel that I am ready to move on.
I am starting to research PICs and all of their glory, but obviously I cannot use PBASIC on them!
I would like to learn C, but it is so completely different than PBASIC. And as a novice, it is very
confusing trying to figure out how everything works.

Does anybody have information that could make this transition easier? I am basically hoping for
a conversion chart so-to-speak that shows how things are done in PBASIC and translates them
into how it is done in C.

Any help would be great!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-20 05:14
    You might have a look at the PIC-Basic compiler from microEngineering Labs (melabs.com/). The entry level version is only $100.

    There's no guide for converting PBasic to C because most of the significant operations in PBasic are not available in C or are very very different. Things like PULSOUT or HIGH or LOW or SEROUT simply don't exist in C. Something like these would need to be provided as library calls, but those would be dependent on the vendor of the C system. You might look at the Arduino's C libraries for equivalent functionality.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-20 08:27
    The PicBasic Pro Demo is free and supports a bunch of different PIC chips, it's limited to only 31 lines of code but that is plenty for getting the feel of it.

    You could also move on up to the Propeller chip and even continue to program in basic using PropBasic.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • bill190bill190 Posts: 769
    edited 2010-06-20 13:24
    I would suggest finding a free simple C compiler for just your PC (nothing to do with microcontrollers). Then first learn how to write C programs with that.

    Then you can easily display things from your programs on your pc monitor and see that your programming is working.

    Also read a book on C programming. So far as books go, C was developed using the "UNIX" operating system and there are many books out there which frequently mention UNIX things which don't apply to a PC.

    Unix things would use a $ "command prompt" in the books examples to compile something. Like this...

    $ cc myfile.c

    Whereas a PC "command prompt" would look like this...

    C:\> cc myfile.c

    So best to look through the book and at least see that it uses PC examples as opposed to UNIX examples. Then you willl know what·the book·is talking about.

    You can get an IDE or Integrated Development Environment. These add all sorts of additional files to your programming making everything even more confusing. There would be a book length document on just how to use the IDE and you are best to read that.

    And then there is something like Microsoft Visual C++ which has all sorts of "objects" to learn about in addition to learning C.

    I would suggest avoiding the IDE and Visual C++ things for your very first C program on your PC. There should be a simple free windows C compiler/linker out there somewhere?

    Then write your first "Hello World!" program using that...
    http://en.wikipedia.org/wiki/Hello_world_program

    PIC programming is done with the Microchip IDE called MPLAB. This comes with a free C compiler for other than PIC 18 devices.

    Then there is an add-on·free MCC18 PIC C compiler. You are best to install that in the C:\ directory of your PC as this compiler will·not work with long directory/file names.

    Then any programs you work on should also be very close to C like in a C:\Pic directory. If the program is buried too deep in a directory tree, C18 will say·it can't find the·folder/file!

    There is also a paid for C compiler called the Hi-Tech C compiler. Sample C programs written for that compiler will not work on the C18 compiler!

    So there are many different C compilers out there! (To add to all the confusion!) A C program which works for one C compiler many not work on another C compiler. So also read the compiler documentation.

    This stuff can take years to learn.

    ·
  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-20 20:01
    If you want to learn C there is a wonderful video tutorial by Mark Virtue. I actually paid for the lessons a few years ago (really) but now I cannot find the website where it was available. A Google search returns a bunch of torrents.

    Anyway, he presents the information very clearly making it very easy to follow. He uses the Dev C++ compiler by Bloodshed - it's free.

    I highly recommend it, it's worth paying for.

    Rich H

    edit: I found it. The first three chapters are free. I had overlooked the first Google hit because it looked like so many other useless hits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 6/20/2010 8:15:45 PM GMT
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2010-06-20 21:12
    Unless you are set on learning the PIC series specifically, I suggest taking a look at the Arduino, specifically the Duemilanove.

    The Arduino has it's own IDE that allows you to program in a C/C++ "manner". I say "manner" because the IDE is really a front end to the GCC compiler, but it is designed to hide some of the development steps that are involved in the process. So an Arduino "sketch" gets converted into a valid C/C++ program, then is compiled with GCC, and the output is loaded into the Arduino, managed by the bootloader+ide.

    The benefit here is that it provides a gentle introduction to C/C++ syntax & concepts, as well as a library of funtions that make it fairly easy to get started. When/if you decide that you want to get more involved in the process, you can program the Atmega328 chip directly using an AVRISP MKII programmer (approx. $35), and AVR Studio (free). In doing this, you are bypassing (or overwriting) the Arduino bootloader altogether, and essentially using the Duemilanove as a development/programming board for the Atmega328.

    All of that said, there is one caveat. There are a lot of Arduino "kits" on the market, and they vary considerably in the quality of the instructional material included. The closest that I've seen to the "What's a Microcontroller" manual is the book written by Earthshine Electronics: www.earthshineelectronics.com/files/ASKManualRev3.pdf. They sell kits based on the book, but they are located in the UK, so depending on your location, the price will vary. Just be aware that if you do pick up an Arduino, you'll likely need to spend a little more research time than you would with a BS2.

    Lastly, while I've not used one, but have been considering purchasing one, Andre' LaMothe has a couple of kits available that are very comprehensive, with very god documentation. If you're looking for C/C++, you'll want to look at his AVR & PIC based products. He does have a few kits based on Parallax chips (SX & Propeller), but they don't use C/C++ as the target language.
  • metron9metron9 Posts: 1,100
    edited 2010-06-21 22:43
    Atmel chips, and codevision are very cheap to get into and very good answers to questions at avrfreaks.com a Teensy using a usb port on your PC to program is another very easy way to go.


    I just started learning C myself (assembler is my playpen) Codevision has a free download for limited size files and is low cost as well to buy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • StingzLDStingzLD Posts: 2
    edited 2010-07-18 05:47
    Thanks for all your help guys! Although I did not go through with any of your suggestions (sorry!), I did happen to run across a "free" version of the PIC C Compiler from CCS. And when I say "free", I do not mean the demo but the full on version of CCS. Although it is slightly outdated (literally slightly, V4.084 instead of V4.109 but looks and acts identically), it is exactly what I have been looking for. It even has a tool that talks directly to MPLAB (which I had started learning ASM with previous to this topic, thanks for the advice on the IDE though!). And to make things even better, there is a PIC Wizard that you can use to set up all your configuration bits and even define I/O and other stuff, and it writes the code for you! And of course the TONS of examples that come with it. This was definitely the best find I have found/will probably ever find in regards to a good "free" C compiler... considering the compiler is $600, oh yea!

    As far as the Arduino goes, I would actually recommend getting one. I bought one about 8 months ago, and it is a cool little device. The only downside I found really quickly is that it is insufficient when it comes to the projects I am trying to get going. But that doesn't mean it isn't something you shouldn't buy and play around with! There is a lot that you can do with them that I have not had enough time to play with, but one day I will get to attempt to fully explore the Arduino and all of it's glory.

    Anyways, thanks once again y'all!
Sign In or Register to comment.