Professional Documents
Culture Documents
ME - Micro - L1 - The PIC18F Microcontrollers - Architecture and Assembly Language Programming - VF - Eng
ME - Micro - L1 - The PIC18F Microcontrollers - Architecture and Assembly Language Programming - VF - Eng
1
What is a Microprocessor?
Microprocessor is a computer Central Processing Unit (CPU) on a
single chip.
‒ It contains millions of transistors connected by wires.
Tasks that need to have high deterministic update rates are coded
using the native assembly language for a particular microcontroller.
Program Memory
Program Bus
PIC18F448/458
Introduction to Embedded Systems Design using PIC18F – L1 11
Internal Architecture of PIC18 Data Bus
PIC18F448/458
Introduction to Embedded Systems Design using PIC18F – L1 12
Some features of the PIC18F458
Operating frequency: DC – 40 MHz
Program Memory: 32 Kbytes
Data Memory: 1536 Bytes
Data EEPROM: 256 Bytes
I/O Ports: 5 (A, B, C, D, E)
Timers: 4
Serial Communication: USART
10-bit ADC: 8 input channels
Instruction Set: 75 instructions
TRISB 1 0 0 1 0 0 1 1
‒ After the addition, register WREG contains 00 and the flags are as follows:
• C = 1 because there is a carry out from D7.
• Z = 1 because the result in WREG is zero.
• DC = 1 because there is a carry from D3 to D4.
k: constant
ff = 00 → FSR0 = k
ff = 01 → FSR1 = k
ff = 10 → FSR2 = k
LFSR f, k ;FSR(f) = k
MOVLB k ;BSR = k
MULLW k ;PROD = WREG * k
f: RAM address
opcode
Affected flags
Destination:
d = 0, dest = WREG RAM address
d = 1, dest = f If f = INDFx then address = FSRx
Bank: else, address = f
a = 0, bank 0
a = 1, bank BSR
DECF f, d ;dest = f - 1
DECFSZ f, d ;dest = f - 1, skip next inst if 0
DCFSNZ f, d ;dest = f - 1, skip next inst if not 0
INCF f, d ;dest = f + 1
INCFSZ f, d ;dest = f + 1, skip next inst if 0
INFSNZ f, d ;dest = f + 1, skip next inst if not 0
MOVF f, d ;dest = f
MOVWF f ;f = WREG
CLRF f ;f = 0x00
SETF f ;f = 0xFF
;location 6 = (8D)
;location 7 = (3B)
‒ Notice the use of ADDWF for the lower byte and ADDWFC for the higher byte.
0x268 0x5F
0x48
10
RB2 = 0 → RB2 = 1
RB2 = 1 → RB2 = 0
Direct
Access bank Addressing
CLRF 0x68, 0
Mode
in the
RAM address: 0x048 access bank
a = 0, access bank
0x068 0x00
0x48 0x068
BSR f
0x02 0x48
‒ Note: This table shows the syntax for the CLRF instruction, it works for all such
instructions.
Introduction to Embedded Systems Design using PIC18F – L1 67
Auto-increment option for FSR
The auto-decrement or auto-increment affects the entire 12 bits of
the FSRn and has no effect on status register.
‒ This means that FSR0 going from FFF to 000 will not raise any flag.
• LFSR FSR1,0x0120
• LFSR FSR2,0x0150
• MOVFF POSTINC1, POSTINC2
Z, the z flag
‒ The zero flag reflects the result of an arithmetic or logic operation
‒ If the result is zero, then Z = 1, otherwise Z = 0;
‒ Hex numbers: Ex. 99H, 99h, 0x99, 0X99, 99, H’99’ or h’99’
• If the value starts with the hex digits A-F, then it must be preceded with a zero: Ex. 0FEH
EQU (equate)
‒ This is used to define a constant value or a fixed address.
‒ The EQU directive associates a constant number with a data or an address
label so that when the label appears in the program, its constant will be
substituted for the label.
ORG (origin)
‒ The ORG directive is used to indicate the beginning of the address. It can be
used for both code and data. The number that comes after ORG must be in
hex.
LIST directive
‒ The LIST directive is unique to the PIC assembler. It indicates to the assembler
the specific PIC chip for which the program should be assembled.
#include directive
‒ The #include directive tells the PIC assembler to use the libraries associated
with the specific chip for which we are compiling the program.
90
Addition of unsigned numbers
Example: show how the flag register is affected by the following instructions.
‒ After the addition, register WREG contains 00 and the flags are as follows:
• C = 1 because there is a carry out from D7.
• Z = 1 because the result in WREG is zero.
• DC = 1 because there is a carry from D3 to D4.
‒ Example:
‒ Example 1:
‒ Example 2:
‒ Notice that When the second parameter is not stated, it is assumed to be fileReg (F)
The NOP will introduce a bubble into the pipeline to remove data
dependency due to RAW.
‒ The N flag is D7 of the result. If N = 0, the sum is positive (+) and if N = 1, then
the sum is negative.
There are also the BOV and BNOV instructions for the OV flag that
allow us to correct the signed number error.