3/15/03 1:40:41 AM, Andre Abelian wrote: >I need to convert ADRESH to bar graph style led movement. >This code works fine on demo board but I think there is >Shorter method any idea will appreciate. > >if (ADRESH==0) > { > PORTB=0b00000000; > } > if ((ADRESH>0)&&(ADRESH<=30)) > { > PORTB|=0b00000001; > } > if ((ADRESH>=31)&&(ADRESH<=61)) > { > PORTB|=0b00000011; > } Shorter in terms of time or space? If you're looking to save time, note that the cases are mutually exclusive and make all but the first if "else ifs." If you're looking to save space and improve readability, note that you can eliminate the second part of each test if you change the values being or'd with the port to have only one bit set. i.e. set bit 0 if the value is >0, then set bit 1 if the value is >=31 (since bit 0 will already have been set by the first test), and so on. This also has the advantage that if you have to change one of the "break points" you only have to change one line of code, rather than two that might get out of sync. You could make the code more compact (if slightly slower) by using a table lookup; you'd index through an array of "break values" (0, 31, 62, etc.) and each time ADRESH was greater than the current array value, you'd or the port with a bit mask and then shift the mask left. For the number of cases you're talking about, though, I doubt you'd gain much if anything by doing this. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body