PIC Tutorial Changes
Changes for the PIC16F876 board
The
PIC16F876 is very similar to the 16F628, and uses the same 14 bit command
set, so the differences are pretty small, but a few changes to the
existing tutorial code is required.
- Initialisation code - the processor type, include file, and
configuration fuse settings need changing.
- Setup code - the 16F628 requires the CMCON register setting
to disable the comparator hardware, the 16F876 doesn't have this
(although the 16F876A does, but isn't set by default). However, the
16F876 does have PortA set as analogue inputs by default, so these
require setting as digital inputs in the setup code.
- Delay routines - as we're running the 16F876 five times as
fast, the delay routines require modifying to use five times as many
cycles.
- PORT changes - the 16F628 has two 8-bit ports A and B, the
16F876 has three ports - but only B and C are 8-bit, port A only has 6
pins available RA0-RA5, five of the six can be used as analogue inputs.
So it's probably easiest to change all references to PortA and TrisA to
PortC and TrisC, and connect to PortC in place of PortA.
PIC16F628-4MHz |
PIC16F876-20MHz |
Initialisation code |
LIST p=16F628
include "P16F628.inc"
__config 0x3D18 |
LIST p=16F876
include "P16F876.inc"
__config 0x393A |
Setup code |
movlw 0x07
movwf CMCON |
BANKSEL ADCON1
movlw 0x06
movwf ADCON1
BANKSEL PORTA |
Delay routines |
Delay255 movlw 0xff ;delay 255mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay10 movlw d'10' ;delay 10mS
goto d0
Delay1 movlw d'1' ;delay 1mS
goto d0
Delay5 movlw 0x05 ;delay 5ms
d0 movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0 decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00 |
Delay255 movlw 0xff ;delay 255mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay10 movlw d'10' ;delay 10mS
goto d0
Delay1 movlw d'1' ;delay 1mS
goto d0
Delay5 movlw 0x05 ;delay 5ms
d0 movwf count1
d1 movlw 0xE7
movwf counta
movlw 0x04
movwf countb
Delay_0 decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00 |
PORT changes |
TRISA
PORTA |
TRISC
PORTC |
The
changes above should allow the existing 16F628 tutorials to work on the
16F876 board, however the 16F876 has greater hardware capabilities than
the 16F628, for example - 5x10 bit analogue inputs and two PWM outputs,
both of these will be used in later tutorials, and will obviously not be
possible on the 16F628.
Back to hardware page
|