Next Step: Programming PIC directly

bpowell

Senior Member
Hello Gang,

I've been using Picaxe for years now, and to be perfectly clear: I absolutely LOVE my Picaxe chips and products!

I've been given a nice gift-certificate to SparkFun, and while I'll certainly stock up on a few more 08M2 chips...(Sparkfun got rid of the 20X2! Boo!) I'm also looking at a PIC programmer.

I don't know anything about PIC programming, but I'd like to get started, and I'd like to get started on the cheap.

I'm looking at the PicKit3 device...would this be a good place to start?

I'd like to be able to buy raw PIC chips, and learn to program on them to help enhance my understanding. I don't see myself getting away from Picaxe at all, but I'd just like to learn more.

I'm looking for some guidance from folks who know...and that's this group!

Ideally, I'd like to buy my programmer from SparkFun, as I have the gift certificate there.

I know Basic pretty well, but would be willing to learn C if that's the only language I can program PIC in (for free, or included with PicKit).

Thanks for your help / suggestions!
 

nick12ab

Senior Member
I don't know anything about PIC programming, but I'd like to get started, and I'd like to get started on the cheap.

I'm looking at the PicKit3 device...would this be a good place to start?

I'd like to be able to buy raw PIC chips, and learn to program on them to help enhance my understanding. I don't see myself getting away from Picaxe at all, but I'd just like to learn more.

I'm looking for some guidance from folks who know...and that's this group!

Ideally, I'd like to buy my programmer from SparkFun, as I have the gift certificate there.

I know Basic pretty well, but would be willing to learn C if that's the only language I can program PIC in (for free, or included with PicKit).
C is not the only language you can program PIC in assembly language and there are also commercial BASIC compilers available.

Consider purchasing AVR chips preprogrammed with the Arduino bootloader - you won't be able to drop in the chips into a PICAXE board but you get to use the free C compiler and you don't need that costly programmer. A simple inverter can be used with the PICAXE download circuit if you want to use the PICAXE download socket.

I've never done any proper PIC programming so can't comment any more.

I've never done any proper
 

Hemi345

Senior Member
bpowell:231756 said:
I've been given a nice gift-certificate to SparkFun, and while I'll certainly stock up on a few more 08M2 chips...(Sparkfun got rid of the 20X2! Boo!)
A few of us have asked why they retired the 20X2 and they say because it's obsolete and the 20M2 replaced it....
 

Dippy

Moderator
If you learn C then it gives you the ammunition to programme tons of different Micros , not just PICs.

Check out the free MPLAB XC from Microchip.
PICKIT3 is fine.

There are quite a few compilers kicking around.
If you are happy with PICAXE/Stamp BASIC syntax and structure then Proton or PICBASIC PRO are two examples of the next logical step up.
Or dive straight into C,
MikroElektronika do BASIC, PASCAL and C for PICs.
I'm not a fan of their compilers (from ancient experiences) but some people love them.

And then we have the Swordfish compiler. In the middle. It has BASIC syntax with a sort of C-ish structure.
It is superbly 'open' and flexible and is my favourite compiler for 18F PICs.

All compilers I've tried have the odd 'funny' so be aware.

Also be aware that you will need greater knowledge of the PIC hardware and have to read PIC Data Sheets.
You won't be able to seamlessly move to a compiler from PICAXE BASIC - where most of the hard work is done for you behind the scenes.
..and you will have to open your wallet.
The 'learning curve' can be a 'learning cliff' for many.

Much of this has been discussed on the Forum if you search and you will get many opinions and a lot of suggestions.
 

bpowell

Senior Member
I like the 64MHZ option on the 20X2...and I believe it has more program space as well...it's still for sale elsewhere. I saw where Sparkfun said it was a "slow mover" and hence they replaced it with the M2...but I'm curious how much faster the M2's are flying off the shelf.
 

bpowell

Senior Member
Dippy: Thanks for the breakdown!

Yes, I've lurked through these discussion threads before...but I was looking for some advice regarding Sparkfun offerings (which you provided, thanks!)

In just my limited research, I can see where the PICAXE code is doing a TON of heavy-lifting in the background...I realize I'll have to spool up on this knowledge...however, I'm hopeful it will enhance my knowledge of PICAXE as well!

Again, I'm just doing this for hobby...no production products or anything like that...I just want to learn.

Also, I'm not easily finding any forums for PIC programming that are aimed at the beginner...(something comparable to the PICAXE forum)...do you know of any?

