1 / 17

MicroChip 2

MicroChip 2. UNCA ECE 406 April 18, 2007. Indirect register access. FSR register Register 04h A pointer to another register INDF Register 00h Value of the target register Setting FSR to INDF is possible But a little silly. Array access problem. Suppose 43h has the address of array A

huyen
Download Presentation

MicroChip 2

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. MicroChip 2 UNCA ECE 406 April 18, 2007

  2. Indirect register access • FSR register • Register 04h • A pointer to another register • INDF • Register 00h • Value of the target register • Setting FSR to INDF is possible • But a little silly

  3. Array access problem • Suppose 43h has the address of array A • And 57h has an index I • How does you • A[I] = A[I] + 15 • This is useful only with many registers • And necessary if you can’t address all those file registers directly from an instruction

  4. Array access solution MOVLW 43h ; W = &A[0] ADDWF 57h,W ; W = &A[I] MOVWF FRS ; FRS = &A[I] MOVF INDF,W ; W = A[I] ADDLW 15 ; W = A[I]+15 MOVF INDF,F ; A[I] = A[I]+15

  5. PIC I/O • Some pins are available for • Digital input • Digital output • Analog input • Analog output • External clocks • Processor reset • Programming device • Wide variations among processes • Setting the mode isn’t easy

  6. In PIC10F20X – 1 • Some pins must be set with programming • MCLR (Master Clear) function • OPTION register is set when programmed • Can dedicate a pin to external clock • Otherwise the processor can’t run

  7. In PIC10F20X – 2 • Analog available in PIC10F206 • Register CMDCON0 (07h) • Turns on/off an input comparator • Enables comparator output

  8. In PIC10F20X – 3 • TRISGPIO register • Tri-State General Purpose I/O • “Hidden” in PIC10F • Accessed with TRIS instruction • Set to 1 for input • Clear to 0 for output • Written with TRIS instruction • From contents of W • TRIS GPIO is required for some reason

  9. Doing I/O • Register GPIO • Read and write • That’s all • But it may be interesting if TRIS isn’t set right

  10. Subroutines • Be careful about how you use registers • Probably want to use W • For single parameter • And for return • But unlikely on PIC10F20X • Small stack for return address • Only holds two on the PIC10F20X

  11. Call / Return instructions • CALL addr • Pushes PC+1 on stack • Replaces PC with addr • Except addr can only be eight bits • Other bits may come from STATUS register • Whew…. • RETURN • Not supported on PIC10F20X • But does the obvious on other processors

  12. A different Return • RETLW k • Return with Literal from W • Sets W with k • Sets PC to top of stack • Useful for lookup tables

  13. Table lookup • Store a table in instructors in program memory SQUARES RETLW 0 RETLW 1 RETLW 4 RETLW 9 RETLW 16 RETLW 25

  14. Square lookup SQUAREIT ADDLW SQUARES ;; W now points to the right place MOVWF PCL ;; Go there and return On most processors you’d also want to set some bits in the STATUS register

  15. I/O pin selection • Choose your pins • VDD • VSS • GP0 – DIN • GP1 – CLK • GP2 – DOUT • GP3 – RST

  16. Configuration word • Configuration word [p 41] • Bit 4 – 0 • GP3 is digital I/O • Bit 2 – 0 • Watchdog time disabled • Not addressable during device operation • Could set GP3 as MCLR • For reset

  17. Useful definitions • Choose registers • STATE – 0, 1, 2 • NXTST • LSTIN – DIN on last poll • Make useful bit vectors • BDIN – 01h • BCLK – 02h • BDOUT – 04h • BRST – 08h

More Related