|
|
View previous topic :: View next topic |
Author |
Message |
GoatPete Guest
|
16 bit pointers |
Posted: Thu Aug 19, 2004 3:14 am |
|
|
Hi.
This code works for 8 bit pointers (#device *=8), but it does not work for 16 bit pointers (#device *=16). &dataBytes is always 0x0000 and so is dataBytes[x] always 0x00.
Who can point me to my mistake?
Code: |
// 8 bit -> char*
static void send_packet(byte cmd, char* dataBytes[], byte dataLength) {
// 16 bit -> long*
static void send_packet(byte cmd, long* dataBytes[], byte dataLength) {
int8 i;
putc(cmd);
putc(dataLength);
for (i = 0; i < dataLength; i++) {
putc(dataBytes[i]);
}
putc(calc_chk(cmd, dataBytes, dataLength));
}
static void main() {
byte dataBuffer[11];
strcpy(dataBuffer, str);
send_packet(cmd, dataBuffer, 10);
}
|
Regards. |
|
|
GoatPete Guest
|
Re: 16 bit pointers |
Posted: Thu Aug 19, 2004 6:09 am |
|
|
Solved it myself.
Please note that this one is wrong, of course. It's still a pointer to a char.
GoatPete wrote: |
Code: |
// 16 bit -> long*
static void send_packet(byte cmd, long* dataBytes[], byte dataLength) {
|
|
This way it works in 8 bit and 16 bit mode:
Code: |
static void send_packet(byte cmd, char* dataBytes, byte dataLength) {
int8 i;
putc(cmd);
putc(dataLength);
for (i = 0; i < dataLength; i++) {
putc(dataBytes[i]);
}
putc(calc_chk(cmd, dataBytes, dataLength));
}
|
Regards,
GoatPete |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 19, 2004 6:09 am |
|
|
#device *=8 and #device *=16 have nothing to do with char* and long* but rather the size of the actual pointer and not the size of the data. With #device *=8 pointers are only 8 bits which would allow you to only access a block of 256 bytes of RAM.
Code: |
static void send_packet(byte cmd, byte* ptrBytes, byte dataLength)
{
int8 i;
putc(cmd);
putc(dataLength);
for (i = 0; i < dataLength; i++)
{
putc(*(ptrBytes+i));
}
putc(calc_chk(cmd, ptrBytes, dataLength));
}
static void main()
{
byte dataBuffer[11];
strcpy(dataBuffer, str);
send_packet(cmd, dataBuffer, 10);
}
|
|
|
|
valemike Guest
|
|
Posted: Thu Aug 19, 2004 8:01 am |
|
|
In the 16F family, after some headscratching, I realized that I needed to enable 16 bit pointers when my program started getting big. It also took its toll on overall ROM usage compared to 8-bit pointers.
I never found myself having to do 16 bit pointers for the 18F series. Are 16bit pointers enabled by default by the compiler for the 18F? Or is this convenience built into the 18F architecture?
Thanks,
Mike |
|
|
|
|
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
|