Microchip Technology PICkit 3 Debug Express Debugger/Programmer (DV164131) PICkit 3 Debug Express DV164131 数据表
产品代码
DV164131
PICkit™ 3 Debug Express Lessons
© 2009 Microchip Technology Inc.
DS41370C-page 23
The Configuration bit settings that are important for this lesson project and are different
from the default values are:
from the default values are:
Even though all other bit settings are left as default, it is strongly recommended to
define them all in the source as is done in the Lesson 2 source code. This ensures that
the program memory image in the .hex file built by the compiler contains all the
configuration settings intended for the target application. The one exception is the
DEBUG bit, as this is defined by the MPLAB IDE environment depending on whether
the target microcontroller is running in Debug mode or not.
define them all in the source as is done in the Lesson 2 source code. This ensures that
the program memory image in the .hex file built by the compiler contains all the
configuration settings intended for the target application. The one exception is the
DEBUG bit, as this is defined by the MPLAB IDE environment depending on whether
the target microcontroller is running in Debug mode or not.
3.2.3
Exploring the Lesson 2 Source Code
Open the Lesson 2 source code file 02 Blink LED.c in an MPLAB IDE editor window
if it is not open already.
if it is not open already.
FIGURE 3-15:
LESSON 2 “BLINK LED” SOURCE CODE
This source code contains a couple of new lines of interest. The first is a new include
file:
file:
#include "delays.h"
This is the header file for the MCC18 “delays” library, which provides functions used to
create program delays of a certain number of processor cycles. The MPLAB C compiler
comes with a number of useful libraries. These include the standard C libraries stdio
and stdlib, and function libraries such as ctype, delays, math, and string.
There are also libraries for using hardware peripheral functions such as adc, i2c, pwm,
spi
create program delays of a certain number of processor cycles. The MPLAB C compiler
comes with a number of useful libraries. These include the standard C libraries stdio
and stdlib, and function libraries such as ctype, delays, math, and string.
There are also libraries for using hardware peripheral functions such as adc, i2c, pwm,
spi
, usart, and timers as well as for software emulation of peripherals like sw_i2c,
sw_uart
, and sw_spi.
FOSC = INTIO67
This sets the PIC18F45K20 to run using the internal oscillator, so
no crystal or external oscillator is needed. The default frequency is
1 MHz. The oscillator is covered in more detail in Lesson 9. It also
sets OSC1 and OSC2 pins to be used as the RA6 and RA7 I/O
port pins as the OSC pin functions are not needed.
no crystal or external oscillator is needed. The default frequency is
1 MHz. The oscillator is covered in more detail in Lesson 9. It also
sets OSC1 and OSC2 pins to be used as the RA6 and RA7 I/O
port pins as the OSC pin functions are not needed.
WDTEN = OFF
This turns off the Watchdog Timer, as it is not used in this lesson.
When the Watchdog Timer is enabled, it must be cleared periodi-
cally in the code or it will reset the microcontroller.
When the Watchdog Timer is enabled, it must be cleared periodi-
cally in the code or it will reset the microcontroller.
LVP = OFF
This turns off Low-Voltage-Programming, and frees the PGM pin to
be used as the RB5 I/O port pin. (LVP mode is not used by the
PICkit 3 programmer.)
be used as the RB5 I/O port pin. (LVP mode is not used by the
PICkit 3 programmer.)
/** I N C L U D E S **************************************************/
#include "p18f45k20.h"
#include "delays.h"
/** D E C L A R A T I O N S *******************************************/
void main (void)
{
TRISD = 0b01111111;// PORTD bit 7 to output (0) ; bits 6:0 are inputs (1)
while (1)
{
LATDbits.LATD7 = ~LATDbits.LATD7; // toggle LATD
Delay1KTCYx(50);// Delay 50 x 1000 = 50,000 cycles; 200ms @ 1MHz
}
}