PIC24 Tutorial

The PIC24F is a very versatile piece of hardware. I use it at work all the time. Along with the MPLAB IDE and the free C30 compiler, these products from Microchip make for a powerful combination. You can pretty much do anything on the lower end of the frequency spectrum. I would like to share with the web, some of the intricacies of the microcontroller as I have become somewhat familiar with the chip. Most of these resources will apply to the other processors from Microchip 16-bit series. If you have any questions, feel free the comment or email. Come back to this page often as I will be adding features and code for all of the web to see.
1. Introduction
Welcome to 16 bits of… well not power… maybe versatility.
2. Getting Started
What is the PIC24, and how to start programming.
3. First Program
A journey of a thousand miles, starts with a single “step”.
4. Configuration
Different modes of the microcontroller, what do they all mean?
5. Inputs and Outputs
You and your microcontroller: the most basic way to talk.
6. Oscillator and Timing
To a microcontroller, nothing is constant.
7. Interrupts
Because we all have to stop once a in a while.
8. Timers
Getting the most out of time.
9.1. UART – Part 1 – Setup
9.2. UART – Part 2 – Usage
If it’s so universal, how come there’s so many shortcomings?
10.1 I2C – Part 1 – I2C Basics
10.2 I2C – Part 2 – Basic Functions
10.3 I2C – Part 3 – Advanced Functions
Finally, a serial interface everyone can appreciate.
11. ADC
Build a voltmeter out of a PIC.
12. PWM DAC
Who says PWM has to be complicated?

Entries (RSS)
First off, I love your site. It has been much more helpful than any other documentation I have found else where.
I was wondering if you have an experience implementing the PMP feature. I have been unsucessful in my attempts and I am wondering if I am missing something. All I am trying to do is send out a byte of data and watch it in the simulator. I am trying to send out 8 bits of data at a time and I have done the following in my code:
#define PMCON_VALUE 0xB280
#define PMMODE_VALUE 0×0000
#define PMAEN_VALUE 0×0000
#define PMADDR_VALUE 0×0000
#define PMINT_VALUE 0×0000
PMPOpen(PMCON_VALUE, PMMODE_VALUE, PMAEN_VALUE, PMADDR_VALUE, PMINT_VALUE);
PMPMasterWrite(0×55);
I don’t know if there is something more that I need to do, it I have something configure incorrectly, etc. All I know is that I can’t get any of my data lines to change. Any direction that you could give me would be greatly appreciated.
Thanks,
Ryan
Hi Ryan,
The PMP is a digital interface. As such, the io ports must be configured as digital using the AD1PCFG (or equivalent) register. That is all that I can think of that is the most common problem. Also a lot of the functions that come with the C30 compiler have loops in them that wait for certain things to occur. I haven’t taken a look at the PMPMasterWrite(), but I’m pretty sure that there are several loops that wait for the write/read strobe to be at their proper configuration (ie, high/low). If you’re having trouble, and the controller is not sending anything, the execution is most likely stuck in that loop. I would try to make sure that there’s nothing physically in that node that is forcing a high or low signal (i.e. another IC on the same copper trace that is forcing the trace to be pulled high, or grounded). This is especially important for the pins/traces that are used for protocol communications, such as the address and strobe lines because most of the code has loops that wait for a proper condition to occur on these protocol signals.
Pseudo code in the PMPMasterWrite() probably looks like this:
1. output address
2. loop to wait until address pins are properly configured
3. output strobe
4. loop to wait until strobe pins are properly configured
5. send data
6. loop to wait until data is sent
The loops are probably causing you trouble because they are waiting for something to occur. You need to look at the function itself, as well as your circuit and figure out what is wrong.
Best of luck. The harder the problem, the better you’ll feel when you solve it. We’ve all been there.
-J
Hello.
First of all, great site, and explanations.
Now, I see You have PWM section but nothing inside, so I was wondering if You could give me few directions on using PWM with pic24?
This is the first time I’m using PIC24 (c30 compiler) within my student project and I was reading somethin about PWM but not quite understand it.
It’ll be great if You could give some example on how using PWM@PIC24.
(Also, is it possible to measure Duty Cycle of “input” PWM signal?)
Thanks,
Igor
Thanks again for the tutorial, how much till the ADC part is online? I can’t seem to make it work! :<
Hey man, awesome tutorial. has been a great help.
Could you please also do a tutorial on USB for us.
Thanks, you are the man !
Hmm… The USB standard is a little harder to understand, compared to the I2C or the UART. I don’t want to promise anything, but I’ll see if I can make an HID tutorial in the future.
Just wanted to thank you for the these tutorials ! it was a great help =3
keep up the good work
hi man!! thanks for the great tutorial!! i was wondering if you can help me with a tutorial for PWM on the pic 24h. I want to use it for a student project and it’s my first time with the c30 compiler! Tanks
Hello jliu83,
I’ve been reading your tutorial and I like it. Plain simple talk that one can understand. Thumbs up!
I’m working on an altitudemeter using a PIC24HJ12GP201 microcontroller and Bosch BMP085 pressure sensor (I2C).
Years ago I worked succesfully with a PIC16F84 but with these two I just can’t seem to get it to work.
There are some things that I just don’t get. Mostly about the clock. It’s about selecting the right clock values (_FOSCSEL, _FOSC and OSCCON) and with I2C it’s the Baud Rate. I have tried your code snippets but couldn’t get it all together. Now I have used some routines from ‘Pic24 Support Llibraries’ but again… it’s not functioning. I connected all hardware correct and de PicKit2 is reading, writing and debugging with MPLAB works ok.
Is there a possibility that you could take a look at my code and say if I made the right choices?
I’ve prepared a workspace that doesn’t contain any other things than neccesary (buzzers and leds etc..).
I think you can review it in a few minutes.
Got your email. You can remove it before spammers find it..
I’ll mail you tomorrow.