Programming concepts

Status
Not open for further replies.
How can i understand the concepts of programming microcontroller.
If you really want to learn the fundamental concepts, I'd suggest looking at the block diagrams and assembly programming language of a simple PIC microcontroller, eg.



Assembly language is in effect a human-readable version of the machine code (the binary instructions the CPU reads and executes) using mnemonic names rather than the binary values.

Something like a PIC has a small instruction set, so fairly easy to understand - that one only has just over 50.
In comparison, something like a current PC CPU has thousands!


Or, if you just want to be able to program a device to make it do things, then an Arduino is the simplest route.
Those are normally programmed in C language (or C++), a high level language which is converted (compiled) to suit the instruction set of the target device by the Arduino programming package.

There are also thousands of existing projects you can just download, compile and run, with an appropriate arduino board connected to your PC via USB.

C is the most versatile language overall as it can be used with an appropriate compiler to create programs for anything ranging from a tiny 8 pin MCU, through the range of devices & systems up to supercomputers - but that also means the "mechanics" of the CPU instructions are hidden away from the programmer.
 
Thanks
 
Kids, and now adults for some specific quick turn projects, are using a
visual approach called block language programming. This is where you
drag and drop function blocks, like



The above is a very simple application, read a voltage and set a PWM duty cycle, its pulse width,
proportional to that voltage. Here its trivial to do, the blocks are dragged out of the 2'ond window
from left, and placed in 3'rd window, and configured, like pin number to read, pin number to output
PWM signal on. As you do this mBlock, this particular program, converts the block configuration into
Arduino code (C like code) and programs it. Thats the code you see in right hand window. Kids are using
this in 6'th grades to program robots and their movement. I use it to do fast turn around of simple stuff,
like below link. More complex stuff I do in C.


Here is what would have been fairly involved project, to do wireless application, done in Tuniot -


If you learn one block language there are quite a few variants, and its easy to do the other variants
because all the principals pretty much the same. mBlock, Snap4Arduino, Scratch, Visuino, Ardublock,
Tuniot.....

Then there are visual ones that do it like flow charts, Nodered, flowcode, in a flow chart format.

C code is called, rightfully so, a "strongly typed language". It means its not forgiving in the way
you type the instructions and code, how you use variables, etc.. So learning curve if you have never
programmed a tad steep, as is Assembler, appropriately called machine language, where you are
deep in the processor logic and its hardware.

But all people who have used a 4 function calculator have been programming most of their lives.
But the programming done in ones head, eg. the sequence of math operations, the type of operations,
all done typically in our Gerbil brain pans.

If you start with mBlock or Snap4Arduino, software is free, a low end but capable board ~ $3, Arduino
Nano, and a USB cable will get you started.




Regards, Dana.
 
Thanks
 
I am surprised no-one has said this yet: Start a project.

By the time you have it working, you will have learned a lot.
For example, say you have a lot of houseplants, make an automatic watering controller.
Do you free-lance? Make a time-keeping gadget. Your other hobby is cooking? Make your own sous vide controller.
It doesn't matter what the project is.
 
Ok but what programming language is good for microcontroller?
I have never programed one before
 
Ok but what programming language is good for microcontroller?
I have never programed one before
Get an Arduino to play with, a Uno is a good choice - cheap and easy, using C++ (a superset of C), with millions of examples and tutorials available on-line. Don't mess with silly kids 'block' programming - unless you are a young kid of course.
 
Last edited:
Some would say unless you code in ASM at machine level your

just in childs play.


Some would say unless your projects start with AI and Tensor

analysis that your project is simply a dud on arrival.


Some would, and did, say using computers is pointless.


Some would say that the earth is flat or round, while in fact

its neither.


Its well understood in academic and business circles there

are various ways of learning, visual being one of the significant

ones.


IBM seems to think block/flow chart programming an important

contribution - https://developer.ibm.com/components/node-red/


Anyways watch a couple of videos, do same for C, learn both.

But if you just start with block note that you can see/look/modify

the generated C code, an intro to learning and seeing how C is

done while you are doing it.


And to close some would say its impossible to give a computer

a system/task description, voice or image, and that system in

turns generates all the code for the requirement. But those

folks would be wrong as well, its right around the corner.


Regards, Dana.
 
Imagine your first day on a building site. Your boss says "you said you could lay bricks"? You reply, I'm an expert with Lego! Learn C, it's universal.

Mike.
 
In my opinion, if you want to learn what is going on "under the hood" is to get a grasp of Assembly programming, at least at first.
I'm sort of biased, because I have done it this way since My first, which was a PDP8 back in the late '70's.

PS:: In fact Nigel's tutorials are still up there!
 
In my opinion, if you want to learn what is going on "under the hood" is to get a grasp of Assembly programming, at least at first.
I used to be of this opinion too. However, I find C to be very close to Assembler.
What is the difference between,
Code:
    BANKSEL    ADCON1
    movlw    b'11000000'    ; right justify, FOSC/4 vdd and vss vref
    movwf    ADCON1
And,
Code:
   ADCON1=b'11000000';    // right justify, FOSC/4 vdd and vss vref
I don't see how you learn more with the assembler version than the C version.
As long as you don't use provided libraries then you still need to learn the underlying hardware.

Mike.
 
I as well did PDP8 and 4004 assembler in first job.

Not in a hurry to go back to paper tape and non gui environments.


Regards, Dana.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…