2 Microchip PIC
2 Microchip PIC
2 Microchip PIC
8-bit PIC
Microcontroller
Systems
Microcontrollers
User
input
Program
downloa
d
Input
Peripheral
s
ROM
Read Only
Memory
CPU
Central
Processi
ng
Unit
Output
Peripherals
User
output
RAM
Read &
Write
Memory
Microcontrollers
16F877 pin-out
Program Counter
(13 bits)
Address
Stack
13 bits
x8
levels
0000 1FFF
Instructions
RAM
File
Registers
368
X 8 bits
000-1FF
Instruction Register
File Address
Program address
Microcontrollers
Literal
Working (W)
Register
File Select
Register
Status bits
Status (Flag)
Register
Opcode
Instruction
Decode &
CPU control
Data Bus
(8 bits)
EEPROM
256 bytes
MCU
control
lines
Ports, Timers
ADC, Serial I/O
Timing control
Clock
Reset
Port
Microcontrollers
Bank 2 (100-180)
Bank 3(180-1FF)
Address
Register
Address
Register
Address
Register
Address
Register
000h
Indirect
080h
Indirect
100h
Indirect
180h
Indirect
001h
Timer0
081h
Option
101h
Timer0
181h
Option
002h
PC Low
082h
PC Low
102h
PC Low
182h
PC Low
003h
Status Reg
083h
Status Reg
103h
Status Reg
183h
Status Reg
004h
File Select
084h
File Select
104h
File Select
184h
File Select
005h
Port A data
085h
PortA direction
105h
185h
006h
Port B data
086h
PortB direction
106h
Port B data
186h
PortB direction
007h
Port C data
087h
PortC direction
107h
187h
008h
Port D data
088h
PortD direction
108h
188h
009h
Port E data
089h
PortE direction
109h
189h
00Ah
PC High
08Ah
PC High
10Ah
PC High
18Ah
PC High
00Bh
Interrupt Control 08Bh Interrupt Control 10Bh Interrupt Control 18Bh Interrupt Control
00Ch
to
01Fh
20 Peripheral
Control
Registers
08Ch
to
09Fh
20 Peripheral
Control
Registers
020h
to
06Fh
070h
to
07Fh
80 General
Purpose
Registers
16 Common
Access GPRs
0A0h
to
0EFh
0F0h
to
0FFh
80 General
Purpose
Registers
Accesses
70h 7Fh
10Ch
to
10Fh
110h
to
16Fh
4 Peripheral
Control
Registers
96 General
Purpose
Registers
18Ch
to
18Fh
190h
to
1EFh
4 Peripheral
Control
Registers
96 General
Purpose
Registers
170h
to
17Fh
Accesses
70h 7Fh
1F0h
to
1FFh
Accesses
70h 7Fh
Data
word
(bits)
Program
memory
(bytes)
Typical
Instruction
Set
Speed
MIPS
=6
<= 512
33 x 12
bits
<= 2
=8
<= 2 KB
12 / 14
bits
<= 5
<= 64
<= 14 KB
35 x 14
bits
<= 5
18FXXXX
<=
100
<= 128 KB
75 x 16
bits
<= 16
24FXXXX
<=
100
16
<= 128 KB
MCU
10FXXX
Microcontrollers
12FXXX
16FXXX
Pins
76 x 24
bits
= 16
Comment
Microcontrollers
Data
Direction
Latch
Output
Data
Latch
Tri-state
Output
Enable
Output
Current
Driver
Input
Data
Latch
Analogue input
multiplexer
Capture
signal
Instruction
Clock
Microcontrollers
External Pulse
Clock
Source
Select
Prescaler
(clock
divide)
Capture
register
Binary Counter
Compare
register
Post-scaler
(output
divide)
Timer
Overflow/
Timeout
(Interrupt)
Flag
Match flag
ADC operation
ANx
Microcontrollers
Analogue
to Digital
Converter
Reference volts, Vf
Vref+
Setup ADC
Read ADC
8-bit or 16-bit
integer result
Comparator operation
Vc+
Microcontrollers
Vc-
Compartor
status bit
Vc+ > Vc-
The comparator simply sets a bit if one input is higher than the other
10
Microcontrollers
Chip select
Read
Write
EXTERNAL
Data x 8
Interrupt
Parallel
Slave
Port
INTERNAL
Data x 8
11
TIMERS
Timer 0
INT_TIMER0
Timer 1
INT_TIMER1
CCP 1
INT_CCP1
Timer 2
INT_TIMER2
CCP2
INT_CCP2
Microcontrollers
PORTS
RB0/INT pin
INT_EXT
Port B pins
INT_RB
INT_PSP
Analog Converter
INT_AD
Analog Comparator
INT_COMP
SERIAL
UART Serial Port
INT_RDA
INT_TBE
INT_SSP
INT_SSP
INT_BUSCOL
MEMORY
EEPROM
INT_EEPROM
12
1
Start counter
statement
2
Run
Counter
until
overflow
Program Execution
3
Timeout
Interrupt
Microcontrollers
4
Jump to
ISR
7
Continue
5
Time-out
Process
(Interrupt
Service
Routine)
6
Return
from
Interrupt
HOST PC
PIC MCU
TX1 Transmit
Microcontrollers
RX1 Receive
Ground
Line
Driver
Interface
RX2
+/- 12V
TX2
COM PORT
Ground
14
Bit period
Microcontrollers
Time
Idle
Start
Bit
Bit
0
Bit
1
Bit
2
Bit
3
Bit
4
Bit
5
Bit
6
Bit
7
Stop
Bit
The data bits are timed from the falling edge of the start bit
15
SPI Connections
Master
Serial Data Out, SDO
Serial Data In, SDI
Serial Clock, SCK
Microcontrollers
Slave 1
Slave Select
Outputs
Slave 2
SDO
SDI
SCK
SDO
SDI
SCK
!SS
!SS
SS1
SS2
SS3
SPI Signals
SDO/SDI
Microcontrollers
SCK
Data bits
Clock
17
I2C Connections
Microcontrollers
+5V
Master
Slave1
Slave2
etc
SDA
SCL
18
I2C Signals
Start
Microcontrollers
SDA
Acknowledge
SCL
19
A simple C program
/*
OUTBYTE.C
MPB
2-1-07
V1.0
Microcontrollers
*/
#include "16F877A.h"
// MCU select
void main()
{
output_D(255);
}
// Main block
// Switch on outputs
Microcontrollers
21
Microcontrollers
Microcontrollers
10k
Microcontrollers
ICSP
Interface
Vpp/!MCLR
Vdd
Vss
PGD
PGC
1
2
3
4
5
Vdd
Vss
Board +5V Supply
24
Microcontrollers
Microcontrollers
26
Microcontrollers
Host PC
MPLAB
development
system
+ C Compiler
USB
ICD2
interface
6-WAY
connector
PIC MCU
Target
System
27
Microcontrollers