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

How move a byte one byte to left in this array

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



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

How move a byte one byte to left in this array
PostPosted: Sun May 07, 2006 3:37 pm     Reply with quote

How can i move the five bytes at position 45 one byte each other to left
The five bytes make the letter A

It is used for making a routeting message on the dot matrix displays

I need a efficient routine to do this
Code:

const char message[50] = {
   0x00, 0x00, 0x00, 0x00, 0x00,  // 0
   0x00, 0x00, 0x00, 0x00, 0x00,  // 5
   0x00, 0x00, 0x00, 0x00, 0x00,  // 10
   0x00, 0x00, 0x00, 0x00, 0x00,  // 15
   0x00, 0x00, 0x00, 0x00, 0x00,  // 20
   0x00, 0x00, 0x00, 0x00, 0x00,  // 25
   0x00, 0x00, 0x00, 0x00, 0x00,  // 30
   0x00, 0x00, 0x00, 0x00, 0x00,  // 35
   0x00, 0x00, 0x00, 0x00, 0x00,  // 40
   0x7E, 0x7E, 0x11, 0x11, 0x7E   // 45
};


After the move it must be this
Code:

const char message[50] = {
   0x00, 0x00, 0x00, 0x00, 0x00,  // 0
   0x00, 0x00, 0x00, 0x00, 0x00,  // 5
   0x00, 0x00, 0x00, 0x00, 0x00,  // 10
   0x00, 0x00, 0x00, 0x00, 0x00,  // 15
   0x00, 0x00, 0x00, 0x00, 0x00,  // 20
   0x00, 0x00, 0x00, 0x00, 0x00,  // 25
   0x00, 0x00, 0x00, 0x00, 0x00,  // 30
   0x00, 0x00, 0x00, 0x00, 0x00,  // 35
   0x00, 0x00, 0x00, 0x00, 0x7E,  // 40
   0x11, 0x11, 0x11, 0x7E, 0x00   // 45
};


Each five bytes displayed on ten 5x7 ot matrix displays
This array is the displaybuffer.
Ttelmah
Guest







PostPosted: Sun May 07, 2006 3:41 pm     Reply with quote

You can't.
Since this is a constant array, you cannot move the data at all.
However may I suggest a possible 'route'. If you have the address you want to 'start' reading from the array as 'address', and the _offset_ (how much you want to move the data), in a signed variable called 'offset', then:

message[(address+offset)%50]

will access the array as if it started 'offset' bytes from where it really does. You can increment, and decrement 'offset', to move where you access the array from.

Best Wishes
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

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

PostPosted: Mon May 08, 2006 6:32 am     Reply with quote

you can do this if you use a pointer to that array.
for example:

Code:

void MoveByte (char **Array, int Positions)
{
        char AuxArray[50];
        int i;
        int j;

        for (i = 0; i < 50; i++)
        {
                AuxArray[i] = (* Array)[i]; // copy the orignal values
         }

        for (i = 0, j = Positions; i < 50; i++)
        {
                (*Array)[i] = AuxArray[Positions];
                 Positions++;
               
                // last position of an array is a null terminated
                 if (Positions > 49) 
                 {
                           Positions = 0;
                  }
         }

         return;
}

// and you call this function in main, like this:

void main ()
{
        MoveByte (&Message, 4);     // it will probably move 4 bytes
        .
        .
        .
        return;
}   



if you get some problem, write again.

regards
_________________
Andre
Ttelmah
Guest







PostPosted: Mon May 08, 2006 6:34 am     Reply with quote

You can't use pointers to constant arrays in CCS. Hence my suggestion to use an offset byte instead.

Best Wishes
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

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

PostPosted: Mon May 08, 2006 6:56 am     Reply with quote

i thought that it was possible...
if is not..
sorry.

so.. he can make it using a dinamic array...

char *message;

message = (char *) malloc (sizeof (char) * 50);

regards.
_________________
Andre
Ttelmah
Guest







PostPosted: Mon May 08, 2006 7:45 am     Reply with quote

He doesn't even need to fiddle around like this. If the word 'const' is just removed from the declaration, the array will be a simple variable one, and the compiler will handle the initialisation as well. However the 'downside' of the variable array, is the need for 50 bytes of RAM (which may be a problem on some PICs). On smaller PICs, using the offset to the const array may be the better solution.

Best Wishes
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 08, 2006 9:27 am     Reply with quote

Is there another option to do this on a simple matter

I need this to shift data on 10 dot matrix displays by one column each
Maybe another structure
Ducky
Guest







Shift it :-)
PostPosted: Wed May 17, 2006 4:31 pm     Reply with quote

remove the const from your array declaration....than you can use the rotate_right or rotate_left function.

for example...

char message[50] = {
0x00, 0x00, 0x00, 0x00, 0x00, // 0
0x00, 0x00, 0x00, 0x00, 0x00, // 5
0x00, 0x00, 0x00, 0x00, 0x00, // 10
0x00, 0x00, 0x00, 0x00, 0x00, // 15
0x00, 0x00, 0x00, 0x00, 0x00, // 20
0x00, 0x00, 0x00, 0x00, 0x00, // 25
0x00, 0x00, 0x00, 0x00, 0x00, // 30
0x00, 0x00, 0x00, 0x00, 0x00, // 35
0x00, 0x00, 0x00, 0x00, 0x00, // 40
0x7E, 0x7E, 0x11, 0x11, 0x7E // 45
};
rotate_left(message,50);
Ducky
Guest







Sorry...missed somethink
PostPosted: Wed May 17, 2006 4:33 pm     Reply with quote

rotate_x rotates only one bit

the following rotates one byte....sorry

int loop = 0;
for(loop = 0; loop < 8;loop++)
rotate_right(message,50);
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