Part 1
Part 1
This presentation contains illustrations from the book Programming 8-bit PIC Microcontrollers in C
Part 1 Microcontroller Systems describes in detail the internal architecture and interfaces available in the PIC 16F887A, a typical PIC chip, as well as outlining the main features of the development system Part 2 C Programming Essentials provides simple example programs for the microcontroller which show the basic principles of C programming, and interfacing to basic I/O devices Part 3 C Peripheral Interfaces provides example programs for operating PIC chips with a full range of peripherals, using timers and interrupts
Part 1
MICROCONTROLLER SYSTEMS
Figure 1.1
User input
Input Peripherals
Output Peripherals
User output
Program download
Figure 1.2
16F877 pin-out
Figure 1.3
Flash ROM Program Memory 8192 x 14 bits 0000 1FFF
Instructions
Instruction Register
Data Bus (8 bits) EEPROM 256 bytes Ports, Timers ADC, Serial I/O
Table 1.1
Bank 0 (000 07F) Address 000h 001h 002h Register Indirect Timer0 PC Low
003h
004h 005h 006h 007h 008h 009h 00Ah 00Bh 00Ch to 01Fh 020h to 06Fh 070h to 07Fh
Status Reg
File Select Port A data Port B data Port C data Port D data Port E data PC High Interrupt Control 20 Peripheral Control Registers 80 General Purpose Registers 16 Common Access GPRs
083h
084h 085h 086h 087h 088h 089h 08Ah 08Bh 08Ch to 09Fh 0A0h to 0EFh 0F0h to 0FFh
Status Reg
File Select PortA direction PortB direction PortC direction PortD direction PortE direction PC High Interrupt Control 20 Peripheral Control Registers 80 General Purpose Registers Accesses 70h 7Fh
103h
104h 105h 106h 107h 108h 109h 10Ah 10Bh 10Ch to 10Fh 110h to 16Fh 170h to 17Fh
Status Reg
File Select Port B data PC High Interrupt Control 4 Peripheral Control Registers 96 General Purpose Registers Accesses 70h 7Fh
183h
184h 185h 186h 187h 188h 189h 18Ah 18Bh 18Ch to 18Fh 190h to 1EFh 1F0h to 1FFh
Status Reg
File Select PortB direction PC High Interrupt Control 4 Peripheral Control Registers 96 General Purpose Registers Accesses 70h 7Fh
Table 1.2
Data word (bits)
MCU
Pins
Speed MIPS
Comment
10FXXX
=6
<= 512
33 x 12 bits
<= 2
Low pin count, small form factor, cheap No EEPROM, none low power, assembler program
12FXXX
=8
<= 2 KB
12 / 14 bits
<= 5
Low pin count, small form factor, cheap EEPROM, 10-bit ADC, some low power, assembler
Mid-range, UART, I2C, SPI many low power, C or assembler program
16FXXX
<= 64
<= 14 KB
35 x 14 bits
<= 5
18FXXXX
<= 100
<= 128 KB
75 x 16 bits
<= 16
24FXXXX
<= 100
16
<= 128 KB
76 x 24 bits
= 16
Figure 1.4
Figure 1.5
Binary Counter
Compare register
Match flag
Figure 1.6
ADC operation
Reference volts, Vf
Vref+
Figure 1.7
Comparator operation
Vc-
The comparator simply sets a bit if one input is higher than the other
Figure 1.8
Interrupt
Parallel Slave Port
EXTERNAL Data x 8
INTERNAL Data x 8
Table 1.3
Interrupt Source Timer 0 Timer 1 CCP 1 Timer 2 CCP2 RB0/INT pin Port B pins Parallel Slave Port Analog Converter Analog Comparator UART Serial Port UART Serial Port SPI Serial Port I2C Serial Port I2C Serial Port EEPROM
Figure 1.9
Program Execution
Figure 1.10
HOST PC
PIC MCU
Figure 1.11
Bit period 1
0 Idle Start Bit Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Stop Bit
Time
The data bits are timed from the falling edge of the start bit
Figure 1.12
Master Serial Data Out, SDO Serial Data In, SDI Serial Clock, SCK
SPI Connections
Slave 1 SDO SDI SCK !SS Slave Select Outputs SS1 SS2 SS3
Figure 1.13
SPI Signals
SDO/SDI
Data bits
SCK
Clock
Figure 1.14
I2C Connections
+5V
Master
Slave1
Slave2
etc
SDA SCL
Figure 1.15
Start SDA
7 6
I2C Signals
Acknowledge
2 1 0
SCL
Data is strobed in using the master clock, and reception is acknowledged by the slave by taking the data line low
Listing 1.1
/* OUTBYTE.C */ #include "16F877A.h" void main() { output_D(255); } MPB 2-1-07
A simple C program
V1.0
Listing 1.2
Figure 1.16
Figure 1.17
Figure 1.18
MCU
Vpp/!MCLR Vdd Vss PGD PGC
ICSP Interface
Figure 1.19
Figure 1.20
Figure 1.21
USB
ICD2 interface
6-WAY connector
Figure 1.22