8/3/2019 ESD with PIC MCU-2009_P1
1/35
05-Apr-11
1
1
ESD with PIC MCUPart 1
2
Chapter 1
A VERY BRIEF HISTORYOF
MICROPROCESSORS & MICROCONTROLLERS
8/3/2019 ESD with PIC MCU-2009_P1
2/35
8/3/2019 ESD with PIC MCU-2009_P1
3/35
8/3/2019 ESD with PIC MCU-2009_P1
4/35
8/3/2019 ESD with PIC MCU-2009_P1
5/35
05-Apr-11
5
9
10
A generic microcontroller
8/3/2019 ESD with PIC MCU-2009_P1
6/35
05-Apr-11
6
11
12
Advantages of PIC
It is a RISC (Reduced Instruction SetComputer) design
Only thirty seven instructions to remember
Its code is extremely efficient, allowing thePIC to run with typically less programmemory than its larger competitors.
It is low cost, high clock speed
8/3/2019 ESD with PIC MCU-2009_P1
7/35
05-Apr-11
7
13
Harvard Architecture
14
Von-Neumann Architecture
8/3/2019 ESD with PIC MCU-2009_P1
8/35
05-Apr-11
8
15
Complex Instruction Set Computer (CISC)
16
PICs and most Harvard chips are RISC
8/3/2019 ESD with PIC MCU-2009_P1
9/35
05-Apr-11
9
17
Family Core Architectural Differences
18
Family Core Architectural Differences ..
8/3/2019 ESD with PIC MCU-2009_P1
10/35
8/3/2019 ESD with PIC MCU-2009_P1
11/35
05-Apr-11
11
21
The PIC Family: Data Memory
22
The PIC Family: Control Registers
8/3/2019 ESD with PIC MCU-2009_P1
12/35
05-Apr-11
12
23
The PIC Family: Peripherals
24
PIC Peripherals: Ports (Digital I/O)
8/3/2019 ESD with PIC MCU-2009_P1
13/35
8/3/2019 ESD with PIC MCU-2009_P1
14/35
05-Apr-11
14
27
Some members of the PIC 16 Series family ..
28
The PIC 16F84A pin connection diagram
8/3/2019 ESD with PIC MCU-2009_P1
15/35
05-Apr-11
15
29
PIC16C8X PINOUT DESCRIPTION
30
PIC16C8X PINOUT DESCRIPTION ..
8/3/2019 ESD with PIC MCU-2009_P1
16/35
05-Apr-11
16
31
Block diagram of the 16F84A (supplementary
labels in shaded boxes added by the author)
32
W Register
8/3/2019 ESD with PIC MCU-2009_P1
17/35
05-Apr-11
17
33
The 16F84A Status register
34
The PIC16F84 Status register
Unlike most MCUs, there are no instructions to specifically clear or set aflag, such as sec for SEt Carry (MC6800). However, as the Status registeris accessible as a file in the Data store, then any instruction that can alterthe contents of a file can potentially change the state of a flag.
8/3/2019 ESD with PIC MCU-2009_P1
18/35
05-Apr-11
18
35
16F84A memory features
36
The 16F84A program memory and Stack
8/3/2019 ESD with PIC MCU-2009_P1
19/35
05-Apr-11
19
37
Data memory and Special Function Register
map of the 16F84A
38
16F84A Configuration Word
8/3/2019 ESD with PIC MCU-2009_P1
20/35
05-Apr-11
20
39
The EECON1 Special Function Register (address 88H)
40
Data EEPROM
The PIC16F84 has a blockof 64 bytes of data that does not
require power to retain its contents. This non-volatile
memory is not part of the (volatile) Data store and is
accessed through SPRs as a peripheral device.
Any byte can be addressed and then read from or written to
via the EEDATA register as addressed by the EEADRregister and controlled by the EECON1 and EECON2 control
file registers.
Data EEPROM has a minimum endurance of 1,000,000
writes and such data is retained for upwards of 40 years.
Some typical uses of a non-volatile depository would be to
hold the number of pages printed in a laser printer or total
miles/kilometers travelled in a car.
8/3/2019 ESD with PIC MCU-2009_P1
21/35
05-Apr-11
21
41
EEPROM To readan EEPROM location, the required address must be
placed in EEADR and the RD bit set in EECON1. The data in thatmemory location is then copied to the EEDATA register and can beread immediately.
To writeto an EEPROM location, the required data and addressmust be placed in EEDATA and EEADR respectively. The writeprocess is enabled by the WREN (Write Enable) bit being set high,followed by the bytes 55H followed by AAH being sent to theEECON2 register.
The built-in requirement for these codes helps to ensure thataccidental writes do not take place, for example on power-up ordown. The WR bit is then set high and writing actually commences.The write completion is signalled by the setting of bit EEIF inEECON1.
42
EEPROM Read & Write
8/3/2019 ESD with PIC MCU-2009_P1
22/35
05-Apr-11
22
43
Clock oscillator and instruction cycle
44
Microcontroller oscillator generator circuits
8/3/2019 ESD with PIC MCU-2009_P1
23/35
05-Apr-11
23
45
Three ways toprovide theclock signalto a PIC
46
Pipelining
The combination of the RISC instruction set and the Harvard memory map used byPIC microcontrollers has an added advantage: instructions can be pipelined. Every instruction in a computers program memory has first to be fetched and thenexecuted. In many CPUs these two steps are done one after the other first the CPU fetches and then it executes. If, however, program memory has its ownaddress and data bus, separate from data memory (i.e. a Harvard structure), thenthere is no reason why a CPU cannot be designed so that while it is executing oneinstruction, it is already fetching the next. This is called pipelining.
8/3/2019 ESD with PIC MCU-2009_P1
24/35
05-Apr-11
24
47
Power-up and Reset
In the 16F84A there is a Reset input, MCLR (Master Clear, onpin 4). As long as this is held low, the microcontroller is held inReset. When it is taken high, program execution starts.
If the pin is taken low while the program is running, then programexecution stops immediately and the microcontroller is forcedback into Reset mode.
R = 10100 k
48
Some ways to power a PIC
The last one is only for a PIC that is not powering an LED orother high-current load.
8/3/2019 ESD with PIC MCU-2009_P1
25/35
05-Apr-11
25
49
The 16F84A on-chip reset circuit
50
Addressing Modes
8/3/2019 ESD with PIC MCU-2009_P1
26/35
05-Apr-11
26
51
DIRECT/INDIRECT ADDRESSING
52
Data storememory map.
8/3/2019 ESD with PIC MCU-2009_P1
27/35
05-Apr-11
27
53
Indirect address mode
Direct address mode
54
8/3/2019 ESD with PIC MCU-2009_P1
28/35
05-Apr-11
28
55
56
PIC18Fxx2 MCU
8/3/2019 ESD with PIC MCU-2009_P1
29/35
05-Apr-11
29
57
PIC18Fxx2 Simplified Block Diagram
58
PIC18Fxx2 Memory Organization
8/3/2019 ESD with PIC MCU-2009_P1
30/35
05-Apr-11
30
59
PIC18Fxx2 Data Memory Organization
60
PIC18Fxx2 Accessing Data Memory
8/3/2019 ESD with PIC MCU-2009_P1
31/35
05-Apr-11
31
61
62
8/3/2019 ESD with PIC MCU-2009_P1
32/35
05-Apr-11
32
63
64
PORTA and TRISA Registers PORTA is a 5-bit wide latch. RA4 is a Schmitt Trigger input and an
open drain output. All other RA port pins have TTL input levels and
full CMOS output drivers. All pins have data direction bits (TRIS
registers) which can configure these pins as output or input.
Setting a TRISA bit (=1) will make the corresponding PORTA pin an
input, i.e., put the corresponding output driver in a hi-impedance
mode. Clearing a TRISA bit (=0) will make the correspondingPORTA pin an output, i.e., put the contents of the output latch on the
selected pin.
Reading the PORTA register reads the status of the pins whereas
writing to it will write to the port latch. All write operations are read-
modify-write operations. So a write to a port implies that the port
pins are first read, then this value is modified and written to the port
data latch.
The RA4 pin is multiplexed with the TMR0 clock input.
8/3/2019 ESD with PIC MCU-2009_P1
33/35
05-Apr-11
33
65
PORTA and TRISA Registers
66
Logic circuit diagram for pins RA0 to RA3
8/3/2019 ESD with PIC MCU-2009_P1
34/35
05-Apr-11
34
67
PORTB and TRISB Registers PORTB is an 8-bit wide bi-directional port. The corresponding data
direction register is TRISB. A '1' on any bit in the TRISB register puts the
corresponding output driver in a hi-impedance mode. A '0' on any bit in
the TRISB register puts the contents of the output latch on the selected
pin(s).
Each of the PORTB pins have a weak internal pull-up. A single control bit
can turn on all the pull-ups. This is done by clearing the RBPU
(OPTION_REG) bit. The weak pull-up is automatically turned off
when the port pin is configured as an output. The pull-ups are disabled
on a Power-on Reset.
Four of PORTBs pins, RB7:RB4, have an interrupt on change feature.
Only pins configured as inputs can cause this interrupt to occur (i.e., any
RB7:RB4 pin configured as an output is excluded from the interrupt on
change comparison).
The pins value in input mode are compared with the old value latched on
the last read of PORTB. The mismatch outputs of the pins are ORed
together to generate the RB port change interrupt.
68
8/3/2019 ESD with PIC MCU-2009_P1
35/35
05-Apr-11
69
70
Parallel input/output with PORTA & PROTB