Microcontrollers - Chapter 03
Microcontrollers - Chapter 03
Al-AZHAR UNIVERSITY
Microcontrollers:
Programming and Applications
(ITME 4336 )
Chapter 3
Mid-range PIC Architecture
Lecturer: Dr. Mohammad Aqel
First Semester 2020/2021
In a machine with Harvard architecture, on the other hand, the processor can read
and write instructions and data to and from memory at the same time. This results
in a faster, even though more complex, machine. Thus a greater flow of data is
possible through the central processing unit, and of course, a greater speed of
work.
The figure below shows the program and data memory space in a mid-range PIC.
• It is usually used for storing important data that must not be lost if
power supply suddenly stops. For instance, one such data is an
assigned temperature in temperature regulators. If during a loss of
power supply this data was lost, we would have to make the
adjustment once again upon return of supply. Thus our device
looses on self-reliance.
Pin no.6 RB0 Zero pin on port B. Interrupt input is an additional function.
Pin no.7 RB1 First pin on port B. No additional function.
Pin no.8 RB2 Second pin on port B. No additional function.
Pin no.9 RB3 Third pin on port B. No additional function.
Pin no.10 RB4 Fourth pin on port B. No additional function.
Pin no.11 RB5 Fifth pin on port B. No additional function.
Pin no.12 RB6 Sixth pin on port B. 'Clock' line in program mode.
Pin no.13 RB7 Seventh pin on port B. 'Data' line in program mode.
• The low-power frequency crystal option is the one with lowest power
consumption and can be used in systems where the power consumption
element is important.
• The first three oscillator modes (LP, XT, and HS) allow selecting different
frequency ranges.
• The HS option has the highest frequency range and consumes the most
power.
• The LP option has low gain and consumes the least power of the three
crystal modes.
• The built-in oscillator is usually set to operate at 4 MHz and is selected during
the programming of the device. For example, the PIC16F62X series of PIC
microcontrollers can be operated with an internal resistor– capacitor-based
4MHz oscillator (called mode INTRC).
• For example, the internal oscillator frequency in the PIC16F62X can be set by
connecting a resistor to pin RA7 as shown in the Figure.
• The first two reset sources in the preceding list are the most common.
Alazhar University Dr. Mohammad Aqel 27
GAZA First Semester 2020/2021
• POR reset serves to bring all PIC registers to an initial state,
including the program counter register.
• The processor’s !MCLR pin produces the reset action when it reads
logic zero. The exclamation sign preceding the pin’s name (or a line
over it) indicates that the action is active-low.
In order to define a pin as input or output pin, the right combination of zeros and
ones must be written in TRIS register.
If at the appropriate place in TRIS register a logical "1" is written, then that pin
is an input pin, and if the opposite is true, it's an output pin.
Every port has its proper TRIS register. Thus, port A has TRISA, and port B has
TRISB.
Alazhar University Dr. Mohammad Aqel 33
GAZA First Semester 2020/2021
PORTB
• PORTB has 8 pins joined to it. The appropriate register for direction
of data is TRISB.
• TRISB =0x0F; pins 0, 1, 2, and 3 are declared for input, and pins 4, 5, 6,
and 7 for output.
• Not all banking bits are implemented in all devices. For example, the
16F84/16F84A contain two memory banks; therefore, bank shifting requires a
single bank-select bit (RP0). In this case the RP1 bit is not implemented.
• In devices with more than two memory banks bank selection is as shown in
Table 8.2.
Figure 8-7 shows how banked memory is accessed in direct addressing. The
illustration refers to a mid-range PIC with four banks, as is the case with the
16F87x.
Alazhar University Dr. Mohammad Aqel 44
GAZA First Semester 2020/2021
Figure 8-7 Memory Access in Direct Addressing
Bit affected by operations of addition, subtraction and shifting. Unlike C bit, this bit represents
transfer from the fourth resulting place. It is set by addition when occurs carry from bit3 to bit4, or by
subtraction when occurs borrow from bit4 to bit3, or by shifting in both direction.
1=transfer occurred on the fourth bit according to the order of the result
0=transfer did not occur
Bit which is set whenever power supply is brought to a microcontroller as it starts running,
after each regular reset and after execution of instruction CLRWDT. Instruction SLEEP
resets it when microcontroller falls into low consumption/usage regime.
1=after supply has been turned on
0= executing SLEEP instruction
Bit is set after turning on the supply and execution of CLRWDT and SLEEP instructions.
Bit is reset when watchdog gets to the end signaling that something is not right.
1=overflow did not occur
0=overflow did occur
These two bits are upper part of the address for direct addressing. Since
instructions which address the memory directly have only seven bits, they need one
more bit in order to address all 256 bytes which is how many bytes PIC16F84 has.
RP1 bit is not used, but is left for some future expansions of this microcontroller.
01=first bank
00=zero bank
10= 2nd bank
11= 3rd bank
Bit whose role is to be an eighth bit for indirect addressing of internal RAM.
0=bank 0 and 1 (from 00h to FFh)
1=bank 2 and 3
Note that all GPRs are mapped to bank 0. In the 16F84A, this means that user-
defined registers created in bank 0 are accessible no matter which bank is currently
selected.
Alazhar University Dr. Mohammad Aqel 51
GAZA First Semester 2020/2021
• The Figure 8-8 is a map of
the register file in the 16F87x
family.
• General purpose registers do
not start at the same address
offset in each bank. However,
there is a common area that
extends from 0x70 to 0x7f
that is accessible no matter
which bank is selected.
• This 16-byte area are
accessible no matter which
bank is currently selected.
• GPRs created outside this
common area are only
accessible when the
corresponding bank is
selected.
Figure 8-8 16F87x File Register Map
Alazhar University Dr. Mohammad Aqel 52
GAZA First Semester 2020/2021
• The registers in boldface in Figure 8-8 are accessible
from any bank. These registers, such as STATUS and
the indirect addressing registers FSR and INDF, are
bank-independent.
In the 16F84A all GPRs are mapped to the same memory area, no matter in which
bank they are defined. The GPR memory space actually extends from 0x0c to 0x4f
(68 bytes).
A different situation exists in the 16F87x PICs, in which only 16 bytes of GPR
space is mirrored in all three banks. This is the memory referred to as the common
area in Figure 8-8.