Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C Microcontroller tutorial?

Status
Not open for further replies.
Ok. I think i will ask a better question, in hopes of a better answer.

How did YOU learn microcontrollers? (you as in the person reading this)
 
I built a COSMAC Elf 1802, and blinked the LED. I hated entering the program (with a hex keypad) everytime I turned it on.
SO I started programming my Commodore PET in both BASIC and machine language.
Years later the Microsoft macro assembler and Peter Nortons book (showed all the calls available to the PC kernal) and it was a good learning experience but PCs are NOT microcontrollers and as windows started taking over from DOS then assembler became more and more difficult to use and Object oriented languages became the way to use those systems.
Note: ever wonder why XP is so HUGE?
Anyway I got into PICs just before flash parts existed, I spend $$$ on a Parallax Clearview 5x (still got that too) and the well written Parallax app notes for it (about 15 simple assembly programs using CVASM). It was excellent, I could program, run and debug in no time. I was hooked. With only 31 instructions to learn it took no time to write those small programs and eventually burn them on to a PIC project. (I made a simple 16F54 program LED flasher way back that still runs today)
Then a much better ICE with an IDE (design enviroment one program that covers it all) you write your program, press a button and it's running.
BUT ICE pods cost $200 per PIC, and if you do something stupid then well bye bye pod.
I avoided the early days of C (CCS back then was absolute garbage, but only $99 so cheap garbage) and HiTech C was about $995 so I stuck with asm. The uber popular BASIC Stamp was also available and I got one, it was fun but extremly unpowerful and slow. Plus for $60 a pop it was too pricey for any embedded projects.
Now I've built the tools I'd use myself. All my kits are kits I'd buy if I could. I use them, the Junebug or Inchworm are both programmers AND debuggers! The tools are so cheap now and very powerful.

