Architecture of PIC Microcontroller
Architecture of PIC Microcontroller
1
Registers
PIC
Register or a memory cell is an electronic element
which can memorize the state of n bits (n bit register)
Typically n = 8 bits =1 byte
Two types:
o General purpose registers – GPR
o Special function registers - SFR
2
GPR: do not have any special and predetermined function, it is
used for store data
SFR: function is predetermined by the manufacturer.
bits are connected to internal circuits of the microcontroller
timers, A/D converter, oscillators etc,
they are directly in command of the operation of these circuits,
3
SFR REGISTERS
SFR – Special Function Registers
Registers whose function is predetermined by
the manufacturer
SFR bits are connected
to internal circuits of the
microcontroller such as
timers, A/D converter,
oscillators and others,
which means that they
are directly in command
of the operation of these
circuits.
4
MEMORY
Memory is part of the microcontroller used for data storage.
Each memory address corresponds to one memory location.
The contents of any location can be accessed by its addressing.
Memory can either be written to or read from.
5
Basic Numeric Data Types In MikroC Language
There are several types of data that can be used in C
programming language. A table below shows the range of values
which these data can have when used in their basic form.
6
SFR Access in C (mikroC PRO for PIC)
7
INPUT / OUTPUT PORTS
To connect microcontroller to the peripherals we use
registers (called ports).
Ports are connected to the microcontroller pins.
Pins can be configured to be outputs or inputs. It is simply
performed by program.
8
Important Data Ports Specifications
• SFR mapped
Each I/O port is under control of the specialized SFR, which means that each
bit of that register determines the state of the corresponding microcontroller
pin. For example, by writing logic one (1) to a bit of the control register
(SFR), the appropriate port pin is automatically configured as an input and
voltage brought to it can be read as logic 0 or 1. Otherwise, by writing zero to
the SFR, the appropriate port pin is configured as an output. Its voltage (0V
or 5V) corresponds to the state of appropriate port register bit.
9
Working with Ports (Digital I/O Ports)
input/output - pin function (input or output) can be
changed according to particular need.
pin function change is performed by software
pin function can be changed during operation
10
A single data I/O pin of one of
the ports A-E:
Data Ports
Structure
Data I/O port functions:
WR LAT- this latches the data
written to the pin (configured as an
output)
WR TRIS - this latches the data
direction for the pin (0 = output, 1 =
input)
RD Port- this reads the current
value of the pin (configured as an
input)
Each data port (A-E) consists of a
number of pins, each of which can
individually be configured as an input
or output
11
Data Ports Access in C
Data ports are controlled via SFR-mapped registers, and
can be accessed as implicitly declared variables:
Examples:
12
Interfacing push button to
Microcontroller
SW SW
14
Bouncing elimination: hardware
method a method b
Acceptable for a small amount of pussh-buttons
15
Bouncing elimination: software function
16
Interfacing LED to Microcontroller
• Standard digital port output: IO=±25mA
• Enough current to drive standard LED
• Standard led Id=10mA,
• low current LED Id<1mA
• R1 selection: (Vcc-1.4V)/R1=Id
17
Interfacing Output Switch to
Microcontroller
18
EasyPIC™ v7 Input/Output PORT groups
19
EasyPIC™ v7 Input/Output PORT groups
PORT headers, PORT buttons and PORT LEDs are next to each
other, and grouped together.
additional PORT headers are also provided on the left side of the
board, so you can access any pin you want from both sides of
the board.
Some PORT pins are directly connected to the microcontroller, and
some that are connected to other on-board modules are enabled via
jumpers (for example USB jumpers, J12 and J18).
SW1,SW2, SW3 and SW4 connect digital ports to other
peripherals
20
EasyPIC™ v7 Input/Output PORT groups
21
EasyPIC™ v7 Input/Output PORT groups
Tri-state DIP
switch on PORTC
22
Push buttons set-up
Button press
level jumper (J17)
23
Input/Output PORT Software considerations
In order to use IO possibilities of EasyPic, SW1-SW9
should be properly configured, consult
EasyPic_V7_Manual and EasyPic_V7_Schematic
Define function, input or output
For push button debounsing use library function!
24