EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Loading data serially on a GPIO pin.

Started by Dhinesh December 23, 2010
On Thu, 2010-12-23 at 15:38 +0530, Dhinesh Kumar wrote:
> unsigned char data_to_send[] = {0x01,0x00};

Better yet :

#define dts_length 2
unsigned char data_to_send[dts_length] = {0x01,0x00};

.....
for(byte_idx = 0; byte_idx < dts_length; byte_idx++)
roelof

An Engineer's Guide to the LPC2100 Series

> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of roelof 't Hooft
> Sent: Thursday, December 23, 2010 3:54 AM
> To: l...
> Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
> On Thu, 2010-12-23 at 15:38 +0530, Dhinesh Kumar wrote:
> > unsigned char data_to_send[] = {0x01,0x00};
>
> Better yet :
>
> #define dts_length 2
> unsigned char data_to_send[dts_length] = {0x01,0x00};
>
> .....
> for(byte_idx = 0; byte_idx < dts_length; byte_idx++)
> roelof
>

This is not an improvement. What the OP had originally is better
because it scales with the size of the array. Your method gives
the same result, but requires the programmer to do more work
rather than letting the compiler do it for him. Now you have to
change dts_length everytime data_to_send is changed in length.

Mike

my string length may vary so i used that function. thanks for replying.

Regards

Dhinesh Kumar .R

Embedded Developer (R&D)

Hawk Technologies Pvt Ltd

--- On Thu, 23/12/10, Michael Anton wrote:

From: Michael Anton
Subject: RE: [lpc2000] Loading data serially on a GPIO pin.
To: l...
Date: Thursday, 23 December, 2010, 4:54 PM

 

> -----Original Message-----

> From: l...

> [mailto:l...]On Behalf

> Of roelof 't Hooft

> Sent: Thursday, December 23, 2010 3:54 AM

> To: l...

> Subject: Re: [lpc2000] Loading data serially on a GPIO pin.

>

>

> On Thu, 2010-12-23 at 15:38 +0530, Dhinesh Kumar wrote:

> > unsigned char data_to_send[] = {0x01,0x00};

>

> Better yet :

>

> #define dts_length 2

> unsigned char data_to_send[dts_length] = {0x01,0x00};

>

> .....

> for(byte_idx = 0; byte_idx < dts_length; byte_idx++)

>

>

> roelof

>

This is not an improvement. What the OP had originally is better

because it scales with the size of the array. Your method gives

the same result, but requires the programmer to do more work

rather than letting the compiler do it for him. Now you have to

change dts_length everytime data_to_send is changed in length.

Mike

Memfault Beyond the Launch