Help in understanding different Programming
jason0627
Posts: 17
Hello thanks for reading my post.
this post is to help me try to understand the different programming languages. I am using the basic stamp (2) currently so I am learning Basic . I am also interested in using PIC microcontrollers so I am reading up on picbasic (lucky not that different).
I started looking for a good microcontroller module (basically what i want is a good board i can plug my microcontroller in and be able to connect and program easy because previous attempts at soldering a serial connection ending .... not well ). I wanted to get the arduino uno but then i saw it works off of some form of C++. Maybe one day i can get into C but i am not there yet.
So my question is
1. can i plug a basic stamp or pic microcontrollers into a arduino uno and start programming it in basic/picbasic. I have the software to send but i am thinking the arduino has a compiler that would not be compatible.
2. Can I purchase a microcontroller and choose the language i want as long as i have the compiler to put it on the microcontroller. for example if i purchased this guy http://www.fujitsu.com/downloads/MICRO/fma/mcu/n712635.pdf ... and all i wanted it to do was simple program can i do that?
You can probably tell by the question that I am new to this so help is appreciated.
Thanks
this post is to help me try to understand the different programming languages. I am using the basic stamp (2) currently so I am learning Basic . I am also interested in using PIC microcontrollers so I am reading up on picbasic (lucky not that different).
I started looking for a good microcontroller module (basically what i want is a good board i can plug my microcontroller in and be able to connect and program easy because previous attempts at soldering a serial connection ending .... not well ). I wanted to get the arduino uno but then i saw it works off of some form of C++. Maybe one day i can get into C but i am not there yet.
So my question is
1. can i plug a basic stamp or pic microcontrollers into a arduino uno and start programming it in basic/picbasic. I have the software to send but i am thinking the arduino has a compiler that would not be compatible.
2. Can I purchase a microcontroller and choose the language i want as long as i have the compiler to put it on the microcontroller. for example if i purchased this guy http://www.fujitsu.com/downloads/MICRO/fma/mcu/n712635.pdf ... and all i wanted it to do was simple program can i do that?
You can probably tell by the question that I am new to this so help is appreciated.
Thanks
Comments
Microcontrollers all come with their resident machine code that the manufacturers support with a set of Assembler Mnemonics for assembly language programing.
Plugging a non-Arduino CPU into an Arduino UNO board will likely be a disaster. Different chips do different things with different pins. Just try to compare where the crystal is located and the power connections -- often not the same.
Cross-compiling is when you use a different computer to write code and then load it to the target device. The market place for cross-compilers was historically full of extremely expensive software ... before Parallax came along with the BasicStamp and offer a free compiler.
The Propeller has a free compiler in SPIN and PASM. Others have created free compilers for C and a few other languages. And the Propeller even has interpreted languages, such as Forth (also for Free).
But if you want a different product, compilers and languages can get expensive. Mostly, C is the only cross-compiler that sneaks in a free version due to Linux gnomes generating code for such. But it is pretty much a 'play, you pay' world outside of Parallax, Linux, and Arduino.
Finding a board that will allow a BasicStamp or a PIC to plug into Arduino shields might be possible. But I am not sure there is much to be gained by doing so. Arduino dedicates i/o pins to specific tasks and creates a significant limit to how much i/o is available. The chips you mention can do more with more i/o pins, if you build your own boards.
++++++++++
In other words, you have started on what is rather a long journey and want to skip way ahead of where you are. Every time you change to a different brand of microcontroller, you will be introduced to a different way of doing business and a different way of programing. I am not sure why you want to use Fujitsu 8bit microcontrollers when PICs are about the same level of usefulness.
Try not to get ahead of yourself. Try to learn C (it will save you $$$). And enjoy the fact that Parallax offers a lower entry cost with good support for learning. Parts of the world out there are brutal.
I think i will stick with basic and picbasic and when i get good at those i will go onto C.
sounds like i am going back to the soldering board.
Here is a link to Mr. Kernighan's classic C tutorial.
http://www.lysator.liu.se/c/bwk-tutor.html
I printed this out and found the first 16 or 17 headings of about 28 heading were everything that PBasic included in core programing functions - loops, branches, basic maths, etc. After 16 or so, is the additional stuff that C includes to provide more power.
Modern C on the Propeller will have some differences, but the core will be there. Try to not get mixed up about C and C++. The Propeller supports both.
If that tutorial makes you want to read more. Try learning C in Linux on a real PC with a modern tutorial. (I suggest LInux over Windows as all the software and books are available for free, and you will find better help from others on-line).
You can use Puppy Linux on a Windows computer from a Live CD or USB stick without affecting Windows.
And read the complete classic ANSI C text by Richie and Kernighan. There are free downloads available.
+++++++++++++++++++++++++++++++++
C on the Arduinio is NOT what a user would expect generic C to be.
Arduinio has created its own world of Wiring and Sketches and hidden the most important Main( ) from the user in order to disguise the fact that it is really generic C under-the-hood.
Being generic C and pretending to not be can get confusing and actually create an unnecessary dependency on Arduino code and its resources. C on the Propeller is pretty much the real thing, without the nonsense.
You can use generic C with the Arduino Uno, by buying a programming device and NOT using the Arduino Boot Loader/usb port. But that might be a wee bit too advanced for you at this point.
Arduino wants you to stay loyal to Arduino, so 'going the other, more generic way' is not supported.
You would have to work with an OpenAVR community to learn to do things without Wiring and Sketches... the way real programmers work.
First off, welcome to the forums!
Second, don't give up on C or Parallax so easily. Parallax is very much into building an education program around their Propeller Activity Board and C. Check out these tutorials, they will take you through general C programming concepts and then get into building circuits and writing C to control those circuits. The site for learning C is here.
The whole process isn't nearly as dreadful as some make it out to be and the Parallax forums are very helpful to beginners that show they want to learn.
Check out the Parallax Learn site for C and you'll probably start to understand C very quickly before you even have a Propeller to program!!
Any Arduino can be programmed using only C (utilising none of the Arduino functions) via their IDE.
People hit up the knowledge base that is their Forum for problems with all manner of breadboarduinos, PLA-duinos du jour and "DIYduinos".
Their site shows how to make your own on a breadboard.
Buy the Activity (WAM) kit: http://www.parallax.com/product/90005
Or the BOEBOT kit: http://www.parallax.com/product/28832
Sometimes the pages show a big blank area. Scroll down to see more info. What's up with that anyway?
If you intend to do workstation type applications, C is the ideal choice.
If you intend to focus on embedded, as in time critical, you can also use C, but FORTH is considered by many a more focused and streamlined tool for embedded.
If you just want to get your feet wet and try stuff, basic is great, but you often we run into basic's speed and size limitation rather quickly.
Of course the BS2 with a mere 32 bits of RAM space would never work.
There will come a time when you want to do more and the Propeller really is where to go. The QuickStart board has a USB interface. The ProtoBoard can use a simple RS232 interface or a USB to RS232 adapter.
If you desire to avoid soldering, that is what the little white breadboards are for. And the Propeller does have a board available that can adapt to using Arduino shields in some cases.
I could use that on the archiver! gets past the whole interpreter thing!
You find only tests and branches in machine code, so how do you get a loop? A loop is a backward branch (to a lower memory address). That is really all there is too it.
The rest of the stuff is pretty straight forward if you take each Basic instruction and try to imagine a way to do it in Assembler.
The Propellers assembly language is especially nice for this as it is simple, elegant, regular and very easy to play with from Spin programs in the Prop Tool.
However our opening poster is obviously just starting out with micro-controllers and I don't think starting with assembler is a good idea. Sounds like what he needs is a ready to run system like a Propeller board, or an Arduino, etc. With that experience under his belt he will know what possibilities there are to explore. This is certainly not true. I keep seeing statements like this re: assembler recently on various forums. What's going on?
Are you suggesting that pretty much every program anybody ever uses is still only a prototype?
(Don't answer that, I believe that is true but not because they are written in a HLL)
Assembler programs compared to HLL are:
a) Bigger, source code wise, for any given functionality.
b) Harder to write, takes longer and is more error prone.
c) Harder to read and takes longer to understand.
d) Harder to maintain/modify.
e) Not portable across machine architectures / operating systems.
f) Often not much better performing than equivalent compiled code.
g) Often not much smaller binaries than equivalent compiled code.
In short there is no reason to use assembler unless there is a very pressing need to, mostly relating to extremely limited resources like speed and code size or needing to use instructions that compilers don't typically generate. All assembler, all the time? !
I'm really curious to know what sorts of applications you have worked on that demand this.
Loopy, Major? What is so major about: Even a complete beginner who had never seen a program before might guess what that is supposed to do.
Hardly more obscure than looping in BASIC.
Interesting example in a nonsensical way. You use a JMP, not a Branch to create an infinite loop that will perpetually add a and b. I should have mentioned jumps as well as branches.
My point is that studying the Mnemonics for Assembler will never show you how to create a loop. And so, a BasicStamp2 programer trying to take a PBasic list and compare it to what a microcontroller's PDF might list as an instruction set would come up short.
Your example relies on the Assembly language compiler to create a name called "Loop" and then to return to it.
I stand corrected, "A Loop is a backward Branch, or a backward Jmp."
Of course, that implies that forward Branches and forward jumps have different uses... And your example demonstrates how my we all depend on the IDE for the Assembler to make Assembly language easier.
Might guess, or might not. That is a 50/50 chance.
"nonsensical"? You ordered a loop, you got a loop.
A jump and a branch are the same thing. Whether they are conditional or not is another matter. Perhaps true. Yes, where are we going with this?
Programs that convert assembly language source into binary are called "assemblers". "Compiler" is generally used to describe
translators of high level languages. How so? A simple text editor will do.
Take this example from the Propeller Manual:
Now, let's throw out everything that isn't relevant to the assembler program (all the Spin wrappings, which are important to make the example run but not to this discussion):
I took the liberty of adding the COG address of each register for reference. That's essentially what the assembler does with label, just makes a note as to what address it was generating contents for when it sees a label so it can use it later.
Next step, remove all the labels that the assembler keeps track of. Still runnable code when put back inside the Spin wrapper, it still assembles in the Propeller tool (actually, you get an error because I removed Toggle but that's a Spin issue not an assembler issue).
EDIT: I just had to replace the above code after I tried to run it on a Propeller board - I had some addresses wrong. Thus the reason we let assemblers do our bookkkeeping!! Hand assembly is error prone!
Now, if you want to ease the work your assembler does one more step, you can replace dira, cnt, outa with their register addresses. It will still work.
The assembler/ide/whatver isn't doign anythign magic, just helping with the bookkeepping of addresses. The next step is to decode the instruction mnemonics into the actual bits that make up each instruction....we'll leave that for another example.
The point is, the assembler isn't magic jsut a simple aid to the programmer it doesn't generate any code on its own and only does what you tell it to do.
I'm sure most old assembly programmers have at one time or another sat down with a pad of yellow paper and started writing a program and doen what the assembler does, track addressed and generate the binary contents of words.
I think it is a good skillfor any programmer to have, especially if involved in embedded systems or any other system level code. When you understand the assembly language for a machine, you can even get along fine without real hardware, you just "play computer" and step by step go through each instruction and follow the changes it causes in the hardware.
I'm currently burshing up on my PASM and finding that often I am overthinkig it and just need to remember it literally is one instruction at a time and isn't complicated as long as you keep track of teh things that are going on in the hardware.
For me, addressing modes usually cause trouble. The Propeller has few, so it is very nice in that respect. Loops via jumps, branches, etc, you are just changing where the hardware takes teh next instruction from - forward, backward, conditional or unconditional, it doesn't matter - just go there and execute that memory content as an instruction.
No, it won't but once you learn how to do it and the basic idea behind creating a loop in assembler, you know pretty much how ANY other computer language creates loops at the very heart of its operation and you understand why some loops are better than others. Down deep, everything comes to individual instruction running on the hardware.
That's the beauty of it, the assembler doesn't CREATE anything! You as the programmer, creates everything, teh assembler just helps you remember by letting you put a label on that memory cell you want to be the beginning of your creations (and only that cell).
Where is this all going? It is helping a rank begineer that depends on Basic see how to make a move over to using assembly language programing. What may seem obvious to you as a seasoned programmer can easily be a source of frustration to a rank beginner.
Teaching is NOT about clever debate, it is about helping others to notice what they have overlooked or can't seem to grasp.
For instance, it may be quite obvious to you what code on the Propeller in PASM resides in a cog and what code ends up residing in the Hubram and how they interact. But actually teaching this to a begineer is all about helping them to notice the differences between code that is intended for the two desiginations, and how the PAR register works. None of which is taught in the Propeller Manual. (It is explained in terms that presume the reader knows how to envision what is going on.)
What may seen pedantic to you, can be quite difficult for others.
Those "Spin Wrappings" are a must have item. Throwing them out is likely to put a novice into a complete tail spin. Face it the Propeller is special about loading PASM. It doesn't just start a a low address and go forward. It requires a CogNew or a CogInit to get any of the processors running.
Teaching is all about helping the learn to notice ALL that is required.
The above loop example is basically an endless loop like a "repeat" with nothing after it in Spin or a "while (1) { do stuff}" construct in C (see, if you understand the assembler, you can pretty much figure out the basics of how other languages REALLY loop down deep.
Loopy, how about a "for" loop or a "repeat n" looping construct?
The interesting little bits here?
1) Added a new "variable" Count which will hold the number of times you want to loop (the number of times you want to blink * 2)
2) changed the "jmp #:loop" to a "djnz Count, #:loop" - in this case this instruction will decrement Count, check if it is non-zero and take the jump if it is. If it is zero, the cog just falls through to the next instruction.
3) added a 'jmp $' after the djnz just to stop the cog from running through its data as instructions (it will happily do that) - 'jmp $' just jumps to itself, $ is what the assembler uses for the address it is currently at.
So these changes made the loop into a "repeat 40" or 'for (i:=0;i<=40,i++)" type loop.
Loops aren't that tricky!!
Ok, I went and update my original examples to not the importance of Spin ndthe wrapper.
Your comment:
Is even a bigger disservice to learning in my opinion. As Heater pointed out, it is an assembler and does what any assembler does, not a compiler because those do different things. May seem a trivial distinction for a rank beginner but it is an important concept that if misunderstood will haunt later learning.
It is very misleading to say it will create a label then return to it. Assemblers shouldn't create anything and will not generate the code to return to anything which is how I read your statement. If you go into writing assembler of any kind thinking it will create the jump that returns to some place, you will execute a lot of data as instructions before you figure out that the PROGRAMMER IS IN CONTROL and must cause the code path to return to some place.
I agree with pretty much all of that.
That's why I was being annoyingly picky over definitions. Best not to confuse beginners with incorrect info. It's not just "clever debate".
You are right to say that what is obvious to old hands can be clear as mud to a beginner.For this reason an introduction to assembler perhaps should not start with mnemonics but rather with architectural concepts. What is memory? What is RAM vs ROM? What is a memory location and how can be seen as place to store a variable? What's a variable here, better discuss binary numbers. What is an instruction? What does it mean to execute an instruction? What actually is the CPU? And so on and so on.
All of this is perhaps off topic given that does not mention but programming languages, presumably higher level, like BASIC, PICBASIC, C, C++.
My advice here is really to get a dev board that is ready to run and become master of that. Then perhaps master another one. The Jason will understand why one cannot plug a basic stamp or pic microcontrollers into a arduino uno and start programming it in basic/picbasic.
Of course being a Propeller forum I would suggest getting a Propeller board and getting to grips with Spin. An easy step up from BASIC and a lot more powerful and interesting machine than the STAMP or most PICs and Arduinos.
I guess originally high level languages were written in assembler and hence required good assembler programmers. A nice example of this is Leor Zolman's BDS C compiler for the CP/M systems.
This is no longer generally true. Those machine architecture and assembler experts today write their compilers in high level languages. GCC is written in C, Clang is written in C++, for example. Then we find that language parser experts or optimization experts may not even know anything about target architecture of the finished compiler. That's down to the guys that write the code generator back ends.
This is the only sensible way to do it because a compiler is a complex thing and you need all the high level language support you can get. It's essential if you want your compiler to be usable on many different architectures. Not quite. I started out programming microprocessors in HEX. We had to do all the assembling manually Perhaps true but the loss is not so as great as to make it worth worrying about in the vast majority of code. If we had to use assembler for everything we would not have a fraction of a percent of all the useful software we have now. It would just take too long to create.
In fact it is quite possible for a compiler to out perform hand crafted assembler. For example by using OMP (Open Multi-Processing) it is possible to fairly easily spread your codes work load over many CPU's. For example: will spread that array operation over as many CPU's as you have. I suggest doing this in assembler is not so straight forward.
Of course HLL programs can gain a lot of performance by being recompiled for a new improved or totally different architecture. Assembler programs would need a rewrite.
The purpose of programming is to do work for us that we would rather not do ourselves. Or indeed cannot do ourselves.
Out and out performance is not the only requirement, or even the primary requirement.
Clearly high level languages have objectives, as outlined above.
If your statement were true then all programs for all super computers would be written in assembler. I think you will find they are not.
That python script that I create in an hour and gives me results in seconds is seriously outperforming that assembler equivalent program that you have spent a month writing and debugging and gives the same results in milliseconds. The whole project from idea to results can be thousands of times faster than assembler.
You said you have a Basic Stamp 2 and are interested in a Pic (Picaxe). What carrier do you have for your Basic Stamp? Have you worked through the What's a Microcontroller book mentioned in another post?
Why are you interested in a Pic or Picaxe (I forgot which). What do you wnat to do with it that your BS2 can't do?
What kind of projects do you have in mind? Are you a student? Are you a hobbyist? Are you looking into this for career teasons?
I think we've given you a number of ideas and a long detour into assembly language programming (sorry for helping wkth that derail). All of this was based on us guessing what you want to do.
Sadly, the answer was no to your first two questions. Hopefully you have a bit better understanding now of why that is.
We can try and help more if we have a better idea of what you want.
You have to excuse, sometimes things come up on threads that we find interesting or good matefial for debating and we get distracted!