Pbasic versus Basic... and C for that matter.
Mimewar
Posts: 10
What is the difference between Pbasic and BASIC?
I'm learning PBasic on the Parallax Basic Stamp homework board, and doing pretty well at it, and I came across something that suggested that Basic and PBasic are not one in the same. Can someone explain the difference?
Also, I'm thinking of learning C next, as it seems that a lot of PICs can't be programmed in PBasic (is that even correct) Can someone suggest a noob friendly (similar to the parallax approach) way to start in on C?
Thanks.
Shane
I'm learning PBasic on the Parallax Basic Stamp homework board, and doing pretty well at it, and I came across something that suggested that Basic and PBasic are not one in the same. Can someone explain the difference?
Also, I'm thinking of learning C next, as it seems that a lot of PICs can't be programmed in PBasic (is that even correct) Can someone suggest a noob friendly (similar to the parallax approach) way to start in on C?
Thanks.
Shane
Comments
It also has something similar to a C union which allows you to access a piece of memory as a word, two bytes, or a bit vector which is very un-BASIC like. The overall feel is structured BASIC meets assembler and C unions.
Like many BASIC dialects it is missing functions with local variables, so all variables are global. With the RAM constraints in the BS2 you need to be creative with variable space.
With the exception of the signed arithmetic squirrelly-ness, I think it is a good language.
Will learning PBASIC help you learn C? Well they are both Algol family languages, so while their syntax is different, their programming gestalt is similar. But the lack of functions and local variables means you'll pick up some bad habits you'll need to unlearn when you switch to C.
But two nights ago I copy and pasted a PBASIC program and translated it a line at a time into C for the AVR. The changes were mostly syntactic and not semantic.
BTW To get a feel for what I mean about signed arithmetic try
* create a byte A and a word B. Set the byte equal to -1 and the word equal to 1. Try IF A < B and see what happens.
* Assign B = A and then print B.
You won't get the answers you expect which is the squirrelly-ness I mentioned above. There are work arounds to these issues which you'll learn as you get better with PBASIC.
The PBasic interpreter is Parallax owned intellectual property, and is only found on their Basic Stamp products. However, since most dialects of Basic are similar, you should have no problem transferring what you learn to other systems.
As for learning C in a manner similar to the Parallax approach, I suggest finding a kit based on the Arduino Duemilanove. There are several out there, but this one has a well written manual to go with it. You can download it at the bottom of the page.
Note, however, that learning C that way will only give you a limited view of the language, because the Arduino programming environment hides some of the details for you. So I suggest getting a beginner friendly book to get you started. One that I read and liked is titled "Absolute Beginner's Guide to C".
Post Edited (Kevin Wood) : 7/29/2010 3:59:53 AM GMT
Nope, not correct. You can use [url=http://]PicBasic Pro[/url] to program nearly any PIC. It is very similar to PBasic, so similar that in their forum they often refer to Parallax's documentation.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
I looked over the Basic Stamp datasheet, and schematic, as far as I can tell, it's a PIC16F57, with all the peripherals added on. It's got an eeprom( I assume the PIC 16F57 doesn't have the memory?)a crystal, and all the programming transistors and resistors built into it. It's more a convenience thing, at least it looks that way to me. You're paying 50$ for a prebuilt circuit. Which is great, but I'd rather do the legwork myself, and customize it as I see fit. Maybe I'll put off learning C for a while, and just move on to a proper Micro, PIC, and get a programmer debugger, and get going!
Thanks
Any chance anyone in here is available for a few minutes via IM to answer a few questions?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
The 16C57 has burned into it the Parallax PBasic language, again with proven reliability. The external eeprom holds compiled PBasic tokens loaded there through the IDE -- this provides a very concise version of your program which takes up minimal space, and also some intellectual property preservation.
The OEM version is slightly cheaper, if you want to go that route.
So, the Parallax solution provides a very easily programmed device for minimal expense upfront. You COULD spend $xx for a compiler, $50 for a development board, $xx for 'target' boards, $xx for 'native' PIC chips, resonators, RS-232 interface chips, maybe a small linear regulator chip. Having spent $500 or more, at that point you'd be set to manufacture (and debug) your own PIC-based solutions. Or, if you're an experimenter on a budget, spend $150 or so for the BOE with a BS2 module and you're good to go. Not to mention the help Parallax provides which is more extensive than I've seen on any other platform.
Both approaches have strengths and weaknesses. Having tried, I can tell you the Parallax approach is the lowest cost for doing one or two prototypes.
Here goes
1. The stamp is a circuit using a PIC16F57. So if I were to try to clone or replicate enough of the circuit to make my own, or start program my own uC, I would need: a crystal, an EEPROM, a voltage regulator, some transistors, capacitors, and resistors. Oh, and a brownout/reset. I happen to have a PIC16C57 salvaged from something else. Larger package, same thing though(almost) I could theoretically program this wit the above components, and start my own circuit?
2. Can a Pbasic code be safeguarded in EEPROM? So no one else can get a peek at it?
3. Do I always need an external EEPROM? I see some of the PICs I am looking at have flash memory built in. If I read that right, the EEPROM would be part of the PIC?
4. I read in a response I got while I was writing this, that the BStamp is preprogrammed? So, if I get a PIC16xxx, I can't just hook it up properly to serial, and program it in PBASIC? I would need to translate the PBASIC into another language the PIC already knows, when it comes a blank slate?
5. The more questions I get answered the more pop up. I want to prototype a product, and offer it to someone else to mass produce, so using a PIC instead of a stamp has a big appeal.
Thank you all for the responses. I hate to sound lazy or ignorant, but there is a lot of information out there, and it can be hard for someone like me to sift through. ADHD is a burden when you are trying to sift through information, and get the important parts out.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
3) The PIC's flash memory is used for the PBasic interpreter and is not used to hold your program.
4) If you overwrite the flash memory with something else, you won't have the PBasic interpreter and there's no way for you to restore it other than sending it back to Parallax.
1. So, I need a PBasic interpreter to program a PIC with PBasic? I only know PBasic at this point, and I am itching to start building my own projects.
http://www.microchipdirect.com/ProductSearch.aspx?Keywords=DV164120
This looks like a good way to start, but software is still a concern. I would need a program to interface with the PIC, and load PBasic programs into it. Or the EEPROM, or.... I'm so lost.
2. If I want the program to stay around after the power is removed, I need an EEPROM, yes? How do I load my program into an EEPROM?
3. Using only a PIC, instead of a Stamp, do I need to convert the PBasic source code into another language to load it into the EEPROM, or the PIC?
The minimum stuff that you need is packaged up in the OEM Stamp kit
If you want to program PICs, you will need to buy a compiler like PICBasic Pro which accepts Basic programs similar to PBasic (but not identical ... the differences are small - look at the manuals). You won't need a separate EEPROM because PICBasic Pro produces programs meant to take the place of the PBasic interpreter and are stored in the PIC's internal flash memory. You will need a PIC programmer to actually "burn" the program into the PIC's internal flash memory. Look at microEngineering Labs' website for details (www.melabs.com).
I'm kind of feeling bummed out here, every time I feel like I am gaining ground, and nearing the prize, I trip!
Thanks for the help
Shane
So if you're making one to ten of something PBasic with the BS2 is more economical, but you'll be using something like the BS2 OEM module for $30 per unit. If you are making a hundred of something you amortize the $250 for the compiler, plus the cost of the programmer across the units and use the PICBasic compiler.
As I said above, I think you'll find a fair bit of what you know from the BS2 transferable to C. If you want to learn C I'd suggest getting your hands on an Arduino and its IDE. It would be a fairly cheap investment. The propeller and Prop C would be another possibility, but I haven't personally used that.
Quick update. The $30 price for a BS2 OEM is for the fully programmable kit. If you used a BS2-lite circuit you could cut the cost down more, but I have no experience with that.
Post Edited (Martin_H) : 8/2/2010 1:03:55 AM GMT
>Here goes
>1. The stamp is a circuit using a PIC16F57. So if I were to try to clone or replicate enough of the circuit to make my own, or start program my own uC, I would need: a crystal, an EEPROM, a >voltage regulator, some transistors, capacitors, and resistors. Oh, and a brownout/reset. I happen to have a PIC16C57 salvaged from something else. Larger package, same thing though(almost) >I could theoretically program this wit the above components, and start my own circuit?
Yes and no.· You'd only have to do this if you wanted to build a BS2 'clone'.· To give you some idea of how practically difficult this is, this is the basic concept that the company "Parallax" was based on.· It's so difficult to do, that they've been making money off of it since 1991 or so.· However, most people don't WANT to build a BS2 'clone' -- what you seem to be suggesting here is that you have to create a BS2 'clone' in order to program a PIC processor, which is entirely incorrect.
>5. The more questions I get answered the more pop up. I want to prototype a product, and offer it to someone else to mass produce, so using a PIC instead of a stamp has a big appeal.
One thing you might try is to go over to www.sourceboost.com.· They have a low-cost compiler for PIC processors.
Really, you have several paths you can take.· The BS2 path is the cheapest and best supported to start out with.·· A 'vanilla PIC' path has much higher start-up costs (you need to buy a compiler, a board to program the PIC in, and design your own board to run the PIC in, all of which can be $500 or more) -- but that's a DIFFERENT PATH from using a BS2.· If you confuse the two paths, I can't help you, because the questions and answers for each path are very different.
Post Edited (allanlane5) : 8/2/2010 4:43:54 PM GMT
You do have several options for reaching your goals. If you can give a better idea of what you are trying to produce, and how many, it would make it easier to recommend a course of action.
I've been in your shoes before. I wanted to go from PBasic to C. My solution was to get the PicKit2 for $50 from MicroChip which, by the way, comes with a programmer, development board, a PIC16F690 and a free IDE (MPLAB) and Hi-Tec's C Compiler (you can also download these free from MicroChips website). The next thing is to either go to Amazon.com or elproducts.com and get "Beginner’s Guide to Embedded C Programming" and volume 2 of the same name which he uses the PicKit2 much the same way Parallax did with the "What is a microcontroller?" kit. Also, Chuck has other books and solutions you will probably be very interested in at his website (elproducts.com). I really liked Chuck's first book (haven't started volume 2, yet) as I am also somewhat ADD/ADHD and found his writing very easy to follow and learn embedded C with. I hope that helps you out.
Best of Luck,
James
www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en548414
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
Shane,
None the less, I appreciate that Leon did not suggest that it would cost you at least $500 dollars to get away from the Basic Stamp. Parallax has a great product in the Basic Stamp line perfect for learning and getting started in robotics, but $50 for every BS2 you burn versus $2 for a PIC16F690 explains why you won't find a BS2 controlling a microwave, furnace, universal tv remote control, etc. By the time you add the support components to a PIC application, you're up to about $8 dollars (if it's elaborate). By the way, you can protect your code on the PIC using the MPLAB IDE (you asked about this earlier in this thread). Also, the PIC16F690 also has brownout detection/reset built in if you choose to enable it in your configuration bits. Manual reset is just a matter of adding a momentary push button switch. It also gives you options for the clock (built in or external using a ceramic or crystal resonator).
The bottom line is that your are closer than you think to learning embedded C and it won't cost you that much to dive in (PICkit2 = $50, Embedded C Book = $32 at Amazon).
Happy exploring,
James