This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pic32mx270f256b [2019/05/29 07:53] sausage |
pic32mx270f256b [2021/12/14 12:07] sausage Updated missing details. New code. |
||
---|---|---|---|
Line 10: | Line 10: | ||
{{ :pic32mx270f256b-pins.png?nolink |}} | {{ :pic32mx270f256b-pins.png?nolink |}} | ||
- | {{ :pic32mx270f256b-breadboard-components.jpg?nolink |}} | + | |
Here is the overall layout on the breadboard: | Here is the overall layout on the breadboard: | ||
Line 31: | Line 31: | ||
On both the Power and Ground rails on the breadboard, add a 0.1uf capacitor each. | On both the Power and Ground rails on the breadboard, add a 0.1uf capacitor each. | ||
- | Also between Pin 20 (CAP) and Pin 9 (VSS) add a 0.01uf capacitor. | + | Also between Pin 20 (CAP) and Pin 19 (VSS) add a 0.01uf capacitor. |
Add a 10k pull up resistor from Pin 1 (MCLR) to Power. MCLR is Master Clear or Reset. | Add a 10k pull up resistor from Pin 1 (MCLR) to Power. MCLR is Master Clear or Reset. | ||
Line 63: | Line 63: | ||
A simple first test is to light an LED from ''RA1'' which is pin 3 on the microcontroller. | A simple first test is to light an LED from ''RA1'' which is pin 3 on the microcontroller. | ||
- | In the MPLABX IDE, create a new C project and in the main.c file, add the following before the while loop: | + | In the MPLABX IDE, create a new C project by doing the following: |
- | <code C> | + | <code ini> |
- | TRISA = 0b00000000; //all PortA pins are output | + | New Project > Microchip Embedded > Standalone Project |
- | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | + | |
+ | Next > | ||
- | while(1) | + | Family: 32-bit MCUs (PIC32) |
- | { | + | Device: PIC32MX270F256B |
+ | |||
+ | Select Tool: PICkit3 | ||
+ | |||
+ | Next > | ||
+ | |||
+ | Select Compiler: XC32 Compiler | ||
+ | |||
+ | Project Name: MyTestProject (or anything really) | ||
+ | (keep all defaults) | ||
+ | |||
+ | Finish | ||
+ | |||
+ | Under ''Source Files'': | ||
+ | New > C Main File | ||
+ | Finish | ||
+ | </code> | ||
+ | |||
+ | Click the Build Spanner icon to test the project build. Should build successfully. | ||
+ | |||
+ | Change the whole c file to contain: | ||
+ | |||
+ | <code c> | ||
+ | #ifdef __XC32 | ||
+ | #include <xc.h> | ||
+ | #endif | ||
+ | |||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main(int argc, char** argv) { | ||
+ | |||
+ | TRISA = 0b00000000; //all PortA pins are output | ||
+ | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | ||
+ | |||
+ | return (EXIT_SUCCESS); | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | The ''#include <xc.h>'' line includes defined variables like ''PORTA'' and ''TRISA''. | ||
A nice simple test. ''TRISA'' means all the A pins (RA0, RA1, RA2 etc). Setting each bit to 0 in this way means that every pin will be set as an output pin. This means that voltage can be output from the pin to power something. | A nice simple test. ''TRISA'' means all the A pins (RA0, RA1, RA2 etc). Setting each bit to 0 in this way means that every pin will be set as an output pin. This means that voltage can be output from the pin to power something. | ||
Line 82: | Line 120: | ||
Compile the code. A hex file will be created at: | Compile the code. A hex file will be created at: | ||
- | project\dist\PIC32MX270F256B-cpp\production\myfile.hex | + | project\dist\<my project name>\production\myfile.hex |
Switch back to the MPLABX IPE and browse for your hex file. Program it to the chip by clicking the ''Program'' button. | Switch back to the MPLABX IPE and browse for your hex file. Program it to the chip by clicking the ''Program'' button. | ||
Line 94: | Line 132: | ||
<code c> | <code c> | ||
+ | #ifdef __XC32 | ||
+ | #include <xc.h> | ||
+ | #endif | ||
+ | |||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | #include <plib.h> | ||
+ | |||
+ | int main(int argc, char** argv) { | ||
+ | |||
TRISA = 0b00000000; //all PortA pins are output | TRISA = 0b00000000; //all PortA pins are output | ||
- | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | + | PORTA = 0b00000001; //set pin 3 (RA1) to on. (supply 3.3 volts) |
| | ||
int count = 0; | int count = 0; | ||
- | | + | |
while(1) | while(1) | ||
{ | { | ||
Line 106: | Line 154: | ||
count = 0; | count = 0; | ||
} | } | ||
- | | + | |
count++; | count++; | ||
} | } | ||
+ | | ||
+ | return (EXIT_SUCCESS); | ||
+ | } | ||
</code> | </code> | ||
+ | |||
+ | Notice ''plib.h'' is included. This supports defines like ''mPORTAToggleBits''. All this changes in later versions. This document will be updated at some point. | ||
+ | |||
+ | And that gives a basic project that will alternate between flashing LEDs. | ||
===== What happens if? ===== | ===== What happens if? ===== | ||
Line 117: | Line 172: | ||
^ Component ^ During Programming ^ For Execution ^ | ^ Component ^ During Programming ^ For Execution ^ | ||
| Not using a pull up on MCLR to Positive | No effects | Could cause random resets on the PIC if the pin is floating. | | | Not using a pull up on MCLR to Positive | No effects | Could cause random resets on the PIC if the pin is floating. | | ||
+ | | Pull up on MCLR to Negative | Cannot program | - | | ||
| No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| | | No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| | ||
| No External Oscillator | Not required | Internal can be used | | | No External Oscillator | Not required | Internal can be used | |