Navigation

Saturday, 3 September 2016

Using MPLAB software for programming a PIC microcontroller – Part 1

I would be using the MPLAB 8.89 and CCS C Compiler
Step 1: Go to Project -> Project Wizard
Step 2: Choose the PIC18F1320 microcontroller


Step 3: Choose the compiler


In case the compiler is not listed, check the “Show all installed toolsuites” box or click on the Browse button to navigate to the location you installed the compiler.

Step 4: Create a new folder in your preferred location, then navigate to the folder location by clicking on browse in the figure below. Then type the name of the project in the file name text box.



Step 5: Add existing files to your project if needed

Step 6: Click Finish. The following screen will appear


Step 7: Right click on header files and choose Add Files
Navigate to the PICC folder where the CSS C Compiler was installed, Go to the Devices folder and select 18F1320


Step 8: To type in your code, click on New File. Type in your code and save the file with a .c extension in the project folder you created previously. The following c code I used blinks an LED light every 500ms

#include <18F1320.h>
#device ICD=TRUE
#fuses NOWDT, INTRC, MCLR, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NOIESO, NOFCMEN
#use delay(clock=8000000)

void main (void) {

 setup_oscillator(OSC_8MHZ);
 setup_adc_ports( sAN0 );
 SETUP_ADC(ADC_CLOCK_INTERNAL );

 while(1) {
  output_high(PIN_B2);
  delay_ms(500);
  output_low(PIN_B2);
  delay_ms(500);
 }

}

Step 9: Now add the new .c file to the project by right clicking on Source Files and choosing Add files. Choose the newly created file

Step 10: Click on the Build All button
Output Window should show BUILD SUCCEEDED on the last line


Once finished with the program. Close the project by navigating to Project -> Close and choose the project to close.


No comments:

Post a Comment