Searching \ for 'Keeping btfsc, btfss straight' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=keeping+btfsc+btfss
Search entire site for: 'Keeping btfsc, btfss straight'.

Truncated match.
PICList Thread
'Keeping btfsc, btfss straight'
1998\08\14@150133 by Richard A. Smith

flavicon
face
Having just finished first PIC project.   A PIC 16C73 that reads a 4-wire touch
screen and communicates bi-directional with a PC
via the keyboard port.  (Man that keyboard protocol is screwy, and undocumended.
thanks for Digital Storage Scopes)

I have some questions...

Most of my bugs involved getting the polarity wrong on the btfsc and btfss.  Wha
ts methods do you Gurus use to help getting
these right the FIRST time.

Also I see instructions in example code that are not in my databook..  Like skpn
z.  They seem to assemble under MPASM fine.
Are these built in assembler macros?

And finally what macros / compiler directives do you experienced people find mos
t helpful?

This list is such a awesome source...  and sorry for the FAQ I asked earlier.


--
Richard A. Smith                         Bitworks, Inc.
spam_OUTrsmithTakeThisOuTspambitworks.com               501.521.3908
Sr. Design Engineer        http://www.bitworks.com

1998\08\14@155444 by Harold Hallikainen

picon face
       I just comment it like mad, then still get it wrong some of the
time.  I do use the "psuedo codes" like clrc, skpc, skpnc, nvc, nz, bnz,
movfw, tst f, etc.  I've also defined macros called bank0, bank1, etc.
These are listed below.

DisableIRQ macro
       local DIRQloop          ; Declare local symbol in macro
DIRQloop
       bcf     intcon,gie      ; disable global interrupts
       btfsc   intcon,gie      ; make sure it's clear
       goto    dirqLoop        ; if not, go clear again
       endm
EnableIRQ macro
       bsf     intcon,gie      ; set global interrupt enable
       endm

 cblock                        ; reserve ram for save and restore
context
       isrW            ; Hold registers during ISR
       isrStatus
       isrFSR
 endc
SaveContext macro
; Save register context for isr.  Swaps swap high and low halves of f
with the result going either
; back to f or to w.  Swap is used here because they affect no status
bits.
       movwf   isrW            ; Save W
       swapf   status,w        ; get status in W (including bank
select bits) swapping hi/lo halves
       bcf     status,rp0      ; force to bank 0
       movwf   isrStatus       ; and save swapped status
       movf    fsr,0           ; Get fsr in w
       movwf   isrFSR          ; and save it
       endm
RestoreContext macro
       movf    isrFSR,0        ; get old fsr
       movwf   fsr             ; and restore it
       swapf   isrStatus,w     ; get old status (including bsr
bits) in w, swapping back to normal
       movwf   status          ; restore it
       swapf   isrw,1          ; swap halves in isrw making
them backwards
       swapf   isrw,0          ; swap back to forward and in
W without affecting status
       endm
Bank1   macro
       bsf     status,rp0      ; Set bank select bit
       endm
Bank0   macro
       bcf     status,rp0      ; Clear bank select bit
       endm


Harold



Harold Hallikainen
.....haroldKILLspamspam@spam@hallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

1998\08\14@193711 by Jorge Ferreira

flavicon
face
       Hi Richard


At 10:56 98.08.14 -0500, you wrote:
>Having just finished first PIC project.   A PIC 16C73 that reads a 4-wire
touch screen and communicates bi-[SNIP]
>And finally what macros / compiler directives do you experienced people
find most helpful?
{Quote hidden}

 About the "strange" opcodes (SKPNZ, SKPC, ...) its what Microchip calls
"Special Instruction Mnemonics" and you can find them all in the MPASM
manual (Appendix E, Table E.11).

 About the "btfsc" and "btfss" instructions, I also add the same problem
that I solved with the first macro on the following examples.
 Together are a couple of others that have been making my life easier.
Sorry I don't send the whole bunch, but they are commented in Portuguese
and it takes long to translate everything.
 It's nothing special, after all I'm also a beginner I'm only starting my
3rd PIC based projects. But I like macros and the program from were I
collected the macros and code segments bellow, had 10 pages of maccro
declarations and 2 pages of program (95% macro invocations with a handfull
of direct instructions among them).
 This macros are destinated to a 16C54A PIC, they may require some
adjustements for other models. After the macros (only 3) are some code
snipsets of an application where they've been used.


       best regards

       [] Jorge Ferreira


[SNIP]

