Lessons
2012 Microchip Technology Inc. DS41628B-page 41
3.2 LESSON 1: HELLO WORLD (TURN ON AN LED)
3.2.1 Introduction
The first lesson shows how to turn on an LED.
3.2.2 Hardware Effects
DS1 will light up and stay lit indefinitely.
3.2.3 Summary
The LEDs are connected to input-outpins (I/O) RC0 through RC3. First, the I/O pin
must be configured for an output. In this case, when one of these pins is driven high
(RC0 = 1), the LED will turn on. These two logic levels are derived from the power pins
of the PIC MCU. Since the PIC device’s power pin (V
DD) is connected to 5V and the
source (V
SS) to ground (0V), a ‘1’ is equivalent to 5V, and a ‘0’ is 0V.
3.2.4 New Registers
3.2.4.1 BOTH
3.2.4.2 LATC
The data latch (LATx registers) is useful for read-modify-write operations on the value
that the I/O pins are driving. A write operation to the LATx register has the same effect
as a write to the corresponding PORTx register. A read of the LATC register reads of
the values held in the I/O port latches.
3.2.4.3 PORTC
A read of the PORTC register reads the actual I/O pin value. Writes should be per-
formed on the LAT register instead of on the port directly.
3.2.4.4 TRISC
This register specifies the data direction of each pin connected to PORTC.
An easy way to remember this is that the number ‘1’ looks like the letter ‘I’ for input, and
the number ‘0’ looks like the letter ‘0’ for output.
The reader should always write to the latch and read from the port.
TABLE 3-1: NEW REGISTERS FOR BOTH DEVICES
Register Purpose
LATC Data Latch
PORTC Holds the status of all pins on PORTC
TRISC Determines if pin is input (1) or output (0)
TABLE 3-2: TRIS DIRECTION
TRIS value Direction
1 input
0 output