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 support@ccsinfo.com

Ram storage of long intergers to be modified by Modbus

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



Joined: 21 Sep 2005
Posts: 12

View user's profile Send private message Yahoo Messenger

Ram storage of long intergers to be modified by Modbus
PostPosted: Tue Nov 01, 2005 8:12 am     Reply with quote

How is a long stored in ram? I just want to verify that this is right. If the Value is 50.
unsigned long maxdiff;
#byte maxdiff= 74

It stores it at location 74 is 50
and location 75 as 0

I want to modify the values in ram, is there an easy way to do this. Since modbus writes MSD to LSD, not LSD to MSD?

If I have a floating Number how do I handle that?

Lost in the fog... lol
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Nov 01, 2005 9:08 am     Reply with quote

This is an example from a post I made. It does have to swap the byte order as it copies the register locations into the packet.
Code:
               for(y=start;y<finish;y++)
               {  x=(y*2)+1;
                  COMM1_Buffer[Index] = REG_Map[x];
                  Index++;
                  --x;
                  COMM1_Buffer[Index] = REG_Map[x];
                  Index++;
               }
REG_Map is a byte array at the same location as a int16 array.
Code:
Int16 Registry_Map[128];
#locate Registry_Map = 0x200
Int8  REG_Map[256];
#locate REG_Map = Registry_Map
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

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

PostPosted: Tue Nov 01, 2005 9:39 am     Reply with quote

I modified the sample code in the FAQ that stores a float in eeprom so that it stores and reads a long int (2 bytes) in eeprom. I suppose you can re-use the for-loops for your app.

Code:
unsigned long READ_LONG_INT_EEPROM(long int n)
{
    int i;
    long int data;
   
   for (i = 0; i < 2; i++)
        *(&data + i) = read_eeprom(i + n);
    return(data);
}

void WRITE_LONG_INT_EEPROM(long int n, long int data)
{
    int i;

    for (i = 0; i < 2; i++)
    {
        write_eeprom(i + n, *(&data + i) ) ;
    }
}
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