hello , i am having some problems with the multiplication division unit of the xc878 infineon microcontroller. i am trying to do a shift operation. the number to be shifted is a 32 bit. lets say i want to do this: 0x00FB00FF >> 16. i would require the MD0,MD1,MD2,MD3 registers. now my problem. i can load the MD0 and MD1 registers but i dont know how to load the MD2 and MD3 registers. please kindly help out. stephen
You would normally do:
MDU_MD01 = param_5; MDU_MD23 = param_5 >> 16;
and often even show the compiler that you know about the difference in size between left-hand and right-hand side of the assign:
MDU_MD01 = (uint16_t)param_5; MDU_MD23 = (uint16_t)(param_5 >> 16);
The compiler should be smart enough to figure out that a shift right with 16 steps for the second assign is the same as picking up the two most significant bytes - so no real shifting performed.
Personally, I would prefer a function that accesses 32-bit physical registers to use int32_t or uint32_t as argument type instead of using long int or unsigned long - but it isn't too important since the full function is most definitely not portable anyway. Note that uint16_t etc require that you #include <stdint.h>
Hello,
thanks for that tip. but unfortunately the C51 Compiler still does the shifting. actually i am using the MDU to make shifting faster but if i end up shifting again then it doesnt make much sense. any other idea how this Problem can be solved? actually the datasheet says the MDU can handle 32 bit shift, so i cant seem to understand why it doesnt recognise 32 bit variable.
Another solution, if the compiler performs 16-bit shifts as actual shifts, is to use a pointer to a struct of two uint16_t integers and assign (with type cast) this pointer the address of the 32-bit integer. Then individually do
p = (u32_to_u16_struct*)&my_32_bit_val; MDU_MD01 = p->low16; MDU_MD23 = p->high16;
I recommend to use an assembly module.
I believe that the Infineon XC800 is compatible with this http://www.keil.com/support/man/docs/c51/c51_mdu_r515.htm
Using the MDU_R515 directive should therefore automatically use the MDU.