Maker Pro
Maker Pro

Help Getting Started with PIC Microcontrollers

The worst thing about the 8-bit PICs' stack architecture is the size of the stack. The very smallest ones only have two levels! That means that function A can call function B, then function B can call function C, but function C can't call any functions! In other words, the device only supports two levels of function nesting. This is acceptable for very simple programs and programs that use tricks to work around this limitation, but it's a big nasty limitation. Even with the larger 8-bit PIC variants you have to be aware of the limited stack size.

:eek: Does this mean "If, Then, Else" would be the most it can process at once?
 
Thank you so much Kris! I didn't expect to get such a in-depth response! I understand it a lot better now. :)

Following your two stack A,B,C function example: Would that mean that function C couldn't call a "printf()" because a "printf()" is pretty much just an included function?

Thanks again Kris! :)
Dan
 

KrisBlueNZ

Sadly passed away in 2015
:eek: Does this mean "If, Then, Else" would be the most it can process at once?
No. The code generated for if/then/else doesn't use the stack.
Code:
test the conditon
if the condition is false, go to false label
execute the then clause
go to done label
false:
execute the else clause
done:
continue...

Following your two stack A,B,C function example: Would that mean that function C couldn't call a "printf()" because a "printf()" is pretty much just an included function?
That's right. Function C couldn't call anything - not another function in the main program; not a library function.
 
Well just as kind of a update, my PICkit three got here today! After a couple hours of using it, I found that it's not as bad a Dave Jones made it out to be. MPLAB X isn't that bad either.

I did come upon a bug though, when I first tried to download a program onto a PIC, MPLAB told me that "PICKIT 3 firmware version is too old. You must have firmware version 01.28.08 or higher" (or something like that). I did some googling and came upon this thread on the microchip website forum. They said that you had to downgrade MPLAB X or use the older software MPLAB to update the firmware. Well I didn't want to downgrade MPLAB X so since I had downloaded MPLAB a while back I decided to go down that route. I was able to upgrade the firmware with MPLAB but it still gave me that error message in MPLAB X.

Luckily MPLAB X also came with this handy little programing utility, and with that I was able to program my first PIC error free! :) After programing the PIC a couple times, MPLAB X started working. So I guess I'm good to go for now. :)

Thanks to all you guys! :)
Dan
 
Well just as kind of a update, my PICkit three got here today! After a couple hours of using it, I found that it's not as bad a Dave Jones made it out to be. MPLAB X isn't that bad either.

I did come upon a bug though, when I first tried to download a program onto a PIC, MPLAB told me that "PICKIT 3 firmware version is too old. You must have firmware version 01.28.08 or higher" (or something like that). I did some googling and came upon this thread on the microchip website forum. They said that you had to downgrade MPLAB X or use the older software MPLAB to update the firmware. Well I didn't want to downgrade MPLAB X so since I had downloaded MPLAB a while back I decided to go down that route. I was able to upgrade the firmware with MPLAB but it still gave me that error message in MPLAB X.

Luckily MPLAB X also came with this handy little programing utility, and with that I was able to program my first PIC error free! :) After programing the PIC a couple times, MPLAB X started working. So I guess I'm good to go for now. :)

Thanks to all you guys! :)
Dan
Sweet Dan, mine is coming too!!
 
Luckily MPLAB X also came with this handy little programing utility, and with that I was able to program my first PIC error free!

I was going to say that I had to go the same route because MPLABX didn't allow me to create a project for my PIC18F44K22 (it wasn't in the list of choices) but I just saw that it's in there now, so either it was added or I missed it. Anyways, the point is that I've resorted to compiling stuff with the IDE and using the programming utility to upload the .hex file.

Would the fact that you used MPLAB instead of MPLABX to upgrade the pickit 3 firmware have anything to do with it not working correctly?
 
Would the fact that you used MPLAB instead of MPLABX to upgrade the pickit 3 firmware have anything to do with it not working correctly?
No I don't think so, because MPLAB X wasn't working before I upgraded the firmware with MPLAB. And right after I upgraded the firmware with MPLAB, MPLAB X was still giving me that error. It wasn't until after I used that programing utility a couple times that MPLAB X started working right. :)

