0% found this document useful (0 votes)
84 views21 pages

Lec2 Hardware Connections

This document discusses the pin connections and configuration registers of the PIC18F4520 microcontroller. It describes the functions of pins like Vdd, Vss, MCLR, OSC1, OSC2 and ports A-E. It explains how to set the oscillator mode using the CONFIG1H register and how to configure reset voltages and the watchdog timer using other CONFIG registers. It provides example code to initialize these registers in a MPLAB C18 project.

Uploaded by

Hussam Gujjar
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)
84 views21 pages

Lec2 Hardware Connections

This document discusses the pin connections and configuration registers of the PIC18F4520 microcontroller. It describes the functions of pins like Vdd, Vss, MCLR, OSC1, OSC2 and ports A-E. It explains how to set the oscillator mode using the CONFIG1H register and how to configure reset voltages and the watchdog timer using other CONFIG registers. It provides example code to initialize these registers in a MPLAB C18 project.

Uploaded by

Hussam Gujjar
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/ 21

MICROPROCESSOR BASED

EMBEDDED SYSTEM
DESIGN
Syed Ali Jabir
Lecture 2

Email: syedalijabir@gmail.com

PIC18F4520 PIN CONNECTIONS

PIC18F4520 PIN CONNECTIONS


Vdd (Vcc)
Two pins
+5V
Some PIC18F family members have lower voltage for Vdd
Reduces noise
Reduces power consumption

Voltage level can be changed setting appropriate bits in


configuration register

PIC18F4520 PIN CONNECTIONS


Vss (GND)
Two pins
Typically multiple pins for Vcc and GND help reduce
noise in high frequency systems

PIC18F4520 PIN CONNECTIONS


MCLR
Pin 1 is the Master CLear Reset
It is an input and active-LOW
When low pulse is applied, the microcontroller will
reset and terminate all activities
Also called Power-On Reser (POR)

PIC18F4520 PIN CONNECTIONS


MCLR

Typical connections
Vdd
10K

Vdd
10K

MCLR
MCLR

Push
Button

270

PIC18F4520 PIN CONNECTIONS


OSC1 & OSC2
PIC18F can be operated in 10 different oscillator modes
We can select the mode by setting bits FOSC3:FOSC0, in
configuration register 1H
Mostly a quartz crystal of up to 40MHz is connected to
input pins OSC1 and OSC2
`

PIC18F4520 PIN CONNECTIONS


OSC1 & OSC2
1

LP

Low Power Crystal

XT

Crystal/Resonator

HS

High Speed Crystal/Resonator

HSPLL

High Speed Crystal/Resonator with PLL enabled

RC

External Resistor/Capacitor with FOSC/4 output on RA6

RCIO

External Resistor/Capacitor with I/O on RA6

INTIO1

Internal Oscillator with FOSC/4 output on RA6 and I/O on RA7

INTIO2

Internal Oscillator with I/O on RA6 and RA7

EC

External Clock with FOSC/4 output

10

ECIO

External Clock with I/O on RA6

PIC18F4520 PIN CONNECTIONS


OSC1 & OSC2

PIC18F4520 PIN CONNECTIONS

Ports
A
B
C
D
E

PIC18F4520 PIN CONNECTIONS


RECAP
Which pin is used for reset in PIC18F4520 ?
MCLR is active - ?
How many Vdd and Vcc pins are there in PIC18F4520 ?

PIC18F4520 PIN CONNECTIONS


Configuration Registers

PIC18F4520 PIN CONNECTIONS


CONFIG1H register and Oscillator Clock Source
Located at address 0x300001
Is used for clock oscillator settings

PIC18F4520 PIN CONNECTIONS


CONFIG1H register and Oscillator Clock Source
FOSC3:FOSC0
Oscillator Selection
bits

11XX

External RC oscillator, CLKO function on RA6

101X

External RC oscillator, CLKO function on RA6

1001

Internal oscillator block, CLKO function on RA6, port function on RA7

1000

Internal oscillator block, port function on RA6 and RA7

0111

External RC oscillator, port function on RA6

0110

HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)

0101

EC oscillator, port function on RA6

0100

EC oscillator, CLKO function on RA6

0011

External RC oscillator, CLKO function on RA6

0010

HS oscillator

0001

XT oscillator

0000

LP oscillator

PIC18F4520 PIN CONNECTIONS


Instruction Cycle Time
In PIC18F microcontrollers, instruction cycle time is based on of the clock source
provided to OSC pins
So if we use 4MHz crystal
4MHz/4 = 1MHz
Inst. cycle time = 1/1MHz = 1us
Compute Instruction cycle time for 10MHz crystal

PIC18F4520 PIN CONNECTIONS


CONFIG2L register and reset voltage
Located at address 0x300002
Is used for providing stable voltage and clock frequency during reset
An internal power up timer (PWRT) provides a fixed delay during power up
which keeps CPU in reset state until power supply stabilizes
Another internal oscillator startup timer (OST) does the same for crystal oscillator

PIC18F4520 PIN CONNECTIONS


CONFIG2L register and reset voltage
Microcontroller can malfunction if power source provided to Vdd pins fluctuates
Brown Out Reset Voltage (BORV) lets the user set a minimum voltage below which
microcontroller goes into reset state
For a high speed crystal of 40MHz, Vdd = 5V and BORV = 4.5V
For low power systems BORV = 1.8V

Once the voltage stabilizes, program continues execution from the same location

PIC18F4520 PIN CONNECTIONS


CONFIG2H register and watch dog timer
Located at address 0x300003
WATCH DOG TIMER is used to force the microcontroller into the known state of reset
when the system is hung up or out of control due to execution of incorrect sequence of codes
Problems can happen due to corruption of program memory caused by
Power surge
Electrically noisy environment
Inadvertent changes to PC
WDT will force the system into a state of reset/sleep from which it can recover
USES
Prevent a system from going into infinite loop due to software bug
Catch events that cause the system to hang

PIC18F4520 PIN CONNECTIONS


CONFIG4L register and background debugger
Located at address 0x300006
DEBUG
If PIC18F is connected to an in-circuit debugger (Pickit) RB6 and RB7 pins of PORTB
cannot be used as general purpose I/O
STVREN
Stack Full/Underflow Reset Enable

LVP
Used for low-voltage in-circuit serial programming (ICSP) via pin RB5

PIC18F4520 PIN CONNECTIONS


Setting CONFIG registers in MPLAB C18 compiler
#include <p18f4520.h>
#pragma config OSC = HS
#pragma config BORV = 45, PWRT = ON, BOR = ON
#pragma config WDT = OFF
#pragma config DEBUG = OFF, LVP = OFF
void main (void)
{
..
..
.
}

REFERENCES
PIC18F4520 datasheet

You might also like