|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
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
|
|
#17
|
||||
|
||||
|
Re: 16 bit math on PIC
Quote:
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). |
|
#18
|
|||
|
|||
|
Re: 16 bit math on PIC
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PIC 18F2431 | Sparks333 | Programming | 9 | 24-08-2005 01:24 |
| Can the pic controller send the data to pc? | sunnyrx7turbo | Control System | 2 | 05-08-2005 13:14 |
| Linux and new microcontollers. | djcapelis | Programming | 48 | 29-01-2005 00:26 |