SQUARE 1 ELECTRONICS
MARCH 27, 2007
PIC16C711 to PIC16F870
The PIC16C711 has been phased out by Microchip and is no longer available. As a result, some of
the experiments in Microcontrol'n Apps must be changed. We have chosen the F870 as the replacement
because it is already described in the book and because it has the necesssary assortment of digital
I/O pins with one analog input for A/D for the simple data logger experiment. The text and code changes
follow.
F870 ON-BOARD 10-BIT A/D - Using Only The Most Significant 8 bits
This information logically follows page 206 in Microcontrol'n Apps, v2.0.
A description of the PIC16F870 is contained in the chapter entitled PIC16F870.
The 10-bit A/D converter in the PIC16F870 may be used as an 8-bit converter by left justifying
the result and ignoring the least significant two bits.
As an example, we will modify the hardware and code used in the previous example by deleting the
two LEDs on port B and by changing the code to eliminate the use of the ADRESL register and the
two port B lines.
This code will be used later in the simple digital voltmeter and simple data logger experiments.
The schematic is the same as the one on page 203 except that the two LEDs connected to RB0 and RB1
are deleted. RB0 and RB1 should be pulled up.
The flow chart is the same as the one on page 204 except that port B LEDs are not used.
The code is the same as ICD3PG on page 205 except:
Delete:
portb equ 0x06
adres1 equ 0x9e
temp equ 0x23
bcf portb,0 on 11th line after "start" label
Delete the following block of code which deals with the least significant 2 bits:
bsf status,rp0 ;switch to bank 1
movf adresl,w ;get A/D result ls 2 bits
bcf status,rp0 ;switch to bank 0
movwf temp ;store for dissection
btfss temp,7
goto clr_1
bsf portb,1 ;display via LED
do_0 btfss temp,6
goto clr_0
bsf portb,0 ;display via LED
wait call debounce ;wait a while (200 milliseconds)
goto meas ;look at voltage again
;------------------------------------------------------------
clr_1 bcf portb,1 ;display via LED
goto do_0
clr_0 bcf portb,0 ;display via LED
goto wait
;------------------------------------------------------------
Replace the block above with:
wait call debounce ;wait a while (200 milliseconds)
goto meas ;look at voltage again
Turn the pot and observe the port C leds.
SIMPLE DIGITAL VOLTMETER EXPERIMENT
Refer to page 266.
The schematic follows:
For printable version of the Digital Voltmeter Schematic
CLICK HERE
The code is mostly the same as DVM.ASM for the C711 starting on page 268.
The things that change are:
The processor p=16f870
The configuration word h'3f71'
adcon0 is at 0x1f
adres is repaced by adresh at 0x1e
adcon1 is at 0x9f
The following file register equates are changed to:
count equ 0x30
ncount equ 0x31
mcount equ 0x32
;
number equ 0x33
multby equ 0x34
data_lo equ 0x35
data_hi equ 0x36
;
index equ 0x37
dig_ctr equ 0x38
lsb1 equ 0x39
msb1 equ 0x3a
lsb2 equ 0x3b
msb2 equ 0x3c
flags equ 0x3d
;
sendreg equ 0x3e
instr equ 0x3f
char equ 0x40
addr equ 0x41
hold equ 0x42
The line after the "start" label is:
movlw b'00000001' ;port A inputs/outputs
Six lines later, 3 lines of code are deleted:
bcf porta,2 ;initialize
bcf porta,3
bcf porta,4
Move the A/D setup code from the following page just before the "meas" label to where the three lines
of code were deleted above. Revise these lines as shown:
bsf status,rp0 ;bank 1
movlw b'00001110' ;port A, bit 0 analog input
movwf adcon1 ; bits 5,3,2,1 digital I/O, result left justified
bcf status,rp) ;bank 0
The second line after the label "test" is changed - the register becomes "adresh".
Note the A/D conversion code is borrowed from icd4.asm above.
Change the configuration selections to:
;------------------------------------------------------------
;at device programming time, select:
; memory unprotected
; watchdog timer disabled (default is enabled)
; standard crystal (using 4 MHz osc for test) XT
; power-up timer on
; brown-out reset enabled
; lvp disabled
; debug mode disabled
;============================================================
That should do it.
SIMPLE DATA LOGGER EXPERIMENT
Refer to page 316.
The schematic follows:
For printable version of Data Logger Schematic
CLICK HERE
The flow charts are unchanged.
As compared to the C711, the port A pin assignments are changed to match the way that the F870
port works in terms of the available digital I/O vs. analog input combinations.
The following table shows the differences:
ADCON1
C711 F870
--------------------- ---------------------------
RA3 RA2 RA1 RA0 RA5 RA3 RA2 RA1 RA0
--------------------- ---------------------------
A A A A A A A A A
Vref A A A D A D A A
D D A A D D D D D
D D D D D D D D A
The Port pin assignments are:
Function C711 F870 Change
-------------------------------------
A/D input RA0 RA0
Not used RA1 RA1
Display/Upload RA2 RA2
TD RS-232 RA3 RB5 Yes
Not used RA4
TD PIC/LCD RB4 RB4
LED RB5 RA5 Yes
Start RB6 RA4 Yes
Mode RB7 RA3 Yes
The code is mostly the same as LOG.ASM for the C711 starting on page 324.
The things that change are:
The processor p=16f870
The configuration word h'3f71'
adcon0 is at 0x1f
adres is repaced by adresh at 0x1e
adresl is at 0x9e
adcon1 is at 0x9f
The following file register equates are changed to:
count equ 0x30
ncount equ 0x31
mcount equ 0x32
;
number equ 0x33
multby equ 0x34
data_lo equ 0x35
data_hi equ 0x36
;
index equ 0x37
dig_ctr equ 0x38
lsb1 equ 0x39
msb1 equ 0x3a
lsb2 equ 0x3b
msb2 equ 0x3c
flags equ 0x3d
;
sendreg equ 0x3e
instr equ 0x3f
char equ 0x40
addr equ 0x41
hold equ 0x42
count60 equ 0x43
The code from the "start" label to the "mode" label is:
;------------------------------------------------------------
start bsf status,rp0 ;switch to bank 1
movlw b'00001110' ;port A, bit 0 analog input
movwf adcon1 ; bits 5,3,2,1 digital I/O
movlw b'00011101' ;port A inputs/outputs
movwf trisa
movlw b'00000001' ;port B inputs/outputs
movwf trisb
bcf status,rp0 ;switch back to bank 0
bsf portb,4 ;output mark, bit 4 (serial - LCD)
bsf portb,5 ;output mark, bit 5 (serial - PC)
bcf porta,1 ;initialize, not used
bcf porta,5 ;LED off
bcf portb,1 ;initialize
bcf portb,2 ;initialize
bcf portb,3 ;initialize
;------------------------------------------------------------
The second line after the label "test" is changed - the register becomes "adresh".
Note the A/D conversion code is borrowed from icd4.asm above.
The port pin assignments designated "yes" in the "Change" column in the table above must be changed
in the code.
Change the configuration selections to:
;------------------------------------------------------------
;at device programming time, select:
; memory unprotected
; watchdog timer disabled (default is enabled)
; standard crystal (using 4 MHz osc for test) XT
; power-up timer on
; brown-out reset enabled
; lvp disabled
; debug mode disabled
;============================================================
That should do it.
©Square 1 Electronics 1996-2007
|Home |