EasyManuals Logo

Microchip Technology PICkit 3 User Manual

Microchip Technology PICkit 3
102 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #45 background imageLoading...
Page #45 background image
Lessons
2012 Microchip Technology Inc. DS41628B-page 45
3.2.7 C Language
The reader should notice that the PIC16 and PIC18 source code for the ‘C’ language
is very similar.
3.2.7.1 ENHANCED MID-RANGE
EXAMPLE 3-6:
This starts a comment. Any of the following text on this line is ignored by the compiler.
Be sure to place lots of these in your code for readability.
The htc.h file will automatically load the correct header file for the selected processor,
which is selected when first creating a project.
This programs the Configuration Words. See the data sheet for more specific informa-
tion on these.
Every ‘C’ program needs, and starts in, the main function.
The LATCbits is a structure defined in the included file (htc.h). The program only
needs to select DS1, which is located at pin RC0. This could also have been done:
LATC |= 0b00000001. This performs an “or-equals” operation which will preserve all
of the pins except C0. If the “or” operation was omitted: LATC = 0b00000001, then
all of the bits except C0 will be cleared.
This while statement will always evaluate to be true, and the continue statement
merely stays in the current loop. It will sit here forever. The continue statement is not
required for correct operation.
Notice how few lines were needed to replicate the same behavior as the assembly
version.
#include <htc.h> //PIC hardware mapping
//config bits that are part-specific for the PIC16F1829
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF &
BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
__CONFIG(WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF);
//Every program needs a `main` function
void main(void) {
TRISCbits.TRISC0 = 0; //using pin as output
LATC = 0; //init to zero
LATCbits.LATC0 = 1; //turn on the LED by writing to the latch
while(1) continue; //sit here forever doing nothing
}
//
#include <htc.h>
__CONFIG
void main(void)
LATCbits.LATC0 = 1
while (1) continue;

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Microchip Technology PICkit 3 and is the answer not in the manual?

Microchip Technology PICkit 3 Specifications

General IconGeneral
BrandMicrochip Technology
ModelPICkit 3
CategoryComputer Accessories
LanguageEnglish

Related product manuals