Meet The PIC!
Meet The PIC!
CpE 511
MICROPROCESSOR SYSTEM
Jeannalen P. Lunod
Instructor I
Department of Computer Engineering
Introduction to Microprocessors
A microprocessor is a programmable logic device with a
designed set of instructions.
Microcontrollers
Processor specifically designed for
control applications.
Microprocessors
DSPs
DSPs
Processors specifically designed for
digital signal processing.
Microprocessors
Processors for general purpose
processing.
Microcontrollers
Maximum clock
operating frequency is
about 20 MHz
Memory capacity is
about 1K to 14K words.
BLOCK DIAGRAM
RAM
Memory used by a program to store
temporary data during its execution.
Pin Diagram
INSTRUCTION SET
3 basic categories
Byte-oriented instructions
Bit-oriented instructions
Literal and control operations
BYTE-ORIENTED INSTRUCTIONS
Ex: movf f,d
BIT-ORIENTED INSTRUCTIONS
Ex: btfsc f,b
b represents a bit field designator which
selects the number of the bit affected by
the operation
f represents the address of the file in
which the bit is located
d = 0 for destination w
d = 1 for destination f
f = 7-bit file register address
CLRF f Clear f
CLRW Clear w
W register is cleared.
Zero bit (z) is set.
Decrement register f.
If d is 0, the result is stored in the w register.
If d is 1, the result is stored back in register f.
MOVWF f Move w to f
NOP No operation
RLF f,d Rotate left f through carry
The contents of register f are rotated one bit to the left
through the carry flag.
If d is 0, the result is placed in the w register.
If d is 1, the result is stored back in register f.
BTFSC f,b
The contents of the w register are added to the 8-bit literal k and the
result is placed in the w register.
CALL k
Call Subroutine
Call subroutine.
First, return address (PC + 1) is pushed onto the stack.
The 11-bit immediate address is loaded into PC bits.
The upper bits of the PC are loaded from PCLATH, CALL is a 2-cycle
instruction.
Is an unconditional branch.
The eleven-bit immediate value is loaded into PC bits.
The upper bits of PS are loaded from PCLATH.
The contents of the w register are ORed with the eight bit literal k.
The result is placed in the w register.
SLEEP
RETFIE
RETLW k
Port Read
2. Port Read/Write
tris
1. movf
2. btfss
btfsc
porta,3
portb,1
to w reg.
; bit 3 of port A Hi?
; bit 1 of port B Lo?
Port Write
1. Bsf portb,5
bcf porta,2
DATA TRANSFER
1. movf portb,w
movwf
hold
2. movlw 0x00
tris portb
movlw
0x0f
movwf
portb
BIT MANIPULATION
Example:
porta
equ
portb
equ
org
main
movlw
tris
movlw
tris
clrf
movf
movwf
circle
goto
end
0x05
0x06
0x000
0xff
porta
0x00
portb
portb
porta,w
portb
circle
RUNNING LIGHTS
1. Sequencing (rlf or rrf)
Example:
start movlw
0xff
tris porta
movlw
b11111110
tris portb
bcf portb,0
switchbtfss porta,2
goto switch
bsf portb,0
circle goto circle
end
Example :
status
portb equ
shift
ncount
mcount
c
start
get_bit
equ
0x06
equ
equ
equ
equ
org
movlw
tris
clrf
bcf
movlw
movwf
movf
movwf
call
2. Data Transfer
0x03
0x0c
0x0d
0x0e
0
0c000
0x00
portb
portb
status,c
b01001001
shift
shift,w
portb
pause
rlf
goto
pause movlw
movwf
loadn movlw
movwf
decn decfsz
goto
decfsz
goto
end
shift,f
get_bit
0xff
mcount
0xff
ncount
ncount,f
decn
mcount,f
loadn
Example:
main
movlw
movwf
call
movlw
call
.
.
.
b00000011
portb
delay
b00001100
delay
My First Program:
; Turns on a LED connected to B0.
3. Bit Manipulation
Example
bsf
call
clrf
call
bsf
portb,0
delay
portb
; or bcf portb,0
delay
portb,1
.
.
.
processor 16f84
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
; Program
org
; start at address 0
movlw B00000000
tris
PORTB
; w := binary 00000000
; copy w to port B control reg
movlw B00000001
movwf PORTB
; w := binary 00000001
; copy w to port B itself
fin:
goto
end
fin
; program ends here
org 0 the last pseudo instruction, which means, The next instruction should go at address 0 in program
memory. That is, youre telling the assembler where to start.
CLOCK OSCILLATOR
movlw
tris
movlw
movwf
fin: goto
B00000000
PORTB
B00000001
PORTB
fin
1.
2.
3.
4.
PROGRAM FORMAT
LABELS
Standard header
Equates
Program
end
RULES
All labels must start in the first position in column 1
Labels must begin with an alpha character or an
under bar
Labels may contain alphanumeric characters, the
under bar and the question mark
Labels may up to 31 characters long
Labels are case sensitive by default
LITERALS
are constants or numbers, usually hexadecimal
numbers
defined using the movlw and some logic and
arithmetic instructions
start movlw 0x00
start label
movlw instruction
00 literal (constant)
EQUATES
An equate statement may serve to assign a label to a specific
address in the PIC16 designated by a hexadecimal number
portb equ 0x06
port b label
equ tells assembler this is an equate
0x means hexadecimal
06 hexadecimal address
10
END
An END statement is used to tell the assembler it
has reached the end of the program
11