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 #67 background imageLoading...
Page #67 background image
Lessons
2012 Microchip Technology Inc. DS41628B-page 67
EXAMPLE 3-31:
3.8.7 C Language
3.8.7.1 BOTH
This version utilizes global variables. Unlike local variables, global variables have no
function scope, meaning that they are visible to every function within the same source
file where it is declared. It is good practice to uniquely identify global variables such as
preceding each variable with an underscore.
This byte is modified in the check_switch function, and the result is returned to the
main loop.
EXAMPLE 3-32:
Notice how the bytes, delay and direction, were declared inside of main. These cannot
be modified anywhere outside of main. Also, notice how check_switch returns an
unsigned char byte to the main loop. In ‘C’, only one variable can be returned.
RotateLeft:
bcf STATUS, C ;clear the carry
rrcf LATC,f ;rotate the LEDs (through carry) and turn on the next LED to the right
btfss STATUS,C ;did the bit rotate into the carry (i.e. was DS1 just lit?)
bra MainLoop
bsf LATC, 3 ;yes, it did and now start the sequence over again by turning on DS4
bcf STATUS, C ;clear the carry
bra MainLoop ;repeat this program forever
unsigned char _previous_state = SWITCH_UP; //global variable
void main(void) {
unsigned char delay;
unsigned char direction;
.....
}
unsigned char check_switch(void){
...
..
}

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