You are on page 1of 24

Advanced PIC Micro-controller

Programming
Lecture 3
First Microcontrollers
IBM started using Intel processors in its PC
Intel started its 8042 and 8048 (8-bit
microcontroller) using in printers
Apple Macintosh used Motorola
1980 Intel abandoned microcontroller business
By 1989 Microchip was a major player in
designing microcontrollers
PIC: Peripheral Interface Controller
Microcontroller Unit (MCU)
Block Diagram

An integrated electronic computing and logic device that


includes three major components on a single chip
Microprocessor
Memory
I/O ports

Includes support devices


Timers
A/D converter
Serial I/O
Parallel Slave Port

All components connected by common communication


lines called the system bus.
MCU Architecture
RISC (Harvard)
Reduced instruction set computer
Simple operations
Simple addressing modes
Longer compiled program bust faster to
execute
Uses pipelining
CISC (Von Neuman)
Complex instruction set computer
More complex instructions (closer to high-
level language support)
Main 8-bit Controllers
Microchip
RISC architecture (reduced instruction set computer)
Has sold over 2 billion as of 2002
Cost effective and rich in peripherals
Motorola
CISC architecture
Has hundreds of instructions
Examples: 68HC05, 68HC08, 68HC11
Intel
CISC architecture
Has hundreds of instructions
Examples: 8051, 8052
Many difference manufacturers: Philips, Dallas/MAXIM Semiconductor, etc.
Atmel
RISC architecture (reduced instruction set computer)
Cost effective and rich in peripherals
AVR
Harvard Architecture
Von Neumann
Architecture
Von Neumann Architecture:
Fetches instructions and data
from a single memory space
Limits operating bandwidth
8-bit Bus Program
& Data
Memory
CPU Harvard Architecture:
Harvard
Architecture Uses two separate memory
spaces for program
instructions and data
8-bit Bus Data
Memory
Improved operating bandwidth

16-bit Bus
CPU Allows for different bus widths

Program
Memory
PIC18F Microcontroller Families
PIC microcontrollers are designed using
the Harvard Architecture which includes:
Microprocessor unit (MPU)
Program memory for instructions
Data memory for data
I/O ports
Support devices such as timers
Microcontroller with
the Harvard Architecture
The PIC18F4520 Microcontroller

10
PIC18F4520 Basic Component

32KB Program ROM


1536 bytes of data RAM
32 I/O pins.
256 bytes of EEPROM
4 Timers
One serial interface
8 channel, 10 bit ADC

11
Block Diagram

Stack
RAM EEPROM
Program
ROM PC
Program Data
Bus Bus
CPU

Interrupt Other
Control OSC Timers Ports
Logic Peripherals

12
MPLAB IDE
&
MCC18
Flowcharting
Flowchart
A graphical
representation of
processes (tasks) to be
performed and the
sequence to be followed
in solving computational
problem
Writing Assembly Programs /
and IDE Structure
M:/Microchip/Project1/proj_name.mcp
Create a Project M:/Microchip/Project2/proj_name.mcp Analyze the problem
...etc.
(understand it and
simplify if possible)

Source Code containing mnemonics:


Build M:/Microchip/Project1/code_name.asm
Editing
All
M:/Microchip/Project2/code_name.asm
...etc.
*.asm File Draw a flowchart!

Assembling
*.lst (list) File *.err (Error) File

*.O (Object) File Write the source


code using
mnemonics
Linking

*.COD
*.HEX
Execute and debug
Known as MPLAB SIM your code
Simulation Uses a simulator on the PC to
execute the program
Not real-time execution

Allows tracing the logical/functional


Debugger errors
File Structure in IDE
Project_name.mcp
New project
Project_name.mcw
Project_name.mcs
Code listing
code_listing.asm
Error File (.err)
Error[113] C:\MCC18\CLASS_PROJECT\ADDCARY.ASM 9 : Symbol not
previously defined (START)
Error[122] C:\MCC18\CLASS_PROJECT\ADDCARY.ASM 11 : Illegal
opcode (MOViLW)
Warning[207] C:\MCC18\CLASS_PROJECT\ADDCARY.ASM 17 : Found
label after column 1. (MOiVLW)
Error[108] C:\MCC18\CLASS_PROJECT\ADDCARY.ASM 17 : Illegal
character (0)

Line Number which has an


error. Read the error and
correct it.
List file (*.lst)
000000 EF10 F000 00009 GOTO START MEMORY USAGE MAP ('X' = Used, '-' = Unused)
000020 00010 ORG 0020H
000020 0EF2 00011 START: MOVLW BYTE1 0000 : XXXX------------ ---------------- XXXXXXXXXXXXXXXX XX--------------
000022 6E00 00012 MOVWF REG0,0
000024 0E32 00013 MOVLW BYTE2 All other memory blocks unused.
000026 6E01 00014 MOVWF REG1,0
000028 2400 00015 ADDWF REG0,0,0 Program Memory Bytes Used: 22
00002A E301 00016 BNC SAVE Program Memory Bytes Free: 32746
00002C 0E00 00017 MOVLW 0x00
00002E 6E02 00018 SAVE: MOVWF REG2,0
000030 0003 00019 SLEEP Errors : 0
00020 END Warnings : 0 reported, 0 suppressed

MPASM 5.12 ADDCARY.ASM 2-26-2008 20:03:03


PAGE 2

SYMBOL TABLE
LABEL VALUE

BYTE1 000000F2
BYTE2
REG0
00000032
00000000
Identifies all memory
REG1
REG2
00000001
00000002
locations and opcodes in
SAVE
START
0000002E
00000020
the source code
__18F452 00000001

Messages : 0 reported, 0 suppressed


Memory
Address List file (*.lst)
000000 EF10 F000 00009 GOTO START MEMORY USAGE MAP ('X' = Used, '-' = Unused)
000020 00010 ORG 0020H
000020 0EF2 00011 START: MOVLW BYTE1 0000 : XXXX------------ ---------------- XXXXXXXXXXXXXXXX XX--------------
000022 6E00 00012 MOVWF REG0,0
000024 0E32 00013 MOVLW BYTE2 All other memory blocks unused.
000026 6E01 00014 MOVWF REG1,0
000028 2400 00015 ADDWF REG0,0,0 Program Memory Bytes Used: 22
00002A E301 00016 BNC SAVE Program Memory Bytes Free: 32746
00002C 0E00 00017 MOVLW 0x00
00002E 6E02 00018 SAVE: MOVWF REG2,0
000030 0003 00019 SLEEP Errors : 0
00020 END Warnings : 0 reported, 0 suppressed

MPASM 5.12 ADDCARY.ASM 2-26-2008 20:03:03


PAGE 2 Sequential
SYMBOL TABLE
Line numbers
LABEL VALUE

BYTE1 000000F2
BYTE2
REG0
00000032
00000000
Identifies all memory
REG1
REG2
00000001
00000002
locations and opcodes in
SAVE
START
0000002E
00000020
the source code
__18F452 00000001

Messages : opcode
0 reported,
0 suppressed
Hex Code (*.HEX)
:020000040000FA
:0400000010EF00F00D
:10002000F20E006E320E016E002401E3000E026E2D
:020030000300CB
:00000001FF
Viewing Your Code

PROG MEMORY
PROG CODE
STRUCTURE

EEPROM

WATCH
Programming Steps
Simpler Assembler Process
Link Process