User Tools

Site Tools


pic32mx270f256b

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
pic32mx270f256b [2021/12/12 08:28]
sausage [What happens if?]
pic32mx270f256b [2021/12/14 12:07] (current)
sausage Updated missing details. New code.
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? =====
pic32mx270f256b.txt · Last modified: 2021/12/14 12:07 by sausage