Usually the commonly used reset types are the POR and external reset using the MCLR pin. These following operations can reset the microcontroller: There are times when a reset is required, this can be done automatically (when a microcontroller is in an endless loop to avoid freezing, very low voltage to avoid unexpected operation…) or even manually when a user wants to force to microcontroller to restart its program. When a microcontroller is reset, it starts the execution of the program from the beginning of the program (address 0x0000). The table below gives the recommended values. Higher capacitance increases the oscillator stability but also increases the start-up time. Please always check the PIC datasheet to get the accurate values of C1 and C2 of the oscillator. This figure shows how a crystal can be used as a clock input. RC oscillator mode is for using an external RC resonator (usually 8 MHz and below) and INT specifies the processors internal oscillator if equipped. EC is for use with an external TTL/CMOS clock source. The XT and HS settings are for use with external crystal oscillators, XT is used for crystals 4 MHz and below, HS for 4 MHz and above.
Usually it’s cheap to use the PIC internal oscillator especially with newer PIC models but for higher frequencies that your internal oscillator is not able to provide or for applications requiring accurate timing like USB, CAN, High speed asyncronous serial you want to use an external oscillator.ĭon’t set your frequency higher than required, the higher the frequency the higher the power consumption and this can be a huge problem especially for battery powered applications.Ĭommon oscillator settings are XT, HS, EC, RC and INT. Your application will determine whether to use an internal or external oscillator and which frequency to use. The oscillator settings depend on frequency of the clock, the type of the clock source (crystal, RC…) and whether an internal or external clock is to be used. The important settings are the Clock sources (oscillator), low voltage and the reset (MCLR, watchdog timer…).Īlways switch ON what you need and switch off the rest. Setting the configuration bits is very important if they are not correctly set, the processor will operate in an unknown manner or often not start at all.Ĭlick on Window menu, PIC Memory Views then Configuration Bits to open the configuration bits window.
Click Next.Įnter the name of the project and select the location where to save it by clicking on the browse button.
Go to Microchip website to install a free compiler which is fully functional but without code optimization. If you don’t see it, it means you have not installed it. Ckick Next.Īll Microchip compilers installed on your computer will be shown here. Then click Next.Ĭhoose the hardware tool to program and debug your project. In our case because we want to use PIC18F2220, we will select the Advanced 8-bit (PIC18) Select Standalone Project and click Next.Ĭhoose the PIC Family. Go to File menu and click on New Project to start a new project. We are going to use PIC18F2220 but it should be the same for the rest of microcontrollers.ĭepending on your operating system used, open MPLAB X IDE either form a shortcut on the desktop or from all programs. Let us create a simple project called “Flashing_LED” to switch on and off an LED connected to PORTB.0 with 1 sec interval.Īssuming you have installed the latest version of MPLABX and XC8 compiler, you can start a new project by following these few steps below illustrated with screenshots.
You can also download the Microchip XC 8 Compiler User’s Guide.įor PIC32 microcontrollers XC32 is used and for PIC24 and dsPIC XC16 is used.
You can download a free copy of MPLAB ® X IDE and XC8 Compiler from Microchip website. This compiler offers different optimization levels to suit your needs with FREE downloads available. XC8 is the new C compiler for PIC10, PIC12, PIC14, PIC16 and PIC18 microcontrollers.
MPLAB ® X IDE is the new Microchip IDE and it runs on a PC with Windows ®, Mac OS ® or Linux ® to develop applications for PIC microcontrollers and replaces all MPLAB® C and HI-TECH compilers.
The aim of this course is to teach you how to develop microcontroller based electronic systems using Microchip XC8 (MPLAB X) Compiler.