View previous topic :: View next topic |
Author |
Message |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
Array concatenation |
Posted: Wed Oct 06, 2004 4:14 am |
|
|
Is there any way to concatenate for example 2 bytes array to 1 variable?
Say:
BYTE array[2];
int Var; //2 bytes
I want to write the whatever in the array into the Var.
Thank you _________________ Alex |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Oct 06, 2004 5:12 am |
|
|
Use a union
Code: |
union my_union {
int 16 var;
int8 array[2];
} my_union_variable; |
|
|
![](templates/subSilver/images/spacer.gif) |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Wed Oct 06, 2004 5:17 am |
|
|
int16 and int8
are not recognized for some reason
and also cannot make a variable more than 8 bits.
it does recognize 'long', but the variable is still 8 bits _________________ Alex |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Oct 06, 2004 5:29 am |
|
|
alexz wrote: | int16 and int8
are not recognized for some reason
and also cannot make a variable more than 8 bits.
it does recognize 'long', but the variable is still 8 bits |
ok - so int8 and int16 are not defined.
how do you know the long variable is only 8 bits? Are you sure you aren't running into a typecast problem? |
|
![](templates/subSilver/images/spacer.gif) |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Wed Oct 06, 2004 5:32 am |
|
|
I am not sure.
I just cant find a way to define a 16bit variable :(
I already tryed #type int16=16 _________________ Alex |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Oct 06, 2004 5:52 am |
|
|
Quote: | I just cant find a way to define a 16bit variable :(
|
A long is a 16 bit variable |
|
![](templates/subSilver/images/spacer.gif) |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Wed Oct 06, 2004 5:54 am |
|
|
I know that.
But in the watch window it is still 8 _________________ Alex |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 06, 2004 7:59 am |
|
|
Your version must be old as dirt!
Code: |
typedef uint8_t int;
typedef int18_t signed int;
typedef uint16_t long;
typedef int16_t signed long;
|
|
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Oct 06, 2004 8:53 am |
|
|
What version of the compiler did you say you were using?
We are trying to help,.. but the assignment is easy. and we don't understand the problem?
int8 array[2];
int16 Var;
Var=make16(array[0],array[1]); //whatever order you want
I think the problem is the compiler version or the watch window.
(ps i think its the watch window)
Last edited by treitmey on Wed Oct 06, 2004 9:01 am; edited 3 times in total |
|
![](templates/subSilver/images/spacer.gif) |
alexz
Joined: 17 Sep 2004 Posts: 133 Location: UK
|
|
Posted: Wed Oct 06, 2004 8:55 am |
|
|
version CCS 3.207 _________________ Alex |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Oct 06, 2004 9:24 am |
|
|
Here is a little test progrm. in watch window put in addr,h tmp,h
the ",h" displays it in hex digits,.. 4 bits per 1 hex digit
btw. I used 3.212 compiler
Code: | #include <16F877.h>
#device *=16
#CASE
#use delay(clock=16000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP
#define VER_MAJOR 1
#define VER_MINOR 00
#define INTS_PER_MIN_TMR2 3660
#zero_ram
#use rs232(baud=57600,xmit=PIN_A2,INVERT,stream=DEBUG) // STDERR(same as DEBUG)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=FA403) //This is talking to FA403 wireless
void main(void)
{
int8 tmp[2];
int16 addr;
tmp[0]=1;
tmp[1]=2;
addr=make16(tmp[0],tmp[1]);
while(1)
{
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
|