Good morning
Is there a way to memcpy from SFR's in the C51?
I have tried to memcpy((char*)&buffer, (char*)&CAN0IF2DA1L, 8); but it doesn't work
Other things i tried
memcpy((char*)&buffer, CAN0IF2DA1L, 8); //error C214: illegal pointer conversion
memcpy((char*)&buffer, (char*)&CAN0IF2DA1L, 8); //error C189: '&' on bit/sfr illegal
Any ideas?
Richard
RichardT said:seems like the most efficient way of doing this is to copy all 8 bytes every time
Well, doing work that serves no purpose is very rarely the most efficient way of doing anything.
This also probably applies to the case at hand. Watch, be appalled, and learn: ;-)
// copy message into CAN0rx; switch(dlc) { case 8: m->Data[7] = CAN0IF2DB2H; case 7: m->Data[6] = CAN0IF2DB2L; case 6: m->Data[5] = CAN0IF2DB1H; case 5: m->Data[4] = CAN0IF2DB1L; case 4: m->Data[3] = CAN0IF2DA2H; case 3: m->Data[2] = CAN0IF2DA2L; case 2: m->Data[1] = CAN0IF2DA1H; case 1: m->Data[0] = CAN0IF2DA1L; case 0: }
This is one half of what may be the only C code snippet infamous enough to carry a name of its own: Duff's Device.
Broeker said:Duff's Device
was about to say that - you beat me to it!
Broeker said:the only C code snippet infamous enough to carry a name
Algol has Jensen's Device
It's brilliant :)