Gertius Posted August 20, 2006 Report Posted August 20, 2006 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 Quote
TK. Posted August 20, 2006 Report Posted August 20, 2006 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. Quote
Gertius Posted August 20, 2006 Author Report Posted August 20, 2006 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 Quote
Gertius Posted August 21, 2006 Author Report Posted August 21, 2006 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.