Lecture 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

ISTANBUL AYDIN UNIVERSITY

FACULTY OF ENGINEERING
ELECTRICAL & ELECTRONICS ENGINEERING DEPT.

EEE471: EMBEDDED SYSTEM DESIGN

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.

 In PIC16F84A, PortA has the pin’s number: 17, 18, 1, 2, 3

Dr. M. Alkrunz
October 13, 2022 2
EEE471: Embedded System Design
PIC16F84A - Port A and Port B Registers

How to adjust the Port A pins as digital input or digital output?!!

 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:

Bit-4 Bit-3 Bit-2 Bit-1 Bit-0

TRISA 0 1 1 0 1

 RA0, RA2, RA3 are inputs.

 RA1, RA4 are outputs.

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.

 In PIC16F84A, PortB has the pin’s number: 6, 7, 8, 9, 10, 11, 12, 13

 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

Two Types of Memory

Data Memory Program Memory

RAM (GPR+SFR) Flash Memory


“Direct Map” “Read/Write” Memory

EEPROM
Address: 00H to 3FH
“Indirect Map”

Dr. M. Alkrunz
October 13, 2022 5
EEE471: Embedded System Design
PIC16F84A- Program Memory
(1)

 The program memory is a flash type which mean


(2)
you can write/erase many times.

 The size of program memory is 1024 locations, (3)

with 14 bits width (1024 × 14). (4)

 00H is the address of (Reset Vector).

 04H is the address of (Interrupt Vector).

(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.

 The SFRs control the operation of the device.

 GPR has 68 locations from 0CH to 4FH. These


locations are left to the user to store information on
them, and they will lose their contents information if
the power supply is lost. (2)

(1) SFR - “Have special functions”


(2) GPR - “For user use”
(3) Not implemented (Read as 0)
(3)

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.

 To be discussed in details later.

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:

 If Z = 1, then the two numbers are equal.

 If Z = 0, then the two numbers are not equal.

Dr. M. Alkrunz
October 13, 2022 10
EEE471: Embedded System Design
PIC16F84A- Some of SFR
Example: (DC and C bits)

Note: Summation is performed in hexadecimal.

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

 If carry occurs from the first 4-digits, then DC = 1.


 If carry occurs from the all addition process, then C = 1.

Dr. M. Alkrunz
October 13, 2022 11
EEE471: Embedded System Design
PIC16F84A- Some of SFR
OPTION Register:

 This register has an important role in TMR0 setting.

 We will discuss that in details at the topic of TMR0.

INTCON Register:

 This register has an important role in Interrupt.

 We will discuss that in details at the topic of Interrupt.

EEDATA, EEADR, EECON1, EECON2 Registers:

 These registers have an important role in EEPROM.

Dr. M. Alkrunz
11.10.2019 12
EEE471: Embedded System Design
PIC16F84A- Some of SFR

PCL and PCLATH Register:


 The program counter (PC) specifies the address of the
instruction to fetch for execution.

 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.

 All updates to the PCH register go through the PCLATH


register.

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:

1. LP: Low Power Crystal

2. XT: Crystal/Resonator

3. HS: High Speed Crystal/Resonator

4. RC: Resistor/Capacitor

 PIC16F84A can also accept an external clock source.

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”

LP: Low Power Crystal:

 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.

HS: High Speed Crystal/Resonator:

 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:

1) See Table below for recommended


values of C1 and C2.
2) A series resistor (RS) may be required
for AT strip cut crystals.

 Higher capacitance increases the stability


of the oscillator, but also increases the
start-up time.
 These values are for design guidance
only.
 Rs may be required in HS mode, as well
as XT mode, to avoid overdriving crystals
with low drive level specification.
 Since each crystal has its own
characteristics, the user should consult the
crystal manufacturer for appropriate
values of external components.
Dr. M. Alkrunz
11.10.2019 18
EEE471: Embedded System Design
PIC16F84A- Clock Generator “Oscillator”
RC: Resistor/Capacitor:

 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

 Reset is used for putting the microcontroller into a 'known' condition.

 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.

 Resistor should be between 5 and 10K.

Dr. M. Alkrunz
11.10.2019 21
EEE471: Embedded System Design
PIC16F84A- Reset
Microcontroller PIC16F84 knows several sources of resets:

a) Reset during power on, POR (Power-On Reset)

b) Reset during regular work by bringing logical zero to MCLR microcontroller's pin.

c) Reset during SLEEP regime

d) Reset at watchdog timer (WDT) overflow

e) Reset during at WDT overflow during SLEEP work regime.

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

 Again, this space can only be accessed during programming.


 Therefore, when you program the microcontroller, select them as follows:

OSC CP PWRTE WDT

XT ON ON ON

LP OFF OFF OFF

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

You might also like