290 likes | 581 Vues
Lecture 3. 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. Status Register. Z, DC, C, TO and PD bits are not writable.
E N D
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.
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 000u u1uu (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.
PIC Instruction Set • The instruction set for the PIC16F84 consists of 35 single word instructions • These are grouped into three major categories • Byte-oriented • Bit-oriented • Literal and control
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=16F84 • 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 ‘portB’ to the file register located at 0x06. Port B is always located at this file register. portB equ 0x06
Sample Program LIST P=16F84 PORTB equ 0x06 TRISB equ 0x06 STATUS equ 0x03 RP0 equ 0x05 org 0 movlw 0x0FD movwf PORTB bsf STATUS, RP0 bcf TRISB 0x080, 1 bcf TRISB 0x080, 2 movlw 0x07F
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.
Exercise • Write a program to clear W and Port B, then add 0x0A to 0x0B and send it out thru Port B.
Example for CALL and GOTO list p=16F84 goto Main ; Subroutine Delay movlw 0xff movwf 0x0c L1 nop decfsz 0x0c,1 goto L1 return ; Main program Main movlw 0x0 tris porta tris portb movlw 0xff movwf portb call Delay
Exercise • Write a subroutine to clear PortB and send data in W to PortB • Write a program to add 0xA to 0xB and send it to PortB (use the subroutine)
Exercise • Write a subroutine to delay for 1 msec, given that your input clock is 4 MHz