As I've posted in a previous reply.
You need a programmer (get a good one, ie one with a preprogrammed PIC as a brain & works with MPLAB so you'll always have new PIC support)
A debugger (it's built into some programmers, PICkit2, ICD2, Junebug, Inchworm) it's such a powerful tool it has become common on almost all modern microcontrollers. It's like a simulator but with real hardware.
Language
BASIC so easy to get the your first program running
ASM not so tough, and you will get smarter and only when you understand how a PIC thinks can you hope to master it (in any language)
C this is the most commonly used PIC high level language, you will need it for anything above the 18 series PICs
 
My experiences learning C with some of the links I found most help: **broken link removed**
Regards, David.
 
C on Pics

Bill and all,

An inexpensive C compiler and IDE is available from SourceBoost. The compiler is either free (for small projects) or at most $80 (US). It integrates with MPLAB well. I use it with MPLAB 7.6 and one of Bill's Inchworm+/Unicorn combos. SourceBoost IDE has a simulator built in to it that I use for debuging code snipits before I stick them into code that I actually run on the PIC under MPLAB. :eek:

There is also an RTOS that they have available. If you only need their pre-compiled version, it is free. They also provide an LCD routine and Serial routine in source form.

Also available is several other languages including Basic and C++. The Basic is currently in beta and is free.

If you look at the code that BoostC generates, generally it is what you would have written in assembler. When you write in C, keep in mind it really is a "sort of" high level language with a one byte view of the world. So if you are and assembler guy, it really won't take much to move to C. Learn the syntax and the constructs.

I have used it on things as small as 16F84As and currently on 16F628A/648A, 16F877A. It supports the 18F chips, but I haven't done anything yet.

Currently I am off playing with some IR stuff for remote controls. My DirectTV remote wouldn't turn on my Panisonic Plasma on and off correctly. Using some of Nigel's boards with and ICD installed for the Inchworm+ to run things with. I built my own version of a board for the IR that plugs into via one of the 10 pin connectors and also a serial board to write the stuff back to the PC to see what the codes are that the remote is generating.

So far what I have seen is that all the "old" doc on IR remotes is way over simplified and out of date. I found some stuff that gave me a lead on the what the Panasonic really is doing. It sends a 48 bit stream that includes a 32 bit device code followed by a 16 bit function code.

But, I have digressed. Bill, look at C, it won't take long to get up and running. You may find that simple things go together quickly and bigger stuff easier and more "wierd" bug free. ;)
 
blueroomelectronics said:
Obscure
JAL
Pascal (I actually liked Pascal on the PC, Alice Pascal was helpful and now free)

Pascal was the teaching language of choice, as it's well structured and encourages good programming practice - modern BASIC's are now more like Pascal than the old BASIC's.

Borland Turbo Pascal had the major advantage of being blindingly fast to compile, MUCH faster than any MicroSoft offerings.

JAL is certainly obscure though, it's a language written specifically for the PIC, with simularities to both Pascal and C - but it was designed starting from the PIC, not starting from a pre-conceived language.
 
I've got a nice programmer from a fellow forum member. I don't remember what it was called, though... i think it was an ICD clone, or something... yeah that is what it is. I had an LED blinker going, but i didn't even understand the program, so it really didn't help me. :eek: I was also using a really out-of-date pic
 
Marks256 said:
How did YOU learn microcontrollers? (you as in the person reading this)
It started with the Z80 in the early 1980s during my apprenticeship training at BCIT. Then some training on writing assembler for the PC (8088). Basically a micro computer course.
When I wanted to build something for myself, the 68HC11 was pretty popular so I ordered the data book from Motorola. Since I had the micro computer training, using a microcontroller was easy, once I read the book, because all I had to do was think of it as a complete system on a chip. My first serious micro project with the HC11 was an automatic TV antenna rotator. It would decode the IR from the TV remote and rotate the TV antenna in the proper direction. Now I have cable and it's in a box in the basement somewhere. The HC11 was an easy chip to get started with because it came with a built in serial bootloader and all you needed was a 5V-RS232 converter and some software.
I started with PICs because the HC11 was getting old, was relatively expensive, and it didn't come in smaller packages so was cumbersome for small projects. I've never liked the PICs Harvard architecture especially after working with the Z80, 68HC11, 6809, etc but it is a popular and cheap platform and I'm getting used to it now.
 
Marks256 said:
I've got a nice programmer from a fellow forum member. I don't remember what it was called, though... i think it was an ICD clone, or something... yeah that is what it is. I had an LED blinker going, but i didn't even understand the program, so it really didn't help me. :eek: I was also using a really out-of-date pic

It is an ICD2 clone very much like an inchworm. The one diff is that it expects the +5V from the target. It has a 1x6 molex and 2x5 pin header ICSP ports, IIRC.

The blinking LED programs are easy to understand in C or Basic. There is help here.

If you are NOT going to use it send it back or pass it on to someone who will ! :D
 
I am searching for the same pot of gold as you Marks....

I come from an assembler backround, that is being able to flash led's and do very basic programs. Time has passed without me doing any "programming". I know have decided to get back into developing things with PIC's.

I bought myself a ICD2 programmer,it cam with MPLAB and C18 compiler. The C18 is valid for 60days however you can still use it after the 60days. I also got some PIC18F252's to play around with. I have NO "C" experience however I have been searching on the web for tutorials....alas I didnt find anything substantial in helping to program pic's using C. All the books I have on C programming pertain to a PC and all state that the ONLY way to learn C is to start writing programs.....sound easy on a pc...but try it on a PIC when you dont know where to start.

After much irritation i managed to flash an LED on my pic aswell as get the USART to send some text to Hyperterminal using RS232. I am busy working on the ADC.... The guys here are very helpful...I posted my code that didnt seem to work and they spotted some mistakes and after many attempts I got it right with their help.

I am trying to develope an embedded web server using a PIC and ethernet controller. Connecting to the pic will be 3xanalog inputs that will be logged and a RS232 connection to the PC.

My main problem or frustration is knowing what is needed to be done, however not knowing how to implement using C. At first it seems difficult but i'm confident in the long run it will become easy...just have to get there.

Anyways if you come right with a C tutorial please let me kow and I shall vice versa. Good luck!!!
 
I've recommended this to a few people on here, and I'm going to recommend it to you as well.

This development board from Matrix Multimedia is excellent:
**broken link removed**
They also do CDROMs to accompany the package, where you're taken through Microntroller programming from the ground up. It's PIC specific, but the skills you will learn can be applied equally well to any Microcontroller. Applying them to a new Microcontroller would involve the same chores as for anyone who moves to a different device.
I got myself the Assembly and C CDROMs, but you could just get the C tutorial if you wanted. Personally I'd recommend you get yourself some experience with Assembly even if you don't program in it regularly because with Microcontrollers you're never really removed from the hardware and an understanding of Assembly sort of goes hand in hand with an understanding of the hardware to be honest.
The tutorials are excellent, they start off teaching you the programming language and then later you're taken through a set of lab tutorials where you're shown how to program PIC Microcontrollers. The programs you are shown (and those you develop yourself) can be sent to the development board so that you can see the results of what you're doing. I learned so much with these courses that I am more than happy to recommend them to you or anyone else starting out with Microcontrollers.

Brian
 
My programing path started 31 years ago... Fortran 74, BASIC, Z-80 assembler, Pascal, Modula2, LSI-11 assembler, Prolog, C, 68000 assembler... after which it blurs a bit, LOL. So to write C on the PIC all I had to learn was the architecture and the C18 extensions to cope with it. Oh, and a few assembler instructions for convenient instructions like rlcf

As for learning C on the PIC, I can thoroughly recommend the UBW hardware design and accompanying firmware using the 18F series with USB ports (18F2455, 2550, 4455, 4550.) The bootloader/USB combo lets you download new code easily. The UBW firmware source helps you learn C on the PIC quickly, and you can modify the code to try things out. Finally, the USB is also used in serial mode so you can DEBUG via hyperterminal, which also speeds the learning process up.

The UBW can be built easily on a breadboard, the free artwork for the PCB allow you to make one at home, and our friends at Sparkfun will sell you one as a kit or fully built.

Just my 2c,
Paul

PS: If you'd like to learn a bit of C before diving into the PIC/C18, you could try running Linux... it allows you to write "Hello world!" trivially easily and move from there using "standard" C tutorials. Linux is free... which is an excellent price :) (And yes, free as in open/libre!)
 
Hey 3v0... I too love the PDP11 instruction set for being so very orthogonal. It was even easy to edit in binary once you understood the octal bit fields for source and destination registers, addressing modes etc.

The guys at Motorola clearly liked it too when they created the 68000 :)
 
Brian Hoskins said:
I've recommended this to a few people on here, and I'm going to recommend it to you as well.

This development board from Matrix Multimedia is excellent:
**broken link removed**

It seems a pretty pricy $267 US, looks alot like the EasyPIC series of development boards.
 
3v0, don't worry. I AM going to use it. I just need to find a starting point that i can get my head around. :eek:

I like the looks of that kit that brian linked to, but i can't afford that.



aussiepoof said:
PS: If you'd like to learn a bit of C before diving into the PIC/C18, you could try running Linux... it allows you to write "Hello world!" trivially easily and move from there using "standard" C tutorials. Linux is free... which is an excellent price :) (And yes, free as in open/libre!)

Aussiepoof, i know you didn't mean it like i am making it sound, but i am a bit offended by that... I have been using NOTHING but linux for the past few months or so. UBUNTU 7.10 Gusty 64bit w/ NVIDIA drivers and Compiz Fusion (which is horribly unstable...) To keep this rant short, i am going to stop now... Oh, and i have already played around with C quite a bit. I am quite comfortable with it. I just want to get comfortable with C for PICs. I know that the basics are going to be the same, but all these configuration parameters confuse me.






I am ok with learning assembly. My only problem is, i am going to need some text that actually EXPLAINS things. I dont want the code dumped on me and leave me to figure it out, i want structure. I can't find anything that offers me that. :(
 
Marks256 said:
I am ok with learning assembly. My only problem is, i am going to need some text that actually EXPLAINS things. I dont want the code dumped on me and leave me to figure it out, i want structure. I can't find anything that offers me that. :(

The CDROMs I mentioned from Matrix Multimedia will give you that explanation, and they start from the very beginning. Again, I would highly recommend them. You don't HAVE to buy the development board as well, it only helps because you're able to test the programs more easily. At each stage they show you the hardware setup you'll need so you could just setup the circuits you're interested in and don't bother testing the ones you're happy with.

Brian
 
Mark256 said:
. I know that the basics are going to be the same, but all these configuration parameters confuse me.

If that is all that is holding back you should have said so.

Start by getting sampling these parts if you want my help.

18F1330's are 18 pin PICs that can be run up to 32Mhz using the internal OSC.
Get some 1024K Byte EEPROM 24FC1025-I/P and/or 24LC1025-I/P, you can use these to work with I2C.
If you are interested in doing the recorded voice thing from mondo you will want their digital pots MCP41010-I/P.
Do not order and 16F parts.

If you make this order I can have you up and running very quickly. The parameters are cook book stuff. I can give them to you. You can also figure them out from
MPLAB C18 PIC18 Configuration Settings Addendum
The PIC18 Configuration Settings Addendum is no longer published as a .PDF file. It is included with MPLAB IDE and MPLAB C18 C Compiler as on-line help.
 
Marks256 said:
Aussiepoof, i know you didn't mean it like i am making it sound, but i am a bit offended by that...
I didn't say anything offensive. At no point did you say you were quite comfortable with C. Nor did you mention Linux (use of which doesn't imply knowledge of C at all.)
I just want to get comfortable with C for PICs. I know that the basics are going to be the same, but all these configuration parameters confuse me.
Ah... the root of the problem at last! Using the UBW design and code might suit you well because you can see what they've done with config paramters and perhaps even ignore them for a bit while you get used to the C for PICs :)
I am ok with learning assembly. My only problem is, i am going to need some text that actually EXPLAINS things. I dont want the code dumped on me and leave me to figure it out, i want structure. I can't find anything that offers me that. :(
As you're comfortable enough with C then the UBW code is *very* easy to follow and modify and as I said the UBW hardware design can be built in a couple of hours or less on a breadboard so it's *very* cheap to get up and running.

Paul
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top