View previous topic :: View next topic |
Author |
Message |
joe06 Guest
|
16 bits return from a function |
Posted: Mon Feb 17, 2003 10:22 am |
|
|
Hi All, is someone able to explain me why the MSB part of the returned value is always 0 in this fucntion ?
compiled on 16F877, CCS 3.093
int16 Read_Byte_Int_Mem(void)
{
while(rd); // Wait for rd low
EEADR = flash_adress_low; // Load low Adress
EEADRH = flash_adress_high; // Load High Adress
eepgd = zeeprom_flash; // 1 or 0 depending on mem to read
rd = 1; // Start Reading
#asm
nop
nop
#endasm
return((EEDATH << 8) | EEDATA);
}
thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 11789 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: 16 bits return from a function |
Posted: Mon Feb 17, 2003 11:34 am |
|
|
That is becuase EEDATA and EEDATH are both 8 bit vars. You need to cast them to int16
return((int16)(EEDATH << 8) | EEDATA);
:=Hi All, is someone able to explain me why the MSB part of the returned value is always 0 in this fucntion ?
:=compiled on 16F877, CCS 3.093
:=
:=int16 Read_Byte_Int_Mem(void)
:={
:=
:= while(rd); // Wait for rd low
:= EEADR = flash_adress_low; // Load low Adress
:= EEADRH = flash_adress_high; // Load High Adress
:= eepgd = zeeprom_flash; // 1 or 0 depending on mem to read
:= rd = 1; // Start Reading
:= #asm
:= nop
:= nop
:= #endasm
:=
:= return((EEDATH << 8) | EEDATA);
:=}
:=
:=thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 11795 |
|
|
joe06 Guest
|
Re: 16 bits return from a function |
Posted: Mon Feb 17, 2003 11:46 am |
|
|
oups ! sure ...
thanks !
:=That is becuase EEDATA and EEDATH are both 8 bit vars. You need to cast them to int16
:=
:=return((int16)(EEDATH << 8) | EEDATA);
:=
:=:=Hi All, is someone able to explain me why the MSB part of the returned value is always 0 in this fucntion ?
:=:=compiled on 16F877, CCS 3.093
:=:=
:=:=int16 Read_Byte_Int_Mem(void)
:=:={
:=:=
:=:= while(rd); // Wait for rd low
:=:= EEADR = flash_adress_low; // Load low Adress
:=:= EEADRH = flash_adress_high; // Load High Adress
:=:= eepgd = zeeprom_flash; // 1 or 0 depending on mem to read
:=:= rd = 1; // Start Reading
:=:= #asm
:=:= nop
:=:= nop
:=:= #endasm
:=:=
:=:= return((EEDATH << 8) | EEDATA);
:=:=}
:=:=
:=:=thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 11796 |
|
|
|