Searching \ for '16 bit variables' 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=bit+variables
Search entire site for: '16 bit variables'.

Truncated match.
PICList Thread
'16 bit variables'
1997\03\16@021203 by James and Iliana

flavicon
face
       First let me say " THANK YOU " to all that have helped me in the past.
       I'm in the middle of making a routine that reads a resistor value and
wanted to use more than 8 bits for the value. Is there a way to use 2
registers to make a 16 bit variable ?? Can the variable be sent via RS232
as decimal ?? At this point in time I have the routine working great except
that I would like to use bigger values.
       Thanks for taking the time to read this post !!

----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

1997\03\16@230700 by James and Iliana

flavicon
face
       First let me say " THANK YOU " to all that have helped me in the past.
       I'm in the middle of making a routine that reads a resistor value and
wanted to use more than 8 bits for the value. Is there a way to use 2
registers to make a 16 bit variable ?? Can the variable be sent via RS232
as decimal ?? At this point in time I have the routine working great except
that I would like to use bigger values.
       Thanks for taking the time to read this post !!

       I'm sending this message again as I got a " Message Not Deliverable "
notice and I didn't see it on the list.

----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

1997\03\17@103133 by Andy Kunz

flavicon
face
At 10:04 PM 3/16/97 -0600, you wrote:
>        First let me say " THANK YOU " to all that have helped me in the
past.
>        I'm in the middle of making a routine that reads a resistor value and
>wanted to use more than 8 bits for the value. Is there a way to use 2
>registers to make a 16 bit variable ?? Can the variable be sent via RS232
>as decimal ?? At this point in time I have the routine working great except
>that I would like to use bigger values.

Assembly, I presume.  The C compilers all handle this built-in.

You have to use two registers, and do all the carry handling in software.
The PIC doesn't know anything more than 8 bits and a carry.

What functions do you need?  Add, Subtract, Multiply, Divide, print as
decimal or hex?

Andy

==================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
         Hardware & Software for Industry & R/C Hobbies
       "Go fast, turn right, and keep the wet side down!"
==================================================================

1997\03\17@142128 by James and Iliana

flavicon
face
At 10:10 AM 3/17/97 -0500, you wrote:
>At 10:04 PM 3/16/97 -0600, you wrote:
>>        First let me say " THANK YOU " to all that have helped me in the
>past.
>>        I'm in the middle of making a routine that reads a resistor value
and
{Quote hidden}

Hi Andy,
       I've made a little progress on the 16 bit variable front. I found the wa
y
to declare two registers under one name and have the msb and lsb a subset
of the name.

\-----------------------------\
       cblock
twobytename:0, msbname, lsbname
       endc
\-----------------------------\

       The function I need is to transmit the twobyte to an ascii terminal as a
number.
       I've tried some binary to BCD routines but could only transmit 0 - 99.
       Any pointers would be appreciated.


----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

1997\03\17@195053 by Andy Kunz

flavicon
face
>\-----------------------------\
>        cblock
>twobytename:0, msbname, lsbname
>        endc
>\-----------------------------\

This isn't the assembler I use, so I may give you syntactical problems.
Basic idea is correct, though.

The code below is for CCS C, which lacks a 16-bit printf.  If you're a s/w
eng, you should be able to translate it to your particular
assembler/compiler easy enough.

Hope this helps.  It was based on the Microchip (I think) code from long
ago.  I have also extended this code to support up to 32 bit numbers
without any problem (another program).

Andy


char[6] Decimal;

void Bin2BCD (WORD Binary)
       {
       BYTE    temp4,
               temp5;

#asm
       bcf     C               // clear carry bit first
       movlw   16              // number of bits to work
       movwf   temp4

       clrf    &Decimal[0]
       clrf    &Decimal[1]
       clrf    &Decimal[2]
       clrf    &Decimal[3]
       clrf    &Decimal[4]
       clrf    &Decimal[5]
loop16:
       rlf     Binary,F
       rlf     &Binary+1,F
       rlf     &Decimal[5],F
       rlf     &Decimal[4],F
       rlf     &Decimal[3],F

       decfsz  temp4,F
       goto    AdjustDEC
       goto    Done

AdjustDEC:
       movlw   &Decimal[5]
       movwf   FSR
       call    AdjustBCD

       movlw   &Decimal[4]
       movwf   FSR
       call    AdjustBCD

       movlw   &Decimal[3]
       movwf   FSR
       call    AdjustBCD
       goto    loop16

AdjustBCD:
       movlw   3                // enter with FSR pointing
       addwf   INDIRECT,W       // to the BCD digit being shifted
       movwf   temp5
       btfsc   temp5,3
       movwf   INDIRECT
       movlw   0x30
       addwf   INDIRECT,W
       movwf   temp5
       btfsc   temp5,7
       movwf   INDIRECT
       return
Done:
       movf    &Decimal[3],W
       andlw   0x0f
       iorlw   0x30
       movwf   &Decimal[0]
       swapf   &Decimal[4],W
       andlw   0x0f
       iorlw   0x30
       movwf   &Decimal[1]
       movf    &Decimal[4],W
       andlw   0x0f
       iorlw   0x30
       movwf   &Decimal[2]
       swapf   &Decimal[5],W
       andlw   0x0f
       iorlw   0x30
       movwf   &Decimal[3]
       movf    &Decimal[5],W
       andlw   0x0f
       iorlw   0x30
       movwf   &Decimal[4]
       clrf    &Decimal[5]             // Marks end of C string
#endasm
       temp5 = 1;
       temp4 = 0;
       while (temp5)
               if (Decimal[temp4] == '0')
                       Decimal[temp4++] = ' ';
               else
                       temp5 = 0;
       }

void ShowDecimal (void)
       {
       BYTE    i;

       for (i=0; i!= 5; i++)           // Blank leading zeros
               if (Decimal[i] == 0)
                       lcd_putc (' ');
               else
                       lcd_putc (Decimal[i]);
       for (i=0; i!=3; i++)
               lcd_putc (" uS");
       }

==================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
         Hardware & Software for Industry & R/C Hobbies
       "Go fast, turn right, and keep the wet side down!"
==================================================================

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