Professional Documents
Culture Documents
// CONFIG1
#pragma config FOSC = ECH // External Clock, 4-20 MHz
#pragma config WDTE = OFF // Watchdog Timer (WDT) disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config CP = OFF // Flash Memory Code Protection off
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out disabled.
#pragma config IESO = ON // Internal/External Switchover on
#pragma config FCMEN = ON // Fail-Safe Clock Monitor enabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protect off
#pragma config PPS1WAY = ON // PPS one-way control enabled
#pragma config ZCDDIS = ON // Zero-cross detect disabled
#pragma config PLLEN = OFF // Phase Lock Loop disable
#pragma config STVREN = ON // Stack Over/Underflow Reset enabled
#pragma config BORV = LO // Brown-out Reset low trip point
#pragma config LPBOR = OFF // Low-Power Brown Out Reset disabled
#pragma config LVP = OFF // Low-Voltage Programming disabled
void main(void) {
// Port B access
ANSELB = 0x0; // set to digital I/O (not analog)
TRISB = 0x0; // set all port bits to be output
LATB = portValue; // write to port latch - RB[0:3] = LED[4:7]
return;
}
Note: If you do not set Configuration bits correctly, your device will not operate at
all or at least not as expected.
Code protection - Turn off code protection until it is required. This ensures that
device memory is fully accessible. From the example code:
#pragma config CP = OFF
Different configuration bits may need to be set up to use another 8-bit device (rather
than the PIC16F1719 MCU used in this example). See your device data sheet for the
number and function of corresponding configuration bits. Use the part number to
search http://www.microchip.com for the appropriate data sheet.
For more about configuration bits that are available for each device, see the following
file in the location where MPLAB XC8 was installed:
MPLAB XC8 Installation Directory/docs/chips
Once you have the settings you want, click Generate Source Code to Output and
then copy the pragma directives from the Output window into your code, as was done
in the example code.
// CONFIG1
#pragma config FOSC = ECH // External Clock, 4-20 MHz
#pragma config WDTE = OFF // Watchdog Timer (WDT) disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config CP = OFF // Flash Memory Code Protection off
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out disabled.
#pragma config IESO = ON // Internal/External Switchover on
#pragma config FCMEN = ON // Fail-Safe Clock Monitor enabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protect off
#pragma config PPS1WAY = ON // PPS one-way control enabled
#pragma config ZCDDIS = ON // Zero-cross detect disabled
#pragma config PLLEN = OFF // Phase Lock Loop disable
#pragma config STVREN = ON // Stack Over/Underflow Reset enabled
#pragma config BORV = LO // Brown-out Reset low trip point
#pragma config LPBOR = OFF // Low-Power Brown Out Reset disabled
#pragma config LVP = OFF // Low-Voltage Programming disabled
void main(void) {
// Port D access
ANSELD = 0x0; // set to digital I/O (not analog)
TRISD = 0x0; // set all port bits to be output
// Port B access
ANSELB = 0x0; // set to digital I/O (not analog)
TRISB = 0x0; // set all port bits to be output
portValue = 0x05;
LATD = portValue; // write to port latch - RD[0:3] = LED[0:3]
LATB = portValue; // write to port latch - RB[0:3] = LED[4:7]
portValue = 0x0A;
LATD = portValue; // write to port latch - RD[0:3] = LED[0:3]]
LATB = portValue; // write to port latch - RB[0:3] = LED[4:7]
_delay(25000); // delay in instruction cycles
}
return;
}
// CONFIG1
#pragma config FOSC = ECH // External Clock, 4-20 MHz
#pragma config WDTE = OFF // Watchdog Timer (WDT) disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
#pragma config CP = OFF // Flash Memory Code Protection off
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config CLKOUTEN = OFF // Clock Out disabled.
#pragma config IESO = ON // Internal/External Switchover on
#pragma config FCMEN = ON // Fail-Safe Clock Monitor enabled
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protect off
#pragma config PPS1WAY = ON // PPS one-way control enabled
#pragma config ZCDDIS = ON // Zero-cross detect disabled
#pragma config PLLEN = OFF // Phase Lock Loop disable
#pragma config STVREN = ON // Stack Over/Underflow Reset enabled
#pragma config BORV = LO // Brown-out Reset low trip point
#pragma config LPBOR = OFF // Low-Power Brown Out Reset disabled
#pragma config LVP = OFF // Low-Voltage Programming disabled
void main(void){
// Port D access
ANSELD = 0x0; // set to digital I/O (not analog)
TRISD = 0x0; // set all port bits to be output
// Port B access
ANSELB = 0x0; // set to digital I/O (not analog)
TRISB = 0x0; // set all port bits to be output
while(1);
return;
}
Note: After you create a main project, you can either add a main.c template file
before using MCC or you can let MCC add main.c for you.
Editing of main.c is always required to add functionality to your program. Review the
generated files to find any functions or macros you may need in your code.
/*
Copyright (c) 2013 - 2015 released Microchip Technology Inc.
All rights reserved.
#include "mcc_generated_files/mcc.h"
/*
Main application
*/
void main(void) {
// initialize the device
SYSTEM_Initialize();
while (1) {
ADC_StartConversion(channel_AN0);
while(!ADC_IsConversionDone());
}
}
/**
End of File
*/
Note: After you create a main project, you can either add a main.c template file
before using MCC or you can let MCC add main.c for you.
Editing of main.c is always required to add functionality to your program. Review the
generated files to find any functions or macros you may need in your code.
/*
Copyright (c) 2013 - 2015 released Microchip Technology Inc.
All rights reserved.
#include "mcc_generated_files/mcc.h"
#define NUM_EE_VALUES 64
/*
Main application
*/
void main(void) {
// initialize the device
SYSTEM_Initialize();
while(1){
// Read from EEPROM and display see Section 5.4
for(i=0; i<NUM_EE_VALUES; i++){
RAMArray[i] = DATAEE_ReadByte(_EEADRL_EEADRL_POSN + i);
LATD = RAMArray[i]; // RD[0:3] = LED[0:3]
LATB = (RAMArray[i] >> 4); // RB[0:3] = LED[4:7]
_delay(25000);
}
};
}
/**
End of File
*/
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchips Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
CERTIFIED BY DNV Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Companys quality system processes and procedures
are for its PIC MCUs and dsPIC DSCs, KEELOQ code hopping
== ISO/TS 16949 == devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchips quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.