Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   16 bit math on PIC (http://www.chiefdelphi.com/forums/showthread.php?t=39849)

dcbrown 05-10-2005 17:22

Re: 16 bit math on PIC
 

I think for the 12F, the code could be done as follows. There isn't a ADDWFC (add w/carry) as there is on the 18F so I suppose you just test the Carry bit in the status reg directly?). Anyway, I might have flipped the value of the carry bit but I believe it is asserted to 1 upon carry out and asserted to 0 for a borrow - but I might have them mixed up so make sure you test this before using it. Just one way, I'm sure there are lots of others.

Code:

Where a is at address 0x20/0x21
      b              0x22/0x23
      c              0x24/0x25

:                  c = a+b;
    MOVF  0x20, W          ; a.lo              -> W
    ADDWF  0x22, W          ; W + b.lo          -> W, set carry bit status
    MOVWF  0x24              ;                      W -> c.lo
    MOVF  0x21, W          ; a.hi              -> W
    BTFSC  STATUS,C          ; test carry bit in STATUS[0x03].<0>
    ADDLW  1,    W          ; W + Carry in bit  -> W
    ADDWF  0x23, W          ; W + b.hi          -> W
    MOVWF  0x25              ;                      W -> c.hi

:                  c = a-b;
    MOVF  0x20, W          ; a.lo              -> W
    SUBWF  0x22, W          ; W - b.lo          -> W, set borrow bit status
    MOVWF  0x24              ;                      W -> c.lo
    MOVF  0x21, W          ; a.hi              -> W
    BTFSS  STATUS,C          ; test carry bit in STATUS[0x03].<0>
    SUBLW  1,    W          ; W - Borrow        -> W
    SUBWF  0x23, W          ; b.hi - W          -> W
    MOVWF  0x25              ;                      W -> c.hi


KenWittlief 05-10-2005 18:43

Re: 16 bit math on PIC
 
Quote:

Originally Posted by sciguy125
... And if you don't need a reset pin, you configure that to be an I/O also. In the process of doing that, it occured to me that the chip would start running the program and disable the reset as soon as it's plugged into my JDM programmer. ...

you are right, if you use the reset and both programmer pins on the chip as outputs, then the device will take off running when its programmed, and the programmer wont be able to gain control of it again.

Making the two programmer pins inputs solves the problem. I did the same thing - check the programming data sheet - I think its only a problem if the SW drives one or both programming pins high (or low? I forget).

sciguy125 07-10-2005 02:57

Re: 16 bit math on PIC
 
Quote:

Originally Posted by sciguy125
Now, if you'll excuse me, I think I have some 2N7000's in the garage somewhere to fix my programmmer.

As a note to anyone here who might try that modification, I ran into some trouble with it. After spending hours checking and rechecking the hardware, it turned out to be a software issue. (It's always the other one...) I had to increase the "clock delay", as PikDev calls it. In IC-Prog it's called "I/O delay". I haven't experimented yet to find the minimum setting, but my arbitrary selection of 25 in IC-Prog worked.


All times are GMT -5. The time now is 10:28.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi