how to compare a two digital numbers ??

Status
Not open for further replies.

zika1212

New Member
i'm using assembly to program PIC16f876 and i sued the A/D converter to convert an analog input into a 10 bits digital number .. now i want to generate an 8 bits digital output that represent the input number .. how can i do that ??
 
You'd just right shift the whole 10 bits twice, discarding the two LSBs. That is, if you intend to use the whole scale. If you're measuring a signal that is always small, maybe you'd want to drop the 2 MSBs instead and limit your capabilities to 0-1.25V instead of 0-5V.
 
It's even easier than that, there's a bit in a register you can set that either right justifies or left justifies the 10 bit word, see my analogue tutorial (or the datasheet) for details. It's the ADFM bit in the ADCON1 register, by clearing it you get an 8 bit result in ADRESH.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…