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 am trying to write a simple program that do the following. it increments a 3-bit binary number after a delay. It looks like following. do{ if (bin_num++ > 0x7) bin_num=0; deley(); }while(1) Now what i want to do is that , read Port 1, and if any bit is Zero (for example if P1^3 is zero) then leave skip the number 3 in incrementing bin_num. So the bin_num will count as 0, 1, 2, 4, .. Any quick idea how to best do this ?? Any help would be great. Thankzz && Bye -Rocknmoon
What a curious problem. I have not tried this, but it should get you on your way. It is easy to check for any 1s in a word by adding to that word a word full of 1s and looking for overflow e.g.
skip = ( P1 + (unsigned int) 0x00FF ) > 0x00FF;
skip = ( ~P1 + (unsigned int) 0x00FF ) > 0x00FF;
do { skip = ( ~P1 + (unsigned int) 0x00FF ) > 0x00FF; bin_numm++; if ( bin_num == 0x08 ) bin_num = 0; if ( ( bin_num == 0x03 ) && skip ) bin_num++; delay(); }while(1)