Searching \ for ' [PIC] bsf, FSR?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'bsf, FSR?'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] [PIC] bsf, FSR?'
2001\05\08@222932 by David Queen

flavicon
face
Is there a way to use bit functions with the FSR or another way to select
which bit with a value you can update in a loop?

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\09@075528 by michael brown

flavicon
face
----- Original Message -----
From: "David Queen" <spam_OUTdaqueTakeThisOuTspamSWBELL.NET>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Tuesday, May 08, 2001 9:25 PM
Subject: [PIC] bsf, FSR?


> Is there a way to use bit functions with the FSR or another way to select
> which bit with a value you can update in a loop?

I have done this, though its probably not the most efficient way.  However,
if someone knows of a more efficient(code space) way please let me know, as
this lacks finesse.  This routine(Store_Bit) is called with rombit_idx
containing the one-relative (1,2,3..64) bit number to be set or cleared.
bits.1 contains the value to be stored(0,1).  Be careful of page boundarys.

<Warning - untested as of yet (this is for a Dallas one-wire search, but I
dont have any 1-wire devices yet)>

Store_Bit
             call      SetupFSR         ;convert rombit_idx to something we
can use
;Determine if we need to set a bit (1) or clear a bit (0)
             rrf       bits, W          ;get bit.1 value right justified
into W
             andlw     b'00000001'      ;maintain sanity
             addwf     PCL, F           ;quick test for 0 or 1
             goto      ClrWorkBit       ;must be 0 (clr bit)
SetWorkBit                               ;must be 1 (set bit)
             clrc
             rlf       TEMP2, W         ;get bit position * 2 (0, 2, 4 ..
14)
             addwf     PCL, F           ;bump PC, turn bit on then return
             bsf       INDF, 0
             return
             bsf       INDF, 1
             return
             bsf       INDF, 2
             return
             bsf       INDF, 3
             return
             bsf       INDF, 4
             return
             bsf       INDF, 5
             return
             bsf       INDF, 6
             return
             bsf       INDF, 7
             return
ClrWorkBit
             clrc
             rlf       TEMP2, W         ;get bit position * 2 (0, 2, 4 ..
14)
             addwf     PCL, F           ;bump PC and turn it off then
return
             bcf       INDF, 0
             return
             bcf       INDF, 1
             return
             bcf       INDF, 2
             return
             bcf       INDF, 3
             return
             bcf       INDF, 4
             return
             bcf       INDF, 5
             return
             bcf       INDF, 6
             return
             bcf       INDF, 7
             return

;-------------------------------------------------------------
;GetWorkBit --
;             at bit offset rombit_idx (1 relative)
;  Entry:
;        rombit_idx - contains one relative bit offset from rom work area
(work0..work7)
;                     of bit to retrieve value of
;  Exit:
;        work0..work7(rombit_idx) -> W
;--------------------------------------------------------------
GetWorkBit
             call      SetupFSR         ;point to the bit in question
             clrc
             rlf       TEMP2, W         ;get bit position * 2 into w
             addwf     TEMP2, W         ;compute w = bit offset * 3 (0, 3,
6 ...)
             addwf     PCL, F           ;bump PC to jump to appropriate
test
;Bit 0
             btfss     INDF, 0          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 1
             btfss     INDF, 1          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 2
             btfss     INDF, 2          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 3
             btfss     INDF, 3          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 4
             btfss     INDF, 4          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 5
             btfss     INDF, 5          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 6
             btfss     INDF, 6          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1
;Bit 7
             btfss     INDF, 7          ;Is bit set(1)
              retlw    d'0'             ; No, return 0
             retlw     d'1'             ; Yes, return 1

;----------------------------------------------------------------------
; SetupFSR -- Point FSR at byte within work area determined by rombit_idx
;   Entry:
;         rombit_idx contians bit number (one relative) we need to point to
;   Exit:
;         FSR - pointing at byte within work0..work7
;         TEMP1 - zero relative byte offset (0,1,..7)
;         TEMP2 - zero relative(0,1,..7) bit offset within byte
;-----------------------------------------------------------------------
SetupFSR                                 ;Setup FSR, TEMP1(byte offset), and
TEMP2(bit offset)
             decf      rombit_idx, W    ;convert index to 0 relative
             movwf     TEMP1            ;  and temp byte offset area
             andlw     b'00000111'      ;strip off byte offset leaving bit
offset only
             movwf     TEMP2            ; and save into temp bit offset
area

             clrc                       ;right justify the byte offset in
TEMP1
             rrf       TEMP1, F         ; by right shifting
             clrc                       ;  and stripping 3 LSB's
             rrf       TEMP1, F
             clrc
             rrf       TEMP1, F
;Get FSR pointing at appropriate byte in work area (work0, work1 ...)
             movlw     work0            ;Point FSR at beginning of work
area
             movwf     FSR
             movfw     TEMP1            ;get byte offset (0 relative)
             addwf     FSR, F           ; point FSR straight at it
             return
Hope this helps
>
> --
> http://www.piclist.com hint: The list server can filter out subtopics
> (like ads or off topics) for you. See http://www.piclist.com/#topics
>
>

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...