170 likes | 400 Views
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
E N D
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 • 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
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
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
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
In PIC10F20X – 2 • Analog available in PIC10F206 • Register CMDCON0 (07h) • Turns on/off an input comparator • Enables comparator output
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
Doing I/O • Register GPIO • Read and write • That’s all • But it may be interesting if TRIS isn’t set right
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
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
A different Return • RETLW k • Return with Literal from W • Sets W with k • Sets PC to top of stack • Useful for lookup tables
Table lookup • Store a table in instructors in program memory SQUARES RETLW 0 RETLW 1 RETLW 4 RETLW 9 RETLW 16 RETLW 25
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
I/O pin selection • Choose your pins • VDD • VSS • GP0 – DIN • GP1 – CLK • GP2 – DOUT • GP3 – RST
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
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