;------- Testing a bit in a file position --------------------------------
;
; Parameters:   R - RAM (file) address
;               B - Bit to be tested (0..7)
;               V - Value to test FALSE (0) ou TRUE (1)
;               L - Destination label to jump if condition 'V' verifies
;
; Usage:        ...
;               BitTest TATUS,CARRY,TRUE,C_LABEL
;               ...
;               (do something if not carry)
;               ...
;               ...
;  C_LABEL      ...
;               (do something if carry)
;               ...

BitTest         MACRO   R,B,V,L

       if V
               btfsc   R,B
       else
               btfss   R,B
       endif
               goto    L

               ENDM


;------- Test if WDT timed out (to be used on reset vector)----------------
;
; Parameters:   C - Condition TRUE - Yes, there was a WDT reset,
;                               FALSE - No, it was a MCLR or Power Up Reset
;               L  - Label for jump when condition 'C' verifies
;

TestWDT         MACRO   C,L

       if C
               btfss   STATUS,NOT_TO
       else
               btfsc   STATUS,NOT_TO
       endif
               goto    L

               ENDM


;------- Decrement 16 bit counter and jump if ZERO/NON ZERO --------------
;
; Parameters:   HI - File address for HIGH byte
;               LO - File address for LOW byte
;               C  - Condition TRUE - Jump on non zero
;                                FALSE - Jump on Zero
;               L  - Label for jump when condition 'C' verifies
;

Dec16Jc         MACRO   HI,LO,C,L

       LOCAL   Fimm


               decfsz  LO,F
       if C
               goto    L
       else
               goto    Fimm
       endif
               movf    HI,F
       if C
               BZ      Fimm
       else
               BZ      L
       endif
               decf    HI,F
       if C
               goto    L
       endif
Fimm

               ENDM

[SNIP]


;-------------------------------------------------------------------------
;
;       Processor configuration and inits
;
               ORG     0

Init    TestWDT FALSE,Normal    ; Reset - POR ou MCLR arranque normal
       bsf PORTB,7
       clrwdt
       goto    Wait
Normal  movlw   PA_CFG          ; Configurar port de input
       tris    PORTA
       SetOpt  OPT_CFG
       SetTmr0 TSLICE          ; Init timer

[SNIP]
       ...
       BitTest ESTADO,EID_BIT,FALSE,St_1
;-------------------------------------------------------------------------
;       A STATE - Idle
;
       ... A STATE CODE ...
       goto Alarm_Rst

St_1    BitTest ESTADO,EBI_BIT,FALSE,St_2
;-------------------------------------------------------------------------
;       B STATE - Box In
;

       ... B STATE CODE ...
[SNIP]

St_4
;-------------------------------------------------------------------------
;       E STATE - Reject timing
;

       Dec16Jc C16_HI,C16_LO,TRUE,Wait  ; End of reject time - NO keep going
       ...                                          ; Reset reject signal
       ...                                          ; YES - Switch state
       goto    Wait

[SNIP]



===============================================================
cumprimentos / best regards
     Jorge Ferreira          //.....jorgegfKILLspamspam.....mail.telepac.pt
------ Make sure brain is in gear before engaging mouth -------
===============================================================

1998\08\17@134407 by John Payson

flavicon
face
>>QUOTING
Most of my bugs involved getting the polarity wrong on the btfsc and btfss.  Whats methods do you Gurus use to help getting
these right the FIRST time.

>>ME
Experience, I guess, and care.  Personally I wish that Microchip had defined the opcodes as "execute if set"/"execute if clear" rather than "skip if clear"/"skip if set".  If they changed it now, though (documentation change only) they'd just really confuse everyone.

For the common case where the instruction to be skipped is a jump, I think of a "btfss" as "execute the stuff, FOLLOWING THE JUMP, if the bit is set", and vice versa for "btfsc".  Still make mistakes occasionally, but not too often.

Another thing which I do, which I've seen some others here do as well though Microchip hasn't officially sanctioned it, is to indent by one extra space the instruction following a conditional skip.  For example:

       ; Routine to convert a number 0-15 in W into an ASCII character '0'-'F'
[untested]
       addlw   h'F6'   ; 0-9 A-F -> F6-FF 00-05
       btfsc   C
        addlw  7       ; 0-9 A-F -> F6-FF 07-0C
       addlw   h'3A'   ; 0-9 A-F -> 30-39 41-46

>>QUOTING

Also I see instructions in example code that are not in my databook..  Like skpnz.  They seem to assemble under MPASM fine.
Are these built in assembler macros?

>>ME

The Microchip assembler provides macros for "skpc", etc. which simply expand to "btfss C", etc.  Generally, these macros simply expand to the one obviously-suitable instruction though in the Parallax assembler some people use there are a number of multi-instruction macros as well.

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