PDA

View Full Version : Pbasic versus Basic... and C for that matter.



Mimewar
07-29-2010, 09:05 AM
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

Martin_H
07-29-2010, 09:36 AM
PBASIC is similar to a structured BASIC dialect with system programming bit manipulation commands from assembler or C. But it is missing floating point numbers and its signed arithmetic is squirrelly in the area of < > comparisons and signed extension must be done manually when copying a byte to a word.

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.

Mimewar
07-29-2010, 10:05 AM
Some of that made sense to me, and I thank you for the information.

Martin_H
07-29-2010, 10:28 AM
Well glad I could help and sorry for the bits that didn't make any sense.

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.

Kevin Wood
07-29-2010, 10:53 AM
Mimewar said...
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?


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 (http://www.earthshineelectronics.com/10-arduino-duemilanove-compatible-starter-kit.html) 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

W9GFO
07-29-2010, 11:41 AM
Mimewar said...
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)


Nope, not correct. You can use PicBasic Pro (http://) 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. (http://www.gadgetgangster.com/206)

Mimewar
07-29-2010, 09:31 PM
Oh my gosh! I can use PBASIC to program Micros!? I guess I should watch who I listen to and believe.

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?

Franklin
07-29-2010, 10:56 PM
Just ask your questions here. If they are not related to parallax products ask in the sandbox forum.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

allanlane5
07-30-2010, 12:06 AM
What you're paying $50 for is a pre-built, RELIABLE circuit, with brown-out detection, linear-regulation, and clock built-in. All you add is a +6 to +12 volt powersupply and program it over a serial link using the free IDE, and you have a running solution.

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.

Mimewar
07-30-2010, 12:23 AM
OK, thanks
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.

Franklin
07-30-2010, 12:50 AM
Depending on the product and your knowledge of programming and how much you plan to make using the pic (or avr, or psoc, or arm cortwx....) would make sense. Lower cost means more profit.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

Mike Green
07-30-2010, 01:06 AM
2) The Stamp Editor/Compiler converts the source program to compiled form and this is what's downloaded to the Stamp's EEPROM. There's no easy way to read this program from the Stamp although it is possible to partially read it by loading another program into the EEPROM, overwriting part of what's there. It's also possible to solder connections directly to the EEPROM and use an EEPROM reader/programmer to read the bytecodes from it. You can't reconstruct the original source program from this however since that's not present in the EEPROM.

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.

Mimewar
08-01-2010, 09:51 PM
OK, long delay between messages, needed to process what I read.

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?

Mike Green
08-01-2010, 10:14 PM
In order to program in PBasic, you have to have a PIC16F57 from Parallax that's pre-programmed with their PBasic interpreter. You also need a specific EEPROM that the interpreter uses to store the compiled PBasic program plus you need a resonator and a power source and filter capacitors and ...

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 (http://www.melabs.com)).

Mimewar
08-01-2010, 10:22 PM
250$! for a the interpreter! This is getting ridiculous. I've got everything I need now except a code that works with my hardware. Everything I know is in PBasic, which as it turns out I need 250$ to use. Am I just better off learning C and changing that to Assembly for the PIC?
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

Martin_H
08-02-2010, 03:58 AM
Mimewar, Just to be clear. The PICBASIC compiler costs $250 and compiles down to native PIC code. The PBASIC interpreter is embedded in the Basic Stamp and the IDE is free. They are different, but similar things.

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

allanlane5
08-02-2010, 11:31 PM
>OK, thanks
>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 (http://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

Kevin Wood
08-03-2010, 12:55 AM
As mentioned, the only products that can be programmed in PBasic are the Parallax Basic Stamps. This is because PBasic is a byte-code language, and the PBasic byte-code interpreter is Parallax owned intellectual property. I'm pretty certain that they don't license it to other companies.

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.

Chupacabra
08-03-2010, 11:46 PM
Hello Shane,

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

Leon
08-04-2010, 03:35 AM
Microchip has another way to get into C programming that is even cheaper:

www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en548414 (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en548414)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM

Chupacabra
08-04-2010, 08:58 AM
Very nice and practical suggestion, Leon. It's even half the price of the PICkit 2. After I finish volume 2 of "Beginner’s Guide to Embedded C Programming", that may very well be the perfect "next step" for me since PIC servo control is not discussed in "Beginner’s Guide to Embedded C Programming" volumes 1 or 2 which is really what I want to do (although, I suppose I could apply the techniques in the PWM chapter to control servos). However, I really like the fact that the PICkit 2 includes the standalone programmer making In Circuit Serial Programming a piece of cake provided your application circuit includes a means of plugging it in (very simple feature to include in an application circuit).

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

allanlane5
08-05-2010, 02:58 AM
Thanks Chupacabra, I'm always looking for low-cost ways to introduce the hobby -- I wasn't aware Microchip had lowered the price that much, that's good to know.