












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to using mplab for programming pic16 and pic18 devices, specifically the picdem 2 plus demo board with the mplab icd 2 debugger/programmer. It covers setting up a project in mplab, accessing special function registers (sfrs) and configuration bits using syntax and #pragma commands.
Typology: Study Guides, Projects, Research
1 / 20
This page cannot be seen from the preview
Don't miss anything!
So I thought I’d borrow some graphics from the Microchip folks. For the introduction material we’ll be using the PICDEM 2 Plus demo board with the MPLAB ICD 2 debugger/programmer.
MPLAB ®^ -ICD 2 and PICDEM™ 2 Plus
● All labs will use the ICD 2 and PICDEM 2 Plus
쟙 ICD2 In-circuit programmer and debugger
쟙 PICDEM 2 Plus demo board for most PIC16/18 devices
USB
ICSP over RJ
We’ll use both the PIC16 and PIC18 family of devices. We’ll start with the PIC18 family using the C18 compiler. It’s a good way to program in C and it’s free for students.
Another type of common hardware settings are the configuration bits. We’ll be using this crazy #pragma thing a lot. Basically when Microchip needed a command that isn’t a real C command they say #pragma then do something important for microcontrollers that isn’t part of the default C language. There are a few special times whne we’ll need #pragma. There are just a few things you need to do that C can’t do without a few #pragma ‘s. We’ll talk more about these later, but I thought I’d inclue this little blurb here. :
To learn more about what configuration bits are available you can see a lot of useful things in the help section in MPLAB. Click on Help -> Topics -> Pic18 Config Settings:
To find the settings for your PIC go to the pic18F4520 by expanding the options and finding that number.
You can see the file I selected to the left and you can see the Oscillator Selection bits. We’ll use EC some on the PICDEM 2 board but mainly we’ll use the INTIO67. That setting uses the INTer- nal clock. The internal clock controls how fast the PIC goes through code. The internal clock can go as fast as 8 MHz and as slow as 32kHz. The default is 1MHz.
Let’s talk about the nuts and bolts of setting up a project in MPLAB:
for the program before I even start MPLAB. A workspace typically consist of a minimum of like 10 files.
Most of these files are used within the program and you won’t even open them but they are part of the workspace. I could explain some of them but I don’t really know the details for all of them. To be honest you don’t need to know what they are. They happen behing the scenes. You will notice the .mcw Workspace file, which you’ll open and the .mcp Project file that gets openned automatically within the Workspace.
Most of the work you do will be on the .c files.
Later after you have made a workspace and you want to open it back up, you’ll launch MPLAB and Open Workspace... When you open the workspace everything comes with it. No need to open individual files yadayadayada. Just one thing to open.
Project Wizard. So I usually create my folder in advance then come into MPLAB. The first step within MPLAB is to start with the Project Wizard...
Files Files are the basic components of any program. You’ll have a main source file (.c) that has you main function and primary code. For simple programs you’ll only have 1 source file. For more complex programs you’ll have a .c for you main function then various additional header files and source files for support functions. This is a method for modular programming that we’ll get into later. The files are what you get when you just say New... or Open..(kinda makes since that if you go to File->New you’ll get a new file).
So a file without a project doesn’t really do you any good. Just saying File->New then typing in some code is fun but a file without a project really isn’t all that useful. You’ll spend 99% of your time within a file (usually a .c file), but just know that you’ll need to create more than a file to do anything useful.
Successful Connection
So that’s the basic format for starting a new projects. You’ll do it a lot so get used to it. The first time is the worse time. You only need to add the vairous locations of the toolsuites once.