1 / 29

Lecture 3

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.

hisa
Télécharger la présentation

Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3

  2. 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. 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.

  4. 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

  5. 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

  6. 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

  7. 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.

  8. Field Description

  9. CLRF

  10. CLRW

  11. ADDLW

  12. ADDWF

  13. MOVLW

  14. MOVF

  15. MOVWF

  16. Exercise • Write a program to clear W and Port B, then add 0x0A to 0x0B and send it out thru Port B.

  17. CALL

  18. GOTO

  19. 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

  20. 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)

  21. INCF

  22. DECF

  23. INCFSZ

  24. DECFSZ

  25. NOP

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

More Related