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 #64 background imageLoading...
Page #64 background image
PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 64 2012 Microchip Technology Inc.
3.7.3 Summary
This lesson uses a simple software delay routine to avoid the initial noise on the switch
pin. The code will delay for only 5 ms, but should overcome most of the noise. The
required delay amount differs with the switch being used. Some switches are worse
than others.
This lesson also introduces the #define preprocessing symbol in both ‘C’ and assem-
bly. Hard coding pin locations is bad practice. Values that may be changed in the future
should always be defined once in preprocessing. Imagine if another user wanted to use
these lessons in a different PIC device and all of the pins changed! This would require
going into the code and finding every instance of any pin reference.
EXAMPLE 3-28:
Now all that is needed is to change this one line and it will be reflected everywhere it is
used.
The preprocessor will substitute LATC, 0 every time the LED identifier is seen. This is
done before the code is assembled/compiled, or rather processed, hence the name
preprocessor.
3.7.4 New Registers
Nothing new.
3.7.5 New Instructions
Nothing new.
3.7.6 Assembly
3.7.6.1 ENHANCED MID-RANGE
EXAMPLE 3-29:
There is only one important main difference in this lesson from previous ones. Notice
how the port is being read, and not the latch, when the program is checking the switch.
If LATC is substituted in where PORTC is, the switch will never be detected. Remember
to read from the port and write to the latch. Read-modify-write operations on the LATC
register will read and write the latched output value for PORTC.
3.7.7 PIC18
Nothing new.
3.7.8 C Language
Nothing new.
#define SWITCH PORTA, 3 ;pin where SW1 is connected..NOTE: always READ from
the PORT and WRITE to the LATCH
#define LED LATC, 0 ;DS1
bsf LATC, 0 ;turn on the LED
bsf LED ;turn on the LED
MainLoop:
banksel PORTA ;get into Bank0
btfsc SWITCH ;defined above....notice how the PORT is being read and not the LATCH
bra LedOff ;switch is not pressed - turn OFF the LED
bra Debounce ;switch is held down, pin needs to be debounced

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