From googling around it sounds like you can't update the firmware with MPLAB X at all! It appeared that there where a couple other fixes for that error that didn't require a downgrade, but I didn't understand any of them...
Sweet Dan, mine is coming too!!
Awesome! You'll have to tell us how you make out with it. :) Are you going to try and program in assembler or C? If you go down the C route like me, the book I referred to in post #79 is really good so far for learning it!
Dan
 
Awesome! You'll have to tell us how you make out with it. :) Are you going to try and program in assembler or C? If you go down the C route like me, the book I referred to in post #79 is really good so far for learning it!
Dan

I tried to get the Dummies book from the library, they had a listing for the "C" version, but when the book came in it was c++. I took it anyway. I have been watching some video's on μcu's and can't honestly answer your question right now. Thanks for the review, I will try again to source it - I take it that it is simple to follow then? I like simple :) I get bored very easily reading "stereo instructions" and that has been my biggest hurdle with learning a computer language - I need hands on programming to keep my interest.
 
Actually I was referring to the book "PIC Projects and Applications Using C". Amazon has a preview of it here, unfortunately it's kind of pricy for it only being 183 pages... Yeah I'm a lot like you, I have tried more than once to work my way through one of those big boring text books, but I never got more than a couple chapters in. :D

This book isn't quite like that, he has you blinking an LED with a PIC in the second chapter. And then he builds from there. The first chapter goes really quick (it's only about two pages). I'm about half way through chapter three and so far it has been really easy to understand (and fun!). What he does is have you program a new code into the micro and watch it work, then he explains how each line of code works. Then, he goes on to the next concept.

One of the last projects in the book is making a voltage meter with a 16x2 LCD, so he does cover a lot of ground. :)
Dan
 
Actually I was referring to the book "PIC Projects and Applications Using C". Amazon has a preview of it here, unfortunately it's kind of pricy for it only being 183 pages... Yeah I'm a lot like you, I have tried more than once to work my way through one of those big boring text books, but I never got more than a couple chapters in. :D

This book isn't quite like that, he has you blinking an LED with a PIC in the second chapter. And then he builds from there. The first chapter goes really quick (it's only about two pages). I'm about half way through chapter three and so far it has been really easy to understand (and fun!). What he does is have you program a new code into the micro and watch it work, then he explains how each line of code works. Then, he goes on to the next concept.

One of the last projects in the book is making a voltage meter with a 16x2 LCD, so he does cover a lot of ground. :)
Dan

That is more my speed ;), you are right though, it is a bit pricey!
 
I like simple :) I get bored very easily reading "stereo instructions" and that has been my biggest hurdle with learning a computer language - I need hands on programming to keep my interest.

When I first started learning microcontrollers someone pointed me to http://www.gooligum.com.au/shop/PIC-tutorials

He does an amazing job teaching you the ins and outs of programming and the microcontroller hardware, he even has dev boards that you can by so you can follow along. The website appears to have changed since the last time I have visited so you may have to pay to view all of the tutorials but if you're looking for a cheap and fast way to learn microcontrollers and programming at the same time I highly suggest visiting this guy's website. He teaches all concepts in both assembler and C.

I am in no way advertising for him, I just found his information VERY helpful so I thought it would be beneficial for people just starting out
 
When I first started learning microcontrollers someone pointed me to http://www.gooligum.com.au/shop/PIC-tutorials

He does an amazing job teaching you the ins and outs of programming and the microcontroller hardware, he even has dev boards that you can by so you can follow along. The website appears to have changed since the last time I have visited so you may have to pay to view all of the tutorials but if you're looking for a cheap and fast way to learn microcontrollers and programming at the same time I highly suggest visiting this guy's website. He teaches all concepts in both assembler and C.

I am in no way advertising for him, I just found his information VERY helpful so I thought it would be beneficial for people just starting out
Funny you should mention that, I did come across that today when I was looking for dev. boards, thank you though, I already saved the intro page and will look it over lunch today :) Thanks again.
 
I take it back! That book I was talking about gets pretty bad as you go along.

The chapter about the ADC is when it starts, up until then he explained every thing pretty good. He goes through each register and "explains" it, but it's really hard to follow him. I made it through that chapter, probable since I already knew some C.

