Sunteți pe pagina 1din 24

B.Sc.

Electronics Engineering
Autumn 2014

Lecture 8

Engr. Kamran Javed


PIC18 : Hardware Connections
Vdd (Vcc)
Two pins, +5V is connected to these pins
Vss (GND)
Two pins for ground connection
OSC1 and OSC2
Clock source, most often crystal oscillator is connected.
PIC18F can have speeds up to 40 MHz.
MCLR (Master CLear Reset)
Normally this pin is kept active high
When active low is applied Controller starts Power-on-reset
operation
On Reset: All operations terminate, PC, WREG and SP are
cleared to zero. All TRISx registers are initialized to FFh,
ports are configured as input.
PIC18 : Hardware Connections contd
CPU needs stable clock and Voltage to work properly
PIC comes with features to accommodate this during reset
Two ways of connection
PIC18 : Hardware Connections contd

Minimum Connections for any PIC18


PIC18 : Configuration Registers
Different features can be configured through these registers
Reduces the system cost by eliminating external components
Every Register is 8-bit in size and can be programmed by
CONFIG directive or can be accessed through table reads and
writes. Complete list can be seen at web page of Microchip.
PIC18 : Configuration Registers contd
CONFIG1H Oscillator and Clock Source
PIC18 : Configuration Registers contd

Connections for Crystal and EC (External Clock)

OSCSEN (bit 5) selects internal oscillator (32 KHz, low


power, independent of external connections) or other
options as listed above
PIC18 : Configuration Registers contd

Choices for clock speed


CONFIG directive can be
added in source code
CONFIG OSC=HS, OSCS=OFF ;
Hi Speed osci, disable switch
PIC18 : Configuration Registers contd
CONFIG2L RESET Voltages

CONFIG BORV=45, PWTR=ON, BOR=ON ; example statement


PIC18 : Configuration Registers contd
To ensure the stable voltage and clock during power up
process, there are two timers: Power-up-Timer (PWT) and
Oscillator start-up-Timer (OST)
PWT provides a fixed delay during power up and CPU
remains in reset state until the power supply stabilizes
OST does the same thing for Crystal Oscillator (Clock)
Occasionally Vcc (Vdd) fluctuates causing CPU to
malfunction: Brown-out voltage (BOVR) allows to set the
minimum voltage for Vdd, if it falls below that CPU enters
Reset state (stop execution of programs without losing
any data in registers)
CPU comes in operation state automatically when Vdd fix
PIC18 : Configuration Registers contd
CONFIG2H Watchdog Timer

CONFIG WDT=ON ; example statement in source code


PIC18 : Configuration Registers contd
Watchdog timer is used to force the CPU into a known
state of reset when the system is hung up or out of
control due t o execution of an incorrect sequence of
code. For Example:
Prevent system from going into infinite loop due to software bug
Catch events that cause the system to hang
During sleep mode WDT monitors the external activity
These problems can happen due to corruption of program
in ROM caused by power surge, electrical noise or
inadvertent change to the PC.
WDT postscale bits allow delays upto two minutes
PIC18 : Configuration Registers contd
CONFIG4L Background Debugger

CONFIG WDT=ON ; example statement in source code


PIC18 : Configuration Registers contd

DEBUG
If PIC18 system is connected to in-circuit debugger, then RB6 and
RB7 are lost. By disabling background debugger these pins can
be used as general purpose I/O
STVREN
Stack overflow: system goes to a reset state
LVP
Low voltage in-circuit serial programming (ICSP), RB5 is used

CONFIG DEBUG = OFF, LVP = OFF, STVR = OFF


PIC18 : Configuration Registers contd

LIST Directive
LIST P = 18f458, F = INHX32, MM= OFF, R = HEX, ST = OFF, x= OFF
LIST options
PIC18 : Configuration Registers contd

Putting it All Together


PIC18 : INTEL HEX FILES
Executable machine code to transfer into ROM
Intel Hex File Formats

If we do not choose in LIST the hex format then default


is INHX32. This format can be utilized up to 4GB ROM
For PIC chips that have up to 64K of program memory
INHX8M format is used
INHX8S produces two separate files for odd and even
banks of program memory, so maximum 128K of ROM
can be programmed
PIC18 : INTEL HEX FILES contd.
Hex file has six parts as follows (INHX8M)
:BBAAAATTHHHHHHHHCC
PIC18 : INTEL HEX FILES contd.

Example (INHX8M)
PIC18 : INTEL HEX FILES contd.

INHX32 file has also same six parts but with different
options of TT field
:BBAAAATTHHHHHHHHCC
PIC18 : INTEL HEX FILES contd.
Example (INHX32)
PIC18 : HEX FILE LOADING
There are three ways to load the Hex File in to ROM
1. Device Burner: A separate hardware programmer is used to
burn/load the program onto PIC chip, after programming chip
is placed in actual circuit. Many third party burners available.
2. ICSP: In-Circuit Serial Programmer.
Allows programming while device
is fixed in the circuit. Microchip ICD 2
is a wonderful device for debugging
programs. Excellent for designs that
changes or update. RB6 and RB7 are
utilized. After programming these
pins can again be used as IO.
3. Boot Loader: A piece of program which
loaded in ROM and it communicates with user via serial
port, CAN, USB or even network connection. Ideal for use.

S-ar putea să vă placă și