Go to Post This is a high-energy sporting event, not a piano recital. :) - Alan Anderson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #15   Spotlight this post!  
Unread 05-10-2005, 17:22
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 06:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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