Then the chapter on alphanumeric displays comes along, and at first he gives you an okay explanation of how they work. Then he lists some code (and a schematic) that will supposedly display something like "& t float abc Ωμπ". So I type it up, and when I have finished I try and build it but I get a bunch of errors. So I think that I may have typed it wrong, so I go to his "website" where he has the code in the book free for download. So I download it, paste it in to the editor, and hit build. I got like five errors! Come on guy, do you even test you code before you put it in a book?

So, I was pretty up set and I picked up my book on C (C for dummies all in one desk reference) to try and figure out his code. As I'm looking through it I notice a page that had something about a little * character on it (which the guy used it his code). I had no Idea what it was so I looked into it a little deeper. Turns out it's how you do Pointers!! From what I have heard, pointers are one of the hardest things in C! And this guy had them in his code for beginners in C and said 100% nothing about it! It appeared he expected you to figure it out for yourself!

I guess now what I'm going to have to do is contact the guy who wrote it and see what he says about this. Hopefully he give me some code that he actually tested without pointers.

When I first started learning microcontrollers someone pointed me to http://www.gooligum.com.au/shop/PIC-tutorials

He does an amazing job teaching you the ins and outs of programming and the microcontroller hardware, he even has dev boards that you can by so you can follow along. The website appears to have changed since the last time I have visited so you may have to pay to view all of the tutorials but if you're looking for a cheap and fast way to learn microcontrollers and programming at the same time I highly suggest visiting this guy's website. He teaches all concepts in both assembler and C.

I am in no way advertising for him, I just found his information VERY helpful so I thought it would be beneficial for people just starting out
Thanks so much for recommending that site!!! I probably would have never found it. :) It appears now that it might be my only hope for learning all this PIC microcontroller stuff.
Dan
 
Okay, so moving on, what exactly is more complex about the 16/32 bit PIC MCUs?

From looking around it looks like all the difference is, is more features and all the registers are 16/32 bits long...
Dan
 
Some of the PICs allow/require mapping the IO ports to pins, which makes programming a little more complex, but it makes it much more flexible. Further, the wider the bus, the more addressability is possible and typically the quicker the MCU is. It also simplifies wider arithmetic.
 
If you are totally new to uController, you may want to consider Flowcode (www.matrixmultimedia.com)

It is a visual approach to uCtrl programming, extremely easy to use (especially version 5. They are at version 6)

It will let you do a lot, before you have to start doing some C programming.

I'm pretty sure the code is not optimized, but when you start, you give a <beep> !!!
 
Some of the PICs allow/require mapping the IO ports to pins, which makes programming a little more complex, but it makes it much more flexible. Further, the wider the bus, the more addressability is possible and typically the quicker the MCU is. It also simplifies wider arithmetic.
Okay, that makes since! And it sounds quite doable for me... So next challenge: 16 Bit MCUs! :D
If you are totally new to uController, you may want to consider Flowcode (www.matrixmultimedia.com)
Well I wouldn't consider myself a complete beginner in MCUs, since I have done a lot of coding in C with them already... But who am I to say, I know there is a WHOLE lot left to learn. :) Thanks for your suggestion anyway though!!
Dan
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
Gentlemen, I gotta say that this debate makes me want to slide back under my (exceedingly comfortable) Picaxe security blanket. :eek:

Yes, I now realize their limitations compared to a blank PIC but the more I delve into ASM and C the more I appreciate what the folks at RevEd did and continue to do to entice (uC shy) students into the world of uCs.

On a positive note, I've enjoyed the ASM vs C debate. Even if I only grasp 30 to 50% it still valuable information and opinions.

Cheers,
Chris
 
Gentlemen, I gotta say that this debate makes me want to slide back under my (exceedingly comfortable) Picaxe security blanket. :eek:

Yes, I now realize their limitations compared to a blank PIC but the more I delve into ASM and C the more I appreciate what the folks at RevEd did and continue to do to entice (uC shy) students into the world of uCs.

On a positive note, I've enjoyed the ASM vs C debate. Even if I only grasp 30 to 50% it still valuable information and opinions.

Cheers,
Chris
I am waiting for my "I'm with stupid" shirt to arrive... I can't even get an IDE to function properly!
I am currently reading K.N. King's "C Programming - A Modern Approach" but have been eyeing FlowCode as well Chris, LOL

Interesting find!! - - > http://www.tutorialspoint.com/codingground.htm
Write and test code online!! Very cool and no setup issues with your pc :)
 
Last edited:
Top