MicroChip 2 - PowerPoint PPT Presentation

About This Presentation
Title:

MicroChip 2

Description:

Setting FSR to INDF is possible. But a ... This is useful only with many registers ... MOVWF FRS ; FRS = &A[I] MOVF INDF,W ; W = A[I] ADDLW 15 ; W = A[I] 15 ... – PowerPoint PPT presentation

Number of Views:256
Avg rating:3.0/5.0
Slides: 18
Provided by: scie189
Learn more at: https://www.cs.unca.edu
Category:
Tags: microchip | frs

less

Transcript and Presenter's Notes

Title: MicroChip 2


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
  • AI AI 15
  • This is useful only with many registers
  • And necessary if you cant address all those file
    registers directly from an instruction

4
Array access solution
  • MOVLW 43h W A0
  • ADDWF 57h,W W AI
  • MOVWF FRS FRS AI
  • MOVF INDF,W W AI
  • ADDLW 15 W AI15
  • MOVF INDF,F AI AI15

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 isnt 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 cant 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
  • Thats all
  • But it may be interesting if TRIS isnt 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 PC1 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 youd 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
Write a Comment
User Comments (0)
About PowerShow.com