Em 30/5/2011 20:31, Harold Hallikainen escreveu: >> Em 30/5/2011 17:51, IV3YNB op. Matteo escreveu: >>> Hi all !!! >>> >>> I'm an hobbyst and I am struggling to find the right example or the >>> right >>> application note to read, useful to solve my trouble: >>> >>> I have to control a DDS chip and I need to set his frequency: I have to >>> split a >>> 32 bits word into 4 bytes to manage the frequency into the DDS chip and >>> to save >>> in the memory of the PIC (I will use a 16F877 or similar). >>> >>> >>> May somebody help me? I am not asking for the exact assy code; I am >>> asking for >>> the right document to read and understand. >>> >>> Thank you in advance for your help >>> Matteo - IV3YNB >>> >>> >>> Matteo Copetti -- IV3YNB -- JN65vp >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>> http://www.iv3ynb.altervista.org >>> http://iv3ynb.splinder.it >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> Example in C: >> >> long var; >> char byte0, byte1, byte2, byte3; >> ... >> var =3D VALUE; >> byte0 =3D (char)var; >> byte1 =3D (char)(var >> 8 ); >> byte2 =3D (char)(var >> 16 ); >> byte3 =3D (char)(var >> 24 ); >> >> >> > The way I like to do it in C (and I like types to tell me how many bits > there are, so I use stuff like uint8_t), is like this: > > union{ > uint8_t byte[4]; > unint32_t long; > }value; > value.long=3D something. > most significant byte =3D value.byte[3]; > least significant byte =3D value.byte[0]; > since PIC is little endian. The shift version is portable and doesn't depend on endianess. Besides, a good compiler will generate the same code for both versions. Isaac --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .