0

Hello there,
I am currently working on a pic assembly project converting the results from an acceleromet into an 8 bit LED bar graph.

I can get output from the accel but now i need to convert the results into bar graph and i'm looking for an efficient way to do this. what i need is 255 to equal 11111111
127 to equal 11110000 or (00001111) and 0 00000000

the only way i can find it subtracting results from determined values, i.e. if i had a 255, subtract it from 233, if the result sets of a carry flag then i output 11111111, but this is a very inconvenient way to do it if anyone can help, thanks.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by gusano79
0

I don't know PIC assembly, but this pseudocode should do something like what you want:

If INPUT == 0
  Set OUTPUT = 0
Else
  BARS = INPUT shifted right 5 bits
  OUTPUT = 11111110b
  Shift OUTPUT left BARS times
  OUTPUT = OUTPUT xor 11111111b

Note that the only input value that results in the output bar being completely off is 0, so if it reports any acceleration at all, you'll see at least one LED lit. Whether this is a feature or a bug is up to you. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.