Low Pin Count Demo Board User’s Guide
DS51556A-page 18 © 2005 Microchip Technology Inc.
Rotate
The rotate instructions (RRF or RLF) shift all the bits in the file register right or left by
one position, through the Carry bit. The Carry bit is shifted into the byte and receives
the bit shifted out of the byte. The Carry bit should be cleared before rotation so
unwanted bits are not introduced into the display byte. The Carry bit also indicates
when the display byte is empty. When it is, reinsert the1’ at bit 3.
PICmicro MCUs have two rotate instructions: Rotate Left (RLF) and Rotate Right (RRF).
These instructions rotate the contents of a file register and Carry bit one place.
FIGURE 3-2: ROTATE LEFT
EXAMPLE 3-4: ROTATE EXAMPLE
File Register
Carry
Start
BSF STATUS,RP0 ;select Register Page 1
CLRF TRISC ;make I/O PORTC all output
BCF STATUS,RP0 ;back to Register Page 0
MOVLW 0x08
MOVWF Display
MainLoop
MOVF Display,w ;Copy the display to the LEDs
MOVWF PORTC
OndelayLoop ;Delay .197S
DECFSZ Delay1,f
GOTO OndelayLoop
DECFSZ Delay2,f
GOTO OndelayLoop
BCF STATUS,C ;ensure the carry bit is clear
RRF Display,f ;Rotate Display right
BTFSC STATUS,C ;Did the bit rotate into the carry?
BSF Display,3 ;yes, put it into bit 3.
GOTO MainLoop
LPC Demo Board Lessons
© 2005 Microchip Technology Inc. DS51556A-page 19
3.2.4 Lesson 4: Analog-to-Digital
This lesson shows how to configure the ADC, run a conversion, read the analog voltage
controlled by the potentiometer (RP1) on the board, and display the high order 4 bits
on the display.
The PIC16F690 has an on board Analog-to-Digital Converter (ADC) with 10 bits of
resolution on any of 11 channels. The converter can be referenced to the device’s V
DD
or an external voltage reference. The LPC Demo Board references it to V
DD as
provided by the USB cable. The answer from the ADC is represented by a ratio of the
voltage to the reference.
ADC = V/V
REF * 1023
Converting the answer from the ADC back to voltage requires solving for V.
V = ADC/1023 * V
REF
Two of the three factors on the right side of the equation are constants and may be
calculated in advance. This eliminates the need to actually divide, but still requires fixed
or floating point multiply to solve the equation on the fly.
However, sometimes, such as when reading a sensor, calculating the voltage is only
the first step. There may be additional math to calculate the meaningful data from the
sensor. For example, when reading a thermistor, calculating the voltage is only the first
step on the way to getting the temperature.
There are other means to convert ADC values, including a straight table look-up or a
piece-wise linear interpolation. Each of these represents different speed/memory
trade-offs.
The schematic (Appendix A. “Hardware Schematics”) shows the wiper on the
potentiometer is connected to pin RA0 on the PIC16F690.
Here’s the checklist for this lesson:
Configure PORTA as an analog input, TRISA<0> = 1, ANSEL<0> = 1
Select clock scaling in ADCON1.
Select channel, justification and V
REF source in ADCON0.
Low Pin Count Demo Board User’s Guide
DS51556A-page 20 © 2005 Microchip Technology Inc.
3.2.4.1 ADCON1
ADCON1 selects the ratio between processor clock speed and conversion speed. This
is important because the ADC needs at least 1.6 μs per bit. Accuracy degrades if the
clock speed is too high. As the processor clock speed increases, an increasingly large
divider is necessary to keep the conversion speed. Four MHz is fastest at 8:1 ratio with
a conversion speed of 2 μs per bit. Refer to the “T
AD vs. Device Operating
Frequencies” Table in the Analog-to-Digital Section of the PIC16F685/687/689/690
Data Sheet (DS41262) for recommended configurations.
REGISTER 3-1: ADCON1 – A/D CONTROL REGISTER 1 (ADDRESS: 9Fh)
U-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0
ADCS2 ADCS1 ADCS0
bit 7 bit 0
bit 7 Unimplemented: Read as ‘0
bit 6-4 ADCS<2:0>: A/D Conversion Clock Select bits
000 =F
OSC/2
001 =F
OSC/8
010 =F
OSC/32
x11 =F
RC (clock derived from a dedicated internal oscillator = 500 kHz max)
100 =F
OSC/4
101 =F
OSC/16
110 =F
OSC/64
bit 3-0 Unimplemented: Read as0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown

DM164120-1

Mfr. #:
Manufacturer:
Microchip Technology
Description:
Development Boards & Kits - PIC / DSPIC PICkit 2 Low Pin Cnt Demo Board
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet