Part 1 PIC Microcontroller Systems
Part 1 PIC Microcontroller Systems
8-bit PIC
Microcontrollers
in C
Martin Bates
Elsevier 2008
This presentation contains illustrations from the book
‘Programming 8-bit PIC Microcontrollers in C’
MICROCONTROLLER
SYSTEMS
Figure 1.1 Elements of a digital controller
Input Output
User input Peripherals CPU Peripherals User
output
Central
Processing
ROM Unit RAM
Program Read Only Read & Write
download Memory Memory
Instruction Register
000-1FF
File Address
Program address
EEPROM
Instruction MCU 256 bytes
Decode & control
CPU control lines
Ports, Timers
ADC, Serial I/O
Timing control
Clock Reset
Port A B C D E
003h Status Reg 083h Status Reg 103h Status Reg 183h Status Reg
004h File Select 084h File Select 104h File Select 184h File Select
006h Port B data 086h PortB direction 106h Port B data 186h PortB direction
00Bh Interrupt Control 08Bh Interrupt Control 10Bh Interrupt Control 18Bh Interrupt Control
00Ch 20 Peripheral 08Ch 20 Peripheral 10Ch 4 Peripheral 18Ch 4 Peripheral
to Control to Control to Control to Control
01Fh Registers 09Fh Registers 10Fh Registers 18Fh Registers
110h 96 General 190h 96 General
020h 80 General 0A0h 80 General
to Purpose to Purpose to Purpose to Purpose
06Fh Registers 0EFh Registers 16Fh Registers 1EFh Registers
070h 16 Common 0F0h Accesses 170h Accesses 1F0h Accesses
to Access GPRs to 70h – 7Fh to 70h – 7Fh to 70h – 7Fh
07Fh 0FFh 17Fh 1FFh
Table 1.2 PIC microcontroller types
Data Program Typical
Speed
MCU Pins word memory Instruction
MIPS Comment
(bits) (bytes) Set
76 x 24
24FXXXX <= <= 128 Power range, 3V supply, no
16 bits = 16
100 KB EEPROM,
data RAM < 8 KB, C program
Figure 1.4 I/O pin operation
Output Output
CPU Data Bus
Data Current
Latch Driver
Write data bit
Input
Data
Read data Latch
bit
Analogue input
multiplexer
Capture
Capture
signal
register
Timer
Instruction Overflow/
Clock Pre- Post-scaler
Clock Timeout
Source scaler Binary Counter (output
(Interrupt)
Select (clock divide)
Flag
External Pulse divide)
Vc+
Compartor
status bit
Vc- Vc+ > Vc-
The comparator simply sets a bit if one input is higher than the other
Figure 1.8 Parallel Slave Port operation
EXTERNAL INTERNAL
Data x 8 Data x 8
1 2
Start counter Run
statement Counter
until
overflow
Program Execution
3
Timeout
Interrupt
4
Jump to
ISR
7
Continue
5
Time-out
Process
(Interrupt
Service 6
Routine) Return
from
Interrupt
HOST PC
PIC MCU
Bit period
0
Time
Idle Start Bit Bit Bit Bit Bit Bit Bit Bit Stop
Bit 0 1 2 3 4 5 6 7 Bit
The data bits are timed from the falling edge of the start bit
Figure 1.12 SPI Connections
Master
Slave 1 Slave 2
SDO SDO
SDI SDI
SCK SCK
!SS !SS
SCK Clock
SDA
SCL
Start Acknowledge
Address / Data bits
SDA 7 6 5 4 3 2 1 0
SCL
/*
OUTBYTE.C MPB 2-1-07 V1.0
*/
#include "16F877A.h" // MCU select
void main() // Main block
{
output_D(255); // Switch on outputs
}
:1000000000308A0004280000840183131F30830518
:1000100083161F149F141F159F1107309C00880121
:08002000FF3083128800630029
:02400E00733FFE
:00000001FF
;PIC16F877A
Application Board
Reset
MCU
10k
1 Vpp/!MCLR
ICSP Vdd
2
Interface Vss
3
4 PGD
5 PGC
Vdd Vss
Board +5V Supply
Host PC
MPLAB PIC MCU
development ICD2 Target
system USB interface System
6-WAY
+ C Compiler connector