Thanks again!
 

mrburnette

Senior Member
@bpowell:
Also, I'm not easily finding any forums for PIC programming that are aimed at the beginner...(something comparable to the PICAXE forum)...do you know of any?
I agree with Dippy, but the issues are twofold... you deal with PIC data sheets for h/w and the forum will be based on the flavor of BASIC compiler you select. You will not likely find a form as helpful as PICAXE... from experience.

An alternative is to enlighten your hardware and programming skills by moving to C/C++. The Arduino forum is significantly larger than PICAXE, not quiet as friendly/helpful (no handholding), but oodles of examples abound and an Arduino can easily be made an ATmel uC programmer with ONLY software. You can install your own boot loader on naked (cheap) chips and examples are numerous and well documented.

Now, learning C/C++ may seem crazy if you only want to do BASIC, but learning this will make you a better programmer (overall) and will even improve your BASIC skills due to logical thinking improvements... the same is true in my opinion of other structured languages - JAVA, Structured BASIC, even JavaScript.

- Ray
 

womai

Senior Member
Pickit 3 is fine. I personally prefer Pickit 2 because - apart from being even lower cost - it had a standalone programming tool available (I think they offer now one for the Pickit 3 as well). Programming a bare PIC with a Pickit is only marginally more complicated then downloading a program to the Picaxe.

As for compilers, C ist pretty much the standard in the professional world now (meaning if you ever intend to use your PIC knowledge in your job then by all means start out with C, not Basic), but there are plenty of Basic compilers around as well. No difference in terms of efficiency of the compiled code. I happen to like Mikroelektronika's MikroC, they also have Basic and Pascal (their latest compiler/IDE versions are vastly improved over what Dippy references to), and they offer highly usable demo versions for free (only limited by the size of the compiled code). But there are tons of other vendors and compilers.

I happen to be no fan of Microchip's standard IDE (MPLab), but have to admit that stems from the way it was a few years ago when I started out - at that time it was bloated, unintuitive and felt like a bunch of separate tools thrown together. Chances are it has vastly improved since then. Same goes for Microchip's own C compilers.
 

Dippy

Moderator
Yes, my experience of ME is years out of date.
I did have a quick look last week with a student at the latest free demo of ME C.
I only spent 5 minutes but the libraries still looked as closed as before. I probably missed a click.
And,yes, your experiences with MPLab are out of date - I, too, disliked old MPLab ... if you have time download MPLAB XC.
Let us know what you think as it has replaced Hitech.

Anyway, this wasn't intended to be a smarty competition so all I can say to bpowell is to download a few demo compilers a spend a few weeks getting to grip and seeing what you think.
... and, no, you won't find any other micro Forum as helpful and friendly as this one (even when we tease each other).
 

srnet

Senior Member
I only spent 5 minutes but the libraries still looked as closed as before.
If by that you mean you can't see the source for ME library routines, then you are correct, they dont publish.

Although you could read through the assembly generated ...............
 

womai

Senior Member
Dippy,

no, you didn't miss anything, the ME libraries don't come with source code. Guess they see it as a major differentiation against the competition. That said, I have encountered very few bugs so far (one to be exact - and it got fixed eventually), so as long as they do what you need then just use them and be happy. For other stuff I write my own libraries, but the built in ones are pretty comprehensive and get you started quickly. In many cases just as easy to use as Picaxe Basic (e.g. setting up the ADC and readin an analog value is just one short line of code - can't say that from Microchip's compilers...). They also have complete code examples in the Help file for each library function that you can copy and paste.
 

bpowell

Senior Member
Lots of great input, thanks all!

I don't imagine I'll find another forum as helpful as the PICAXE one! Good thing I don't plan on going anywhere!

I ordered a PICKIT 3 from Sparkfun...I've heard the PICKIT 2 was "better" in many respects, but, given SF doesn't carry it...and my gift-card was through SF...that made the decision easier!

I've also ordered a couple of PIC chips from Digikey...(the PIC version of my PICAXE favorites) so I'm excited to do a little playing.

I don't have a plan for these parts just yet...it's must an educational adventure for me. I think learning about the inner workings of these chips will further enhance my appreciation of what PICAXE does behind the scenes!

Thanks again everybody!

Brendan
 

mrburnette

Senior Member
<...>
I don't have a plan for these parts just yet...it's must an educational adventure for me. I think learning about the inner workings of these chips will further enhance my appreciation of what PICAXE does behind the scenes!
Before PICAXE was the BASIC STAMP... this will give you some insight before your PIC parts and programmer arrive:

