CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16 bits return from a function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
joe06
Guest







16 bits return from a function
PostPosted: Mon Feb 17, 2003 10:22 am     Reply with quote

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

View user's profile Send private message Send e-mail

Re: 16 bits return from a function
PostPosted: Mon Feb 17, 2003 11:34 am     Reply with quote

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
PostPosted: Mon Feb 17, 2003 11:46 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group