Vous êtes sur la page 1sur 44

Microcontrollers Week3: Instructions Sets

Dwight Sabio

Christian Achievers for God and Country

Byte Oriented Operations


Byte instructions work on all 8 bits in the file. So a byte instruction would be followed by the appropriate file number.

Christian Achievers for God and Country

NOP
Uses one instruction cycle. Used for short time delays.

Christian Achievers for God and Country

MOVWF f
Moves contents of W register to another file register location. Status affected: None Example MOVWF Temp

Christian Achievers for God and Country

MOVF f,d
f d Moves contents of one file register to another. Can be used to set the Zero Status bit. Status Affected: Z Example MOVF Temp, f

Christian Achievers for God and Country

CLRF f
The contents of register f are cleared and the Z bit is set. File (f) = 00000000 Status affected: Z

Christian Achievers for God and Country

CLRW
W register is cleared. Zero bit (Z) is set. W = 00000000 Status affected: Z

Christian Achievers for God and Country

INCF f,d
f + 1 d Status affected: Z

Christian Achievers for God and Country

DECF
f - 1 d Status affected: Z

Christian Achievers for God and Country

ADDWF f, d
W + f d Adds the contents of W to a File Register Status Affected: Z

Christian Achievers for God and Country

Christian Achievers for God and Country

Christian Achievers for God and Country

ANDWF f,d
W AND f d Status Affected: Z Performs Logical AND with W and f Can be used to mask out specific bits

Christian Achievers for God and Country

IORWF f, d
W OR f d Status Affected: Z Executes Inclusive-OR with W and a File Register

Christian Achievers for God and Country

XORWF f,d
W XOR f d Status Affected: Z Executes Exclusive-OR with W and a File Register

Christian Achievers for God and Country

COMF f,d
f d Executes a ones compliment on a file register.

Christian Achievers for God and Country

RRF f, d

Christian Achievers for God and Country

RLF f,d

Christian Achievers for God and Country

SUBWF f,d
f - W d Subtracts the contents of W from a File Register Twos compliment Status affected: C, DC, Z

Christian Achievers for God and Country

DECFSZ f,d & INCFSZ f,d

Christian Achievers for God and Country

SWAPF f,d

Christian Achievers for God and Country

Bit Oriented Operations


The bit instructions act on a particular bit in a file, so the instruction would be followed by the data which specifies the file register and bit number. 1. BCF 2. BSF 3. BTFSC 4. BTFSS

Christian Achievers for God and Country

BCF f,b
Clear the bit in a file F. Status Affected: None Operands: 0 f 127 0b7
BCF PORTB, 4; bit 4 is cleared in the PORTB

PORTB bit 4 is cleared; bit 4 = 0

Christian Achievers for God and Country

BSF f,b
Set bit in file F. Status Affected: None Operands: 0 f 127 0b7
BSF PORTB, 4; bit 4 is set in the PORTB

PORTB bit 4 is set; bit 4 = 1

Christian Achievers for God and Country

BTFSC f,b
Test bit in file skip if clear. Operation: skip if (f<b>) 0 Status Affected: None Operands: 0 f 127 0b7 BTFSC STATUS, 2 This test bit 2 in STATUS Register if it is clear then the next instruction is missed. Bit 2 is the zero bit so the program jumps if the result of an instruction was zero.

Christian Achievers for God and Country

BTFSS f,b
Test bit in file skip if set. Operation: skip if (f<b>) = 1 Status Affected: None Operands: 0 f 127 0b7 BTFSS STATUS, 2 This tests bit 2 in the STATUS Register is set then the next instruction is skipped.

Christian Achievers for God and Country

Literal and Control Operations


It modify files with variables or control the movement of data from one file to another.

Christian Achievers for God and Country

ADDLW k
Add a number(literal) to W. Operation: (W) + k (W) Operands: 0 k 255

ADDLW 7 Will add 7 to W, the result is placed in W.

Christian Achievers for God and Country

ANDLW k
The contents of W are ANDed with an 8 bit number(literal). The result is placed in W. ANDLW 12H ANDLW b00010010 ANDLW .18

Christian Achievers for God and Country

CALL k
Call Subroutine CALL WAIT1MIN- This will call a routine (you have written) to wait for 1 min.

Christian Achievers for God and Country

GOTO k
This is an unconditional jump to a specified location in the program.

GOTO SIREN

Christian Achievers for God and Country

IORLW k
The contents of the W register are Ored with the file F. The result is placed in the W register. Status Affected: Z IORLW 7

Christian Achievers for God and Country

MOVLW k
The 8 bit literal is moved directly into W.

MOVLW .127 MOVLW b11101100 MOVLW 15h

Christian Achievers for God and Country

RETFIE
Return from Interrupt This instruction is used to return from an interrupt.

Christian Achievers for God and Country

RETLW k
This instruction is used at the end of a subroutine to return to the program following a CALL instruction. The literal value is placed in the W register. This instruction can also be used with a look up table.

RETLW 0

Christian Achievers for God and Country

RETURN
This instruction is used to return from a subroutine.

Christian Achievers for God and Country

SUBLW k
The contents of the W register are subtracted from a number. Operation: k (W) (W)

Christian Achievers for God and Country

XORLW k
The contents of the W register are Exclusive Ored with the literal. If a number of the input port, indicating temperature, is the same as the literal then the result is zero and the zero bit is set. XORLW 67

Christian Achievers for God and Country

CLRWDT
The watchdog timer is cleared. The watchdog is a safety device in the microcontroller if the program crashes the watchdog timer times out then restarts the program. Status affected: TO, PD

Christian Achievers for God and Country

SLEEP
When executing this instruction the chip is put into sleep mode. The power-down status bit (PD) is cleared, the time-out status bit is set, the watchdog timer and its prescaler is cleared and the oscillator driver is turned off. The watchdog timer still keeps running form its own internal clock. Status affected TO, PD

Seatwork 1- Prelims

Christian Achievers for God and Country

Assume: f. CLRW g. COMF ALPHA,d W = 53h h. DECF BETA k = 26h i. INCF TEMP TEMP = BAh j. IORLW k ALPHA = 3Eh BETA = b11111001 k. IORWF BETA, w Find the result & indicate the l. MOVF ALPHA, 0 value of the C, DC & Z bit a. ADDWF TEMP, 1 m. RLF BETA, 1 n. SUBLW k b. ADDLW k o. SUBWF BETA c. ANDLW k d. ANDWF ALPHA e. CLRF TEMP

Christian Achievers for God and Country

42

Christian Achievers for God and Country

43

Christian Achievers for God and Country

44

Vous aimerez peut-être aussi