Professional Documents
Culture Documents
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
Figure 1.1
Part 1
User input
Input Peripherals
Output Peripherals
User output
MICROCONTROLLER SYSTEMS
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
The microcontroller pins have multiple functions Shows the main parts of the chip in simplified form
03-Jun-11
Table 1.1
Bank 0 (000 07F) Address 000h 001h 002h 003h 004h 005h 006h 007h 008h 009h 00Ah 00Bh 00Ch to 01Fh 020h to 06Fh 070h to 07Fh Register Indirect Timer0 PC Low 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
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 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
12FXXX
=8
<= 2 KB
12 / 14 bits
<= 5
16FXXX
<= 64
<= 14 KB
35 x 14 bits
<= 5
18FXXXX
PC High Interrupt Control 4 Peripheral Control Registers 96 General Purpose Registers Accesses 70h 7Fh
<= 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
Figure 1.7
Comparator operation
Vc+ Input volts 0-Vf ANx Analogue to Digital Converter Reference volts, Vf Vref+ Setup ADC Read ADC 8-bit or 16-bit integer result VcCompartor status bit Vc+ > Vc-
The comparator simply sets a bit if one input is higher than the other The ADC converts an analog input into a binary code
03-Jun-11
EXTERNAL Data x 8
INTERNAL Data x 8
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
Figure 1.10
Program Execution 3 Timeout Interrupt 4 Jump to ISR 7 Continue 5 Time-out Process (Interrupt Service Routine)
Figure 1.11
Figure 1.12
Master Serial Data Out, SDO Serial Data In, SDI Serial Clock, SCK
SPI Connections
Bit period 1
Slave 1
0 Idle Start Bit Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Stop Bit
Time
SDO SDI SCK !SS Slave Select Outputs SS1 SS2 SS3
The data bits are timed from the falling edge of the start bit
03-Jun-11
Figure 1.13
SPI Signals
+5V
Figure 1.14
I2C Connections
Master
Slave1
Slave2
etc
SDO/SDI
Data bits
SDA SCL
SCK
Clock
Slave selection uses addresses issued by the Master Each data bit is transferred on the falling edge of the clock
A simple C program
I2C Signals
/* OUTBYTE.C MPB 2-1-07 V1.0 Acknowledge
2 1 0
*/ #include "16F877A.h" void main() { output_D(255); } // MCU select // Main block // Switch on outputs
SCL
Data is strobed in using the master clock, and reception is acknowledged by the slave by taking the data line low
Listing 1.2
Figure 1.16
03-Jun-11
Figure 1.17
Figure 1.18
ICSP Interface
1 2 3 4 5
Connections to the target chip for programming Basic hardware for downloading the program to a test board
Figure 1.19
Figure 1.20
Figure 1.21
Figure 1.22
USB
ICD2 interface
6-WAY connector