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 #47 background imageLoading...
Page #47 background image
Lessons
2012 Microchip Technology Inc. DS41628B-page 47
3.3 LESSON 2: BLINK
3.3.1 Introduction
This lesson blinks the same LED used in the previous lesson (DS1). This may seem
trivial, but it requires a deep understanding on how the PIC MCU executes each
instruction if using the assembly version.
3.3.2 Hardware Effects
DS1 blinks at a rate of approximately 1.5 seconds.
3.3.3 Summary
One way to create a delay is to spend time decrementing a value. In assembly, the tim-
ing can be accurately programmed since the user will have direct control on how the
code is executed. In ‘C’, the compiler takes the ‘C’ and compiles it into assembly before
creating the file to program to the actual PIC MCU (HEX file). Because of this, it is hard
to predict exactly how many instructions it takes for a line of ‘C’ to execute.
MPLAB
X and MPLAB
8.xx both have options on viewing the disassembly in a ‘C’ proj-
ect. After a successful build of the program, the instructions that the compiler created
can be viewed.
3.3.4 New Registers
3.3.4.1 BOTH
3.3.4.1.1 OSCCON
This register should always be written to in every program. It is important to set the pro-
cessor speed so that the delay loops are accurate. If it is not written to, like in the first
lesson, then the frequency will default to 500 kHz if using the PIC16F1829, and 1 MHz
if using the PIC18F14K22. This varies between devices.
3.3.5 New Instructions
3.3.5.1 BOTH DEVICES
3.3.5.1.1 movlw
An 8-bit literal, or rather constant, is loaded into the Working Register (W)
TABLE 3-4: NEW REGISTERS FOR BOTH DEVICES
Register Purpose
OSCCON Sets the Processor speed
TABLE 3-5: NEW INSTRUCTIONS FOR BOTH DEVICES
Instruction English Purpose
movlw Move literal into WREG Move bytes around
movwf Move literal from WREG into register Move bytes around
decfsz Decrement the register – skip next line if zero Useful for delay loops
bra label Relative to the label Makes code modular
goto label Unconditional Make code modular
movlw 0x5A
After instruction: W = 0x5A

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