Jump to content

Recommended Posts

Posted

Hi everyone!

Did anybody already gather experiences with the "long" datatype while programming the PIC18F452 in C?

I wanted to realize a function for continous adressation of the bankstick, which would automatically switch the chip on an 8-chip board. The "long" variable mem_adress would store the bankchip in nibble 5 (counting from the right), triggering the "MIOS_Bankstick_CtrlSet" Function, and the adress (for the "MIOS_Bankstick_Write" Function) in nibbles 1-4.

But somehow it doesn´t seem to work!

The nibble in which the chip is stored is always 0, I get the value through "mem_adress>>16".

Here's the code if you're interested:

void writeBank(unsigned long mem_adress,unsigned char value) {
	if (mem_adress >= 0x80000)
		return;
	if (bankchip != mem_adress >> 16)						// select BankChip
		MIOS_BANKSTICK_CtrlSet(bankchip=mem_adress>>16);
	MIOS_BANKSTICK_Write(mem_adress%0x10000, value);
}

I searched the forums, but didn't fing anything on this subject, so I just wanted to know if it's generally a bad idea to use "long" variables with MIOS in C and the PIC18F425...

Greetings,

Gertius

Posted

Hi,

in general I wouldn't use the long data type, because it propably (I never used it...) consumes 4 bytes, which means, that each operation takes twice the time, even when only the lower 16 bits are changing.

Best Regards, Thorsten.

Posted

Hi Thorsten,

thanks for the fast response, maybe that is also the answer for some other problems, I was having. I think I will go back to smaller data types, and see if those work better for me.

Sorry for choosing the wrong forum by the way, makes sense to put that into C programming...

Have a good night,

Gertius

Posted

Doh,

finally I found out what was going wrong.

In my main program I used counting variables which were "int" and "char", and added them in various locations to my "long" variables to determine the adress.

But: that way the small 2 bytes of the "long" adress variable changed, but not the third one in which the bankstick was stored, even when it should.

Changed everything to "long" and now it works perfectly.

Just thought I´d let you know.

I´m a programming noob, and now I see why calculating with different data types can give you strange results  :)

Greetings,

Gertius

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...