0% found this document useful (0 votes)
64 views24 pages

Architecture of PIC Microcontroller

Uploaded by

Kanish R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views24 pages

Architecture of PIC Microcontroller

Uploaded by

Kanish R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

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.

Type Size (bits) Arithmetic Type


bit/sbit 1 unsigned integer
unsigned short, char 8 unsigned integer
short, signed char 8 signed integer
int 16 signed integer
unsigned int 16 unsigned integer
long 32 signed integer
unsigned long 32 unsigned integer
float 24 real
double 32 real

6
SFR Access in C (mikroC PRO for PIC)

 All PIC SFR registers and their bits are implicitly


declared as global variables.
 These identifiers have an external linkage, and are
visible in the entire project.
 When creating a project, the mikroC PRO for PIC will
include an appropriate (*) file from defs folder, containing
declarations of available SFR registers and constants.
 For a complete set of predefined globals and constants,
look for “Defs” in the mikroC PRO for PIC installation
folder

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

• Maximum output current per pin


For most microcontrollers, current obtained from one pin is sufficient to
activate an LED or some other low-current device (10-20 mA).

• Pull-up resistors configurable by software


These resistors connect pins to the positive power supply voltage and come
into effect when the pin is configured as an input connected to a mechanical
switch or a push button.

• 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

ANSELC=0 port C is digital


ANSELC=0b00001111
TRISC=0 Port C is output
TRISC=0b11110000

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:

PORTC=0xFF;//all bits of port A are set to 1


PORTB.B5 =0; // bit 5 of PortB is reset to 0
PORTD=PORTC & 0x0F; // PortD=PortC and F hex
PORTC=PORTC | 0b11110000; // PortC=PortC or
0b11110000

12
Interfacing push button to
Microcontroller

SW SW

Interface with push button input


13
Push Button Bouncing
When a button is pressed the contacts “open & close“
rapidly for about 30ms. This is called as SWITCH
BOUNCING.

Bouncing of logical 0 example

14
Bouncing elimination: hardware

method a method b
Acceptable for a small amount of pussh-buttons

15
Bouncing elimination: software function

char Button(char *port, char pin, char


time, char active_state);
Returns 255 if the pin was in the active state for given
period, 0 otherwise
Parameters:
 port specifies the port location of the button;
 pin is the pin number on designated port and goes from
0..7;
time is a debounce period in milliseconds;
active_state can be either 0 or 1, and it determines what
logical state is chacked for bouncing

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

Pull-down diode interface

17
Interfacing Output Switch to
Microcontroller

Output switch interface

18
EasyPIC™ v7 Input/Output PORT groups

I/O group contains PORT headers, tri-state pull


up/down DIP switch, buttons and LEDs

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

Schematic of the single I/O group connected to microcontroller PORTC

21
EasyPIC™ v7 Input/Output PORT groups

Tri-state DIP switches, are used


to enable 4K7 pull-up or
pull-down resistor on any
desired port pin. Each of these
switches has three states:

Tri-state DIP
switch on PORTC

22
Push buttons set-up

Button press
level jumper (J17)

The logic state of all microcontroller digital inputs may be


changed using push buttons.
Jumper J17 is available for selecting which logic state will
be applied to corresponding MCU pin when button is
pressed in any I/O port group.

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

You might also like