Файл: PICmicro MCU C - An itroduction to programming The Microchip PIC in CCS C (N.Gardner, 2002).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 1087

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

iTable pointer control;

i = 0 Do not change, i = 1 increment after instruction execution.

PIC16CXX

Literal and Control Operations

Hex

Mnemonic

Description

Function

3Ekk

ADDLW

K Add literal to W

k + W >> W

39kk

ANDLW

k AND literal and W

k .AND. W >> W

2kkk

CALL

k

Call subroutine

PC+1 >> TOS, k >> PC

0064

CLRWDT

Clear watchdog timer

0 >> WDT (and Prescaler,

If assigned)

2kkk

GOTO

k Goto address(k is 9 bits)

k >> PC(9 bits)

38kk

IORLW

k Incl. OR literal and W

k .OR. W >> W

30kk

MOVLW

k Move literal to W

k >> W

0009

RETFIE

Return from Interrupt

TOS >> PC, 1 >> GIE

34kk

RETLW

k Return with literal in W

k >> W, TOS P >> C

0008

RETURN

Return from subroutine

TOS >> PC

0063

SLEEP

Go into Standby Mode

0 >> WDT, stop oscillator

3Ckk

SUBLW

k Subtract W from literal

k – W >> W

3Akk

XORLW

k Exclusive OR literal and W

k .XOR. W >> W

Byte Oriented Instructions

Hex

Mnemonic

Description

Function

07Ff

ADDWF

f, d

Add W and f

W + f >> d

05Ff

ANDWF

f, d

AND W and f

W .AND. f >> d

018F

CLRF

f

Clear f

0 >> f

0100

CLRW

Clear W

0 >> W

09Ff

COMF

f, d

Complement f

.NOT. f >> d

03Ff

DECF

f, d

Decrement f

f – 1 >> d

0BFf

DECFSZ

f, d

Decrement f, skip if zero f – 1 >> d, skip if 0

0AFf

INCF

f, d

Increment f

f + 1 >> d

0FFf

INCFSZ

f, d

Increment f, skip if 0

f + 1 >> d, skip if 0

04Ff

IORWF

f, d

Inclusive OR W and f

W .OR. f >> d

08Ff

MOVF

f, d

Move f

f >> d

008F

MOVWF

f

Move W to f

W >> f

0000

NOP

No operation

0DFf

RLF

f, d

Rotate left f

0CFf

RRF

f, d

Rotate right f

02Ff

SUBWF

f, d

Subtract W from f

f – W >> d

0EFf

SWAPF

f, d

Swap halves f

f(0:3) << f(4:7) >> d

06Ff

XORWF

f, d

Exclusive OR W and f

W .XOR. f >> d

Bit Oriented Instructions

110


Hex

Mnemonic

Description

Function

10Ff

BCF

f, b

Bit clear f

0 >> f(b)

14Ff

BSF

f, b

Bit set f

1 >> f(b)

18Ff

BTFSC

f, b

Bit test, skip if clear

skip if f(b) = 0

1CFf

BTFSS

f, b

Bit test, skip if set

skip if f(b) = 1

PIC16C5X

Literal and Control Operations

Hex

Mnemonic

Description

Function

Ekk

ANDLW

k AND literal and W

k .AND. W >> W

9kk

CALL

k

Call subroutine

PC+1 >> TOS, k >> PC

004

CLRWDT

Clear watchdog timer

0 >> WDT (and Prescaler,

If assigned)

Akk

GOTO

k Goto address(k is 9 bits)

k >> PC(9 bits)

Dkk

IORLW

k Incl. OR literal and W

k .OR. W >> W

Ckk

MOVLW

k Move literal to W

k >> W

002

OPTION

Load OPTION Register

W >> OPTION Register

8kk

RETLW

k Return with literal in W

k >> W, TOS P >> C

003

SLEEP

Go into Standby Mode

0 >> WDT, stop oscillator

00f

TRIS

f

Tri-state port f

W >> I/O control register

f

Fkk

XORLW

k Exclusive OR literal and W

k .XOR. W >> W

Byte Oriented Instructions

Hex

Mnemonic

Description

Function

1Cf

ADDWF

f, d

Add W and f

W + f >> d

14f

ANDWF

f, d

AND W and f

W .AND. f >> d

06f

CLRF

f

Clear f

0 >> f

040

CLRW

Clear W

0 >> W

24f

COMF

f, d

Complement f

.NOT. f >> d

0Cf

DECF

f, d

Decrement f

f – 1 >> d

2Cf

DECFSZ

f, d

Decrement f, skip if zero f – 1 >> d, skip if 0

28f

INCF

f, d

Increment f

f + 1 >> d

3Cf

INCFSZ

