Lecture 2
Lecture 2
Lecture 2
FACULTY OF ENGINEERING
ELECTRICAL & ELECTRONICS ENGINEERING DEPT.
2. Introduction to PIC16F84A
Instructor:
Assist. Prof. Dr. Mohammed ALKRUNZ
Electrical & Electronics Engineering Dept.
PIC16F84A - PortA and PortB Registers
PIC16F84A has two separated ports: Port A and Port B. These port could be used as
Input port or as Output port.
PortA has 5 pins (RA0 to RA4), the corresponding data direction register is TrisA.
Therefore, you can reach PortA just via TrisA.
Dr. M. Alkrunz
October 13, 2022 2
EEE471: Embedded System Design
PIC16F84A - Port A and Port B Registers
Setting a TrisA bit (bit = 1) will make the corresponding PortA pin as input.
Also, resetting a TrisA bit (bit = 0) will make the corresponding PortA pin as output.
Example:
TRISA 0 1 1 0 1
Dr. M. Alkrunz
October 13, 2022 3
EEE471: Embedded System Design
PIC16F84A - PortA and PortB Registers
PortB has 8 pins (RB0 to RB7), the corresponding data direction register is TrisB.
Therefore, you can reach PortB just via TrisB.
The same idea of PortA is applied for PortB to set the pins as input or output.
Dr. M. Alkrunz
October 13, 2022 4
EEE471: Embedded System Design
PIC16F84A- Memory Organization
EEPROM
Address: 00H to 3FH
“Indirect Map”
Dr. M. Alkrunz
October 13, 2022 5
EEE471: Embedded System Design
PIC16F84A- Program Memory
(1)
(5)
(1) Program Counter
(2) Stack Memory
(3) The program must start here
(4) The Interrupt Service Routine must start here
(5) Program Counter points to locations in program (6)
memory
(6) Unimplemented memory space
Dr. M. Alkrunz
October 13, 2022 6
EEE471: Embedded System Design
PIC16F84A- Data Memory
The data memory is partitioned into two areas. The
first is the Special Function Registers (SFR) area,
while the second is the General Purpose Registers (1)
(GPR) area.
Dr. M. Alkrunz
October 13, 2022 7
EEE471: Embedded System Design
PIC16F84A- EEPROM Memory
EEPROM memory consists of 64 locations, with 8 bits width (64 × 8).
It is not able to write directly to this memory. There are some protection steps to be
done before writing process is performed.
The content information which is stored in this memory is not lost during the losing of
power supply.
Dr. M. Alkrunz
October 13, 2022 8
EEE471: Embedded System Design
PIC16F84A- Some of SFR
Status Register:
Dr. M. Alkrunz
October 13, 2022 9
EEE471: Embedded System Design
PIC16F84A- Some of SFR
Example: (Z bit)
This bit is important in programming since it could be an indication for some results. For
example, if two numbers are subtracted and you want to check if they are equal to each
other or not, then:
Dr. M. Alkrunz
October 13, 2022 10
EEE471: Embedded System Design
PIC16F84A- Some of SFR
Example: (DC and C bits)
F 5 2 F F F
+ + 3 3 +
3 2 3 3
-------- -------- --------
12 7 6 2 13 2
DC = 0 DC = 1 DC = 1
C=1 C=0 C=1
Dr. M. Alkrunz
October 13, 2022 11
EEE471: Embedded System Design
PIC16F84A- Some of SFR
OPTION Register:
INTCON Register:
Dr. M. Alkrunz
11.10.2019 12
EEE471: Embedded System Design
PIC16F84A- Some of SFR
The PC is 13 bits wide. The low byte is called the PCL register.
This register is readable and writable.
The high byte is called the PCH register. This register contains
the PC<8:12> bits and is not directly readable or writable.
Dr. M. Alkrunz
11.10.2019 13
EEE471: Embedded System Design
PIC16F84A- Execution Instructions (Cycle)
Clock is the microcontroller's main starter, and is obtained from an external component
called an "oscillator".
Clock from the oscillator enters a microcontroller via OSC1 pin where internal circuit of
a microcontroller divides the clock into four even clocks Q1, Q2, Q3, and Q4 to manage
the process of “Fetch” and “Execute” operations which do not overlap, and hence
faster program.
These four clocks make up one instruction cycle (also called machine cycle) during
which one instruction is executed.
Instruction is called from program memory on every Q1, and is written in instruction
register on Q4.
Decoding and execution of instruction are done between the next Q1 and Q4 cycles.
Dr. M. Alkrunz
11.10.2019 14
EEE471: Embedded System Design
PIC16F84A- Execution Instructions (Cycle)
Dr. M. Alkrunz
11.10.2019 15
EEE471: Embedded System Design
PIC16F84A- Clock Generator “Oscillator”
PIC16F84A can work with four different configurations of an oscillator.
The user can program two Configuration Word bits (FOSC1 and FOSC0) to select one
of these four modes:
2. XT: Crystal/Resonator
4. RC: Resistor/Capacitor
Note:
The configuration Word and how to select the mode to be discussed after this topic.
Dr. M. Alkrunz
11.10.2019 16
EEE471: Embedded System Design
PIC16F84A- Clock Generator “Oscillator”
Intended for low frequency crystal applications, and gives the lowest power
consumption possible. However, it will operate at any frequency below around
200kHz.
XT: Crystal/Resonator:
The standard crystal configuration, intended for crystals or ceramics in the range
1MHz to 4MHz.
A higher drive version of the XT configuration, for higher frequency crystals and
ceramic resonators. Intended for frequencies in the region of 4MHz or greater. It
leads to the highest current consumption of all the oscillator modes.
Dr. M. Alkrunz
11.10.2019 17
EEE471: Embedded System Design
PIC16F84A- Clock Generator “Oscillator”
Crystal/Ceramic Resonator Operation (HS, XT or LP) Configuration:
Requires connection of an external resistor and capacitor. The lowest cost way of
getting an oscillator, but should not be used when any timing accuracy is required.
Dr. M. Alkrunz
11.10.2019 19
EEE471: Embedded System Design
PIC16F84A- Reset
That practically means that microcontroller can behave rather inaccurately under
certain undesirable conditions.
In order to continue its proper functioning, it has to be reset, meaning all registers
would be placed in a starting position.
Reset is not only used when microcontroller doesn't behave the way we want it to, but
can also be used when trying out a device as an interrupt in program execution, or to
get a microcontroller ready when reading in a program.
One of the most important effects of a reset is setting a program counter (PC) to zero
(00H), which enables the program to start executing from the first written instruction.
Dr. M. Alkrunz
11.10.2019 20
EEE471: Embedded System Design
PIC16F84A- Reset
In order to prevent from bringing a logical zero to MCLR pin accidentally MCLR has to
be connected via resistor to the positive supply pole.
Dr. M. Alkrunz
11.10.2019 21
EEE471: Embedded System Design
PIC16F84A- Reset
Microcontroller PIC16F84 knows several sources of resets:
b) Reset during regular work by bringing logical zero to MCLR microcontroller's pin.
Dr. M. Alkrunz
11.10.2019 22
EEE471: Embedded System Design
PIC16F84A- Configuration Word
These bits are mapped in program memory location 2007h. Address 2007h is beyond
the user program memory space and it belongs to the special test/configuration
memory space (2000h – 3FFFh). This space can only be accessed during
programming.
Dr. M. Alkrunz
11.10.2019 23
EEE471: Embedded System Design
PIC16F84A- Configuration Word
XT ON ON ON
HS
RC
Dr. M. Alkrunz
11.10.2019 24
EEE471: Embedded System Design
*Questions
Dr. M. Alkrunz
11.10.2019 25
EEE471: Embedded System Design
*Thanks
Dr. M. Alkrunz
11.10.2019 26
EEE471: Embedded System Design