PIC Source Book

- Ray
 
Last edited:

Flenser

Senior Member
I used the tutorials on the gooligum when doing my first PIC assember programming:
http://www.gooligum.com.au/tutorials.html

I found them excellent. They are based on Microchip's MPLAB software so you also get a walkthrough on setting up your project in MPLAB.

He also provides C tutorials but I haven't tried these.
 
Last edited:

bpowell

Senior Member
Thanks Flenser, I'll check this out. I don't have a desire to learn assembly just yet, but I do want to learn c.
 

bpowell

Senior Member
PIC Programming Update!

Well team, I thought you'd like a quick update on my PIC programming experience:

  • My computer desktop is littered with datasheets: Chip datasheets, Programmer datasheets, Chip Configuration sheets, Compiler datasheets, MPLAB Datasheets, etc. I've printed about a ream of paper just trying to keep up.
  • I've bought some PIC chips from Digikey...
  • I've "Bought" my programmer (PICKIT 3) from Sparkfun...I've also had to go back an order a USB serial cable since it doesn't appear you can have serial comms with the chip using the PICKIT3 programmer (the way I enjoy with my PICAXE)
  • After countless hours of pouring over datasheets, unfriendly forums, looking at example code, and trial-and-error: I WAS ABLE TO BLINK AN LED!
  • Yes, it was quite an accomplishment...I'm blinking an LED on a PIC chip. My favorite part of that project so far: When you want to use a delay, you have to write your own delay subroutine!
  • I've now moved on to serial communications...I'm trying to utilize the chips EUSART to send simple serial data...according to my MPLAB simulator, I've got that working as well...my O-Scope shows different results...but maybe I'm just not understanding what I should be seeing...the proof will be when I get my serial / USB cable in so I can try to talk to the PC directly.

(I don't even want to tell you how many hours and what level of personal (and family) suffering have gone into this serial communication program!)

Bottom line: I suppose learning C and the PIC is interesting...and it's rewarding once you get a project working...but when it comes to speed, ease, user and community friendliness...in my opinion: PICAXE can NOT be beat!

I'll keep you posted as I learn more!
 

BeanieBots

Moderator
Congratulations getting your LED to flash.
Serial comms can be fun without ready-made commands like serout/serin.
It's very easy to take PICAXE for granted but there's more done for you than the average user will ever appreciate.

When you've mastered serial, have a dive into using the ADCs and see what's involved with something like ReadADC10.
(save ReadTemp for a very rainy day!).

Even once you have mastered it all, I bet you'll still use PICAXE for those "get it going quick" projects.
 

womai

Senior Member
Many modern compilers for PIC come with lots of libraries. MikroC is one example but there are others: It has several demo programs (LED flashing is one of them) that are ready to use and only a few lines of code. When I started it literally took about one minute between the first power-up of my development board and havind the LEDs blink. Reading an ADC is one line of code (because there is a library function for it). Sending serial data is two lines of code - one to set up the comm baud rate, one to send the actual data. I am not sure what Microchip's own C18 compiler offers in this respect.
 

bpowell

Senior Member
Thanks Womai...however, MikroC is another $250...so I'm not able to part with that kind of cash although it certainly sounds like it'd be nice!
 

bpowell

Senior Member
Thanks BeanieBots!

Yes...ADC and ReadTemp may be next on my agenda...first things first though...serial comms!
 

womai

Senior Member
Thanks Womai...however, MikroC is another $250...so I'm not able to part with that kind of cash although it certainly sounds like it'd be nice!
The demo version is free and not restricted in any way except for the size of the compiled code (2K); the limit is actually pretty generous and I have developed several full applications that stayed within this limit. (smaller devices like the PIC12F683 which the 08M is based on don't even HAVE more than 2K program memory!).
 

westaust55

Moderator
Thanks BeanieBots!

Yes...ADC and ReadTemp may be next on my agenda...first things first though...serial comms!
Note that READTEMP using a DS18B29 requires a 1-wire interface with open collector and pull-up resistor akin to i2c data/clk lines.
While the hardware side is relatively easy, the software requires quite precise timing to create the handshaking and pulses for 1 and 0.
Good luck with your ventures into assembler programming.
 

bpowell

Senior Member
Thanks Westaust55! I'm working in C, not assembler...but it's all just for fun. I'm really enjoying it, and it's helping me understand a lot about what the PICAXE system is doing "under the hood".
 
Top