Sie sind auf Seite 1von 22

1

Introduction The PIC 18 Series Instruction Set Byte-oriented file register operations Bit-oriented file register operations Literal and control operations Instruction Formats Operation Types MPASM Assembler Example
2

Micro-controller Programming Options:


1.

2.

3.

Machine Code 00 0111 0001 0101 Assembly Language: needs an assembler addwf NUM, w High-Level Language: needs a compiler for (i=0; i<10; i++) sum += a[i];

77 instructions Three Groups:


1. Byte-oriented file register operations 2. Bit-oriented file register operations 3. Literal and control operations

Operation Types:
Arithmetic Data movement Misc Logic Control

Format: op f, d
op: operation f: number of file or register d: destination (0: working register, 1: file register)

Example: addwf PORTA, 0 Adds the contents of the working register and register PORTA, puts the result in the working register.

Format: op f, b
op: operation f: number of file or register b: bit number, 0 through 7

Example: bsf STATUS, 5 Sets to 1 Bit 5 of register STATUS.

Format: op k
op: operation k: literal, an 8-bit if data or 11-bit if address

Examples: addlw 5 Adds to the working register the value 5. call 9 Calls the subroutine at address 9.

10

Mnemonic Operands ADDWF f, d

Description Add W and f

Cycles 1

Status Affected C,DC,Z

COMF
DECF INCF SUBWF ADDLW SUBLW

f, d
f, d f, d f, d k k

Complement f
Decrement f Increment f Subtract W from f Add literal and W Subtract W from literal

1
1 1 1 1 1

Z
Z Z C,DC,Z C,DC,Z C,DC,Z

11

Mnemonic Operands
ANDWF IORWF XORWF f, d f, d f, d

Description
AND W with f Inclusive OR W with f Exclusive OR W with f

Cycles
1 1 1

Status Affected
Z Z Z

ANDLW
IORLW XORLW

k
k k

AND literal with W


Inclusive OR literal with W Exclusive OR literal with W

1
1 1

Z
Z Z

12

Mnemonic Operands MOVF MOVWF f, d f

Description Move f Move W to f

Cycles 1 1

Status Affected Z

SWAPF
MOVLW

f, d
k

Swap nibbles in f
Move literal to W

1
1

13

Mnemonic Operands DECFSZ INCFSZ BTFSC BTFSS CALL GOTO RETFIE RETLW RETURN f, d f, d f, b f, b k k k -

Description Decrement f, Skip if 0 Increment f, Skip if 0 Bit Test f, Skip if Clear Bit Test f, Skip if Set Call subroutine Go to address Return from interrupt Return with literal in W Return from Subroutine

Cycles 1 (2) 1 (2) 1 (2) 1 (2) 2 2 2 2 2

Status Affected

14

Mnemonic Operands CLRF CLRW NOP RLF


RRF BCF BSF CLRWDT SLEEP

Description Clear f Clear W No Operation Rotate Left f through Carry Rotate Right f through Carry Bit Clear f Bit Set f Clear Watchdog Timer Go into standby mode

Cycles 1 1 1 1
1 1 1 1 1

f f, d
f, d f, b f, b -

Status Affected Z Z C C

TO',PD' TO',PD'
15

16

Assembler directive list #include org equ end

Summary of action Implement a listing option Include additional source file Set program origin Define an assembly constant; this allows us to assign a value to a label End program block
17

Radix

Example

Decimal
Hexadecimal

D255
H8d or 0x8d

Octal
Binary ASCII

O574
B01011100 G or AG

18

;*************************************************** ;This program moves push button switch values from ;Port A to the leds on Port B ;*************************************************** ; ;Configuration Word: WDT off, power-up timer on, ; code protect off, RC oscillator ; list p=18F4550

19

; ;specify SFRs status equ porta equ trisa equ portb equ trisb equ ;

03 05 05 06 06

20

; org 00 ;Initialise start bsf status,5 ;select memory bank 1 movlw B00011000 movwf trisa ;set port A direction movlw 00 movwf trisb ;all port B bits output bcf status,5 ;select bank 0

21

; ;The "main" program starts here clrf porta ;clear all bits in ports A loop movf porta,0 ;move port A to W register movwf portb ;move W register to port B goto loop end

22

Das könnte Ihnen auch gefallen