Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #383001

OT: More MPLAB program problems

From Robert Baer <robertbaer@localnet.com>
Newsgroups sci.electronics.design
Subject OT: More MPLAB program problems
Message-ID <cD%Xx.19186$a85.1429@fx19.iad> (permalink)
Date 2015-10-28 01:24 -0800

Show all headers | View raw


         Problems.

   Code snippet #1:
        CLRW
        ADDWF    swcount,W       ; count to W
        BTFSC    STATUS,Z        ; zero count = divide by zero ==> value 
as zero
        GOTO     BY1
        DECF     swcount,W       ; count = 1    ** Neither W nor swcount 
change; WTF?
; assembles to 0x032A which decodes to DECF direction "W", swcount.
        BTFSC    STATUS,Z
        GOTO     BY1
        DECF     swcount,W       ; count = 2    ** ditto
        BTFSC    STATUS,Z
        GOTO     BY2
        DECF     swcount,W       ; count = 3    ** ditto
        BTFSC    STATUS,Z
        GOTO     BY35
        DECF     swcount,W       ; count = 4    ** ditto
        BTFSC    STATUS,Z
        GOTO     BY4
BY35:  CLRW
        MOVWF    ampres          ; dividend
        MOVF     swcount,W       ; count = 5 or 3 to W
        BCF      STATUS,C        ; clear carry bit for rotate

        RLF      amplo
        RLF      amphi
; MPLAB error message "Argument out of range.  Least significant bits used"
;  assembled to 0x0280 or SUBWF with destination "F", BUT zero for F 
(amphi at 0x27)  WTF?
        SUBWF    W,amphi         ; want results in amphi (d=1)
        BTFSS    STATUS,C        ; if carry, result is negative so no count
        INCF     ampres
        RLF      ampres          ; bit 7 done,ready for next

END snippet #1

   Code snippet #2:
;;;** tab4, tab5 locations considered as invalid...
T4L:   BTFSC    K1.4,0    ; Wave enable input, 1 => enabled
        GOTO     T5L       ; skip lookup code when disabled
        MOVLW    High(tab4)
        MOVWF    PCLATH
        CALL     tab4      ; far call
        ADDWF    amplo     ; add lookup value to amplitude
        BTFSC    STATUS,C
        INCF     amphi
        INCF     swcount

T5L:   BTFSC    K1.5,0    ; Wave enable input, 1 => enabled
        GOTO     DIV       ; skip lookup code when disabled
        MOVLW    High(tab5)
        MOVWF    PCLATH
        CALL     tab5      ; far call
         ...
; ----------------------------------------------
tab1:   ; TABLE SUBROUTINE
         MOVLW   High(tab1_data)
         ADDWF   timhi,W
         MOVWF   PCLATH
         MOVLW   Low(tab1_data)
         ADDWF   timlo,W
         BTFSC   STATUS,C
         INCF    PCLATH,F
         MOVWF   PCL     ; computed GOTO into data
; ------------------
tab1_data:
; ---------------------------------------------- tab1
         RETLW   0x01    ;  [1]
          ...
         RETLW   0x01    ;  [768]
; ----------------------------------------------
tab2:   ; TABLE SUBROUTINE
         MOVLW   High(tab2_data)
         ADDWF   timhi,W
         MOVWF   PCLATH
         MOVLW   Low(tab2_data)
         ADDWF   timlo,W
         BTFSC   STATUS,C
         INCF    PCLATH,F
         MOVWF   PCL     ; computed GOTO into data
; ------------------
tab2_data:
; ---------------------------------------------- arbitrary
          RETLW 0x01   ;  [1]
           ... etc for tab3, tab4, and tab5
   Program easily fits in 0xFD3 space (under 0xFFF limit).

   Help?

Back to sci.electronics.design | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

OT: More MPLAB program problems Robert Baer <robertbaer@localnet.com> - 2015-10-28 01:24 -0800
  Re: OT: More MPLAB program problems Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-28 08:45 +0000
    Re: OT: More MPLAB program problems Robert Baer <robertbaer@localnet.com> - 2015-10-29 01:19 -0800
  Re: OT: More MPLAB program problems piglet <erichpwagner@hotmail.com> - 2015-10-28 09:59 +0000
    Re: OT: More MPLAB program problems Robert Baer <robertbaer@localnet.com> - 2015-10-29 01:45 -0800
      Re: OT: More MPLAB program problems piglet <erichpwagner@hotmail.com> - 2015-10-29 09:31 +0000
  Re: OT: More MPLAB program problems Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-29 08:52 +0000

csiph-web