Escolar Documentos
Profissional Documentos
Cultura Documentos
Chapter 3
Introduction to PIC
Microcontroller Part 2
KHAN WAHID
2010-11 (Term 1)
EE 331: Microprocessor
PIC16F84A Microcontroller
We have so far
discussed the
Fetch unit
EE 331: Microprocessor
Execute Unit
EE 331: Microprocessor
ALU
EE 331: Microprocessor
addwf h20, f
000111_1_0100000
ffffffff
ffffffff
000111_1_0100000
**Read-modifywrite operation
000111
0100000
d=0
d=1
EE 331: Microprocessor
STATUS Register
Holds three flag bits used to tell the software something about
the outcome from an instruction
??
EE 331: Microprocessor
STATUS Register
Similar to C
Holds the carry out
from the lower nibble
to the upper nibble
Hold complement of
the borrow out from
bit 3 to bit 4
EE 331: Microprocessor
DC
Z
8-input
NOR
EE 331: Microprocessor
EE 331: Microprocessor
10
E4.3 (pp. 91): A smart programmer has decided to copy the contents of
the Status register into File h40 for safekeeping so that it can be returned
later without alteration. Do you see any problem?
**SAQ4.3: Given the effect of the movf instruction on the Z flag (as in
E4.3), how could you use this instruction to determine if the contents of
any File is zero?
movf h20, f
EE 331: Microprocessor
11
STATUS Register
Not implemented
EE 331: Microprocessor
12
Data Store
hex
EE 331: Microprocessor
13
Data Store
hex
EE 331: Microprocessor
14
Data Store
hex
EE 331: Microprocessor
15
Example
bcf
Bit Clear File enables the programmer to zero any bit in any
File => bcf h20,7 clears bit 7 in File h20. All other bits
remain unaltered.
bsf
Bit Set File enables the programmer to set any bit in any File
=> bsf h31,3 sets bit 3 in File h31. All other bits remain
unchanged.
hex
EE 331: Microprocessor
16
Addressing Mode
EE 331: Microprocessor
Addressing Mode
17
EE 331: Microprocessor
18
EE 331: Microprocessor
19
EE 331: Microprocessor
Software Demonstration
MPLAB
v8.10
20
EE 331: Microprocessor
Timer / Counter
Seem easy start the counter running when the first event occurs and stop it on
the second
21
EE 331: Microprocessor
22
Timer / Counter
EE 331: Microprocessor
23
Timer / Counter
fOSC
fOSC/2
fOSC/4
fOSC/8
fOSC/16
EE 331: Microprocessor
Timer / Counter
When the maximum count (i.e. 256 for an 8-bit counter) is exceeded,
the timer will be automatically reset and counting will start from zero
again
At the same time, a special signal (called interrupt) is set which starts
another counter (details will follow later)
24
EE 331: Microprocessor
25
Timer 0 (TMR0)
EE 331: Microprocessor
26
Timer 0 (TMR0)
EE 331: Microprocessor
27
Timer 0 (TMR0)
EE 331: Microprocessor
Timer 0 (TMR0)
28
EE 331: Microprocessor
29
OPTION_REG
The user can work around this by writing an adjusted value (desired + 2) to the TMR0
register
In Counter mode (TOCS=1), when an external clock is used, TMR0 must meet
certain requirements which ensure that the external clock is synchronized with the
internal phase clock (TOSC)
EE 331: Microprocessor
30
OPTION_REG
EE 331: Microprocessor
31
Watchdog Timer
EE 331: Microprocessor
Watchdog Timer
32
EE 331: Microprocessor
Watchdog Timer
2PS x 18ms
Maximum: PS[2:0] = 111 =>
27x18ms = 2.3s MCU resets
itself
When WDT times out,
NOT_TO bit in STATUS
register is cleared
33
EE 331: Microprocessor
2PS x 18ms
Maximum: PS[2:0] = 111 =>
27x18ms = 2.3s MCU resets
itself
When WDT times out,
NOT_TO bit in STATUS
register is cleared
34
EE 331: Microprocessor
35
EE 331: Microprocessor
Data EEPROM
Enables writing
Initiates writing
Dr. KHAN WAHID
2010-11 (Term 1)
36
EE 331: Microprocessor
37
EECON2
EEPROM Matrix
PIC16F62X
EE 331: Microprocessor
EECON2
EE_GET subroutine
38
EE 331: Microprocessor
39
EECON2
Required sequence
for writing
EE 331: Microprocessor
40
EE 331: Microprocessor
41
EE 331: Microprocessor
42
EE 331: Microprocessor
43
PORTA
TRISA
Dr. KHAN WAHID
2010-11 (Term 1)
EE 331: Microprocessor
44
EE 331: Microprocessor
45
RB3:RB0
EE 331: Microprocessor
46
EE 331: Microprocessor
47
EE 331: Microprocessor
48
Schmitt Trigger
RB3:RB0
Dr. KHAN WAHID
2010-11 (Term 1)
EE 331: Microprocessor
49
EE 331: Microprocessor
50
EE 331: Microprocessor
51
Examples
EE 331: Microprocessor
52
Then, how can the start of program execution be delayed until power has
stabilized?
PIC84A on-chip
power-up and
reset circuitry
External reset circuit
Dr. KHAN WAHID
2010-11 (Term 1)
EE 331: Microprocessor
53
NOT (fosc/4)
EE 331: Microprocessor
54
Triggers PWRT
Triggers OST
(72 ms)
1024Tosc
EE 331: Microprocessor
55
EE 331: Microprocessor
56
Sets OST
EE 331: Microprocessor
Example 4.5
SAQ:
http://seng.ulster.ac.uk/eme/sidk/quintessential/Chapters_2ed/book.htm
57
EE 331: Microprocessor
Acknowledgments
58