f, d

Increment f, skip if 0

f + 1 >> d, skip if 0

10f

IORWF

f, d

Inclusive OR W and f

W .OR. f >> d

20f

MOVF

f, d

Move f

f >> d

02f

MOVWF

f

Move W to f

W >> f

000

NOP

No operation

34f

RLF

f, d

Rotate left f

30f

RRF

f, d

Rotate right f

08f

SUBWF

f, d

Subtract W from f

f – W >> d

38f

SWAPF

f, d

Swap halves f

f(0:3) << f(4:7) >> d

18f

XORWF

f, d

Exclusive OR W and f

W .XOR. f >> d

111


Bit Oriented Instructions

Hex

Mnemonic

Description

Function

4bf

BCF

f, b

Bit clear f

0 >> f(b)

5bf

BSF

f, b

Bit set f

1 >> f(b)

6bf

BTFSC

f, b

Bit test, skip if clear

skip if f(b) = 0

7bf

BTFSS

f, b

Bit test, skip if set

skip if f(b) = 1

PIC16C5X/PIC16CXX

Special Instruction Mnemonics

These instructions are recognized be the Assembler and substituted in the program listing. They are form of shorthand similar to Macros.

Mnemonic

Description

Assembly Code

Flag

ADDCF

f, d Add Digit Carry to File

BTFSC

Status, Carry

INCF

f, d

Z

B

k

Branch

GOTO

k

BC

k

Branch on Carry

BTFSC

Status, Carry

GOTO

k

BDC

k Branch on Digit Carry

BTFSC

Status, Digit Carry

GOTO

k

BNC

k Branch on No Carry

BTFSS

Status, Carry

GOTO

k

BNDC

k Branch on No Digit Carry

BTFSS

Status, Digit Carry

GOTO

k

BZ

k

Branch on Zero

BTFSC

Status, Zero

GOTO

k

BNZ

k Branch on No Zero

BTFSS

Status, Zero

GOTO

k

CLRC

Clear Carry

BCF

Status, Carry

CLRDC

Clear Digit Carry

BCF

Status, Digit Carry

CLRZ

Clear Zero

BCF

Status, Zero

MOVWF

k Move File to W

MOVF

f, W

Z

NEGF

f ,d Negative File

COMF

f, f

INCF

f, d

Z

SETO

Set Carry

BSF

Status, Carry

SETDC

Set Digit Carry

BSF

Status, Digit Carry

SETZ

Set Zero

BSF

Status, Zero

SKPC

Skip on Carry

BTFSS

Status, Carry

SKPNC

Skip on No Carry

BTFSC

Status, Carry

SKPDC

Skip on Digit Carry

BTFSS

Status, Digit Carry

SKPNDC

Skip on No Digit Carry

BTFSC

Status, Digit Carry

SKPZ

Skip on Zero

BTFSS

Status, Zero

SKPNZ

Skip on No Zero

BTFSC

Status, Zero

SUBCF

f, d Subtract Carry from File

BTFSC

Status, Carry

112


DECF

f, d

Z

SUBDCF

f, d Sub Digit Carry from File

BTFSC

Status, Digit Carry

DECF

f, d

Z

TSTF

f Test File

MOVF

f, f

Z

9.3Advanced BIT Manipulation

The CCS C compiler has a number of bit manipulation functions that are commonly needed for PICmicro®MCU programs

bit_set, bit_clear and bit_test simply set or clear a bit in a variable or test the state of a single bit. Bits are numbered with the lowest bit (the 1 position) as 0 and the highest bit 7.

For example:

c=’A’;

//c

in

binary is now 01000001

bit_test(c,5);

//c

is

now 01100001 or ‘a’

if(bit_test(x,0)) printf(“X is odd”);

else

printf(“X is even”);

shift_lest and shift_right will shift one bit position through any number of bytes. In addition, it allows you to specify the bit value to put into the vacated bit position. These functions return as their value 0 or 1 representing the bit shifts out. Note, these functions consider the lowest byte in memory the LSB. The second parameter is the number of bytes and the last parameter is the new bit.

Example:

int x[3] = {0b10010001, 0b00011100, 0b10000001};

short bb;

//x msb first is: 10000001, 00011100,

10010001

bb= shift_left(x,sizeof(x),0);

//x msb first is: 00000010, 00111001,

00100010

//bb is 1

bb= shift_left(x,sizeof(x),1);

//x msb first is: 00000100, 01110010,

01000101

//bb is 0

Note: The first parameter is a pointer. In this case, since x is an array the unsubscripted identifier is a pointer. If a simple variable or structure was used, the & operator must be added. For example:

long y;

struct { int a,b,c} z; shitf_left(&y,2,0);

113