Lecture 3 1 2 Status Register The STATUS

  • Slides: 29
Download presentation
Lecture 3 1

Lecture 3 1

2

2

Status Register • The STATUS register contains – Arithmetic status of the ALU –

Status Register • The STATUS register contains – Arithmetic status of the ALU – RESET status – Bank select bit for data memory. • As with any register, the STATUS register can be the destination for any instruction. 3

4

4

Status Register • Z, DC, C, TO and PD bits are not writable. –

Status Register • Z, DC, C, TO and PD bits are not writable. – These bits are set or cleared according to device logic. • For example, CLRF STATUS will clear the upper-three bits and set the Z bit. This leaves the STATUS register as 000 u u 1 uu (where u = unchanged). • Only the BCF, BSF, SWAPF and MOVWF instructions should be used to alter the STATUS register because these instructions do not affect any status bit. 5

PIC Instruction Set • The instruction set for the PIC 16 F 84 consists

PIC Instruction Set • The instruction set for the PIC 16 F 84 consists of 35 single word instructions • These are grouped into three major categories – Byte-oriented – Bit-oriented – Literal and control 6

7

7

List and Equates • Before writing your program, you need to describe the type

List and Equates • Before writing your program, you need to describe the type of device that the program is to be burned to List p=16 F 84 • Equate – Similar to variable declaration in other programming languages. – Labels are assigned to addresses. Later, whenever that label is referred to in the program, the compiler looks up its address. • E. g. Assigns ‘port. B’ to the file register located at 0 x 06. Port B is always located at this file register. port. B equ 0 x 06 8

Sample Program LIST P=16 F 84 PORTB equ 0 x 06 TRISB equ 0

Sample Program LIST P=16 F 84 PORTB equ 0 x 06 TRISB equ 0 x 06 STATUS equ 0 x 03 RP 0 equ 0 x 05 org 0 movlw 0 x 0 FD movwf PORTB bsf STATUS, RP 0 bcf TRISB 0 x 080, 1 bcf TRISB 0 x 080, 2 movlw 0 x 07 F 9

 • Each instruction is a 14 -bit word divided into: • An OPCODE

• Each instruction is a 14 -bit word divided into: • An OPCODE which specifies the instruction type • One or more operands which further specify the operation of the instruction. 10

Field Description 11

Field Description 11

CLRF 12

CLRF 12

CLRW 13

CLRW 13

ADDLW 14

ADDLW 14

ADDWF 15

ADDWF 15

MOVLW 16

MOVLW 16

MOVF 17

MOVF 17

MOVWF 18

MOVWF 18

Exercise • Write a program to clear W and Port B, then add 0

Exercise • Write a program to clear W and Port B, then add 0 x 0 A to 0 x 0 B and send it out thru Port B. 19

CALL 20

CALL 20

GOTO 21

GOTO 21

Example for CALL and GOTO list p=16 F 84 goto Main ; Subroutine Delay

Example for CALL and GOTO list p=16 F 84 goto Main ; Subroutine Delay movlw 0 xff movwf 0 x 0 c L 1 nop decfsz 0 x 0 c, 1 goto L 1 return ; Main program Main movlw 0 x 0 tris porta tris portb movlw 0 xff movwf portb call Delay 22

Exercise • Write a subroutine to clear Port. B and send data in W

Exercise • Write a subroutine to clear Port. B and send data in W to Port. B • Write a program to add 0 x. A to 0 x. B and send it to Port. B (use the subroutine) 23

INCF 24

INCF 24

DECF 25

DECF 25

INCFSZ 26

INCFSZ 26

DECFSZ 27

DECFSZ 27

NOP 28

NOP 28

Exercise • Write a subroutine to delay for 1 msec, given that your input

Exercise • Write a subroutine to delay for 1 msec, given that your input clock is 4 MHz 29