We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,, I want to know a few alternate ways of doing the following thing. code unsigned long longconstant 0x1234; unsigned long longvariable; The 'longvariable' gets its value one bit at a time. Suppose it is inside a for() loop and in each pass of the loop a next bit of the 'longvariable' is initialized. After all the bits of the 'longvariable' gets their values , it is then compared with the 'longconstant'. If both compare equal then an output pin is set. So thats all. Can anyone suggest how could it be done.. ?? I am sure there would be more than one ways to do this.. If anyone can throw some quick code , that would be great. Thankzz && Bye -rocknmoon
Start with doing it the ISO C / Keil way:
const unsigned long code longconstant = 0x1234UL; unsigned long idata longvariable;
bit buildLongOneBitAtATimeAndCompare(void) { const unsigned long code longConstant = 0x1234UL; unsigned long longVariable; unsigned char bitCount; longVariable = 0; for (bitCount = 0; bitCount < 32; ++bitCount) { longVariable <<= 1; longVariable |= r_port1_1; } return longConstant == longVariable; }