Okay now I'm home.
My latest project is the USB meter device. It uses a current / voltage / power measuring chip that outputs data to the microcontroller via the i2c bus. It is quite a nice little chip to use really. Anyway, the microcontroller will request these values one at a time from the chip.
I then display this current / voltage / power data on a little 5x10 LED matrix. (the numbers are 5 pixels high by 3 pixels wide - the screen scrolls so you can see all of the info). Here's an example of you to display the current data:
The microcontroller will request current data from the sense chip.
The sense chip will send back the current data e.g. 512mA
The microcontroller will then use this number in conjunction with data from a number table stored in program memory to display '512 mA' on the LED display.
Here's the code that contains the digits 0 - 9 in a program memory number table:
Code: Select all
Const NumberTable(30) As Byte = (%00011111,%00010001,%00011111,%00001001,%00011111,%00000001,%00010111,%00010101,%00011101,%00010001,%00010101,%00011111,%00011100,%00000100,%00011111,%00011101,%00010101,%00010111,%00011111,%00010101,%00010111,%00010000,%00010000,%00011111,%00011111,%00010101,%00011111,%00011101,%00010101,%00011111)
Here's the code to separate the three digits contained within '512' into their own digit. I.E. Number1 will hold '5', then number 2 will hold '1' and number3 will hold '2':
Code: Select all
Number1 = CurrentReading
Number1 = Number1 Mod 10
Number2 = CurrentReading * 10
Number2 = Number2 Mod 10
Number3 = CurrentReading * 100
Number3 = Number3 Mod 10
Then to display these digits in the form of 512 mA on the screen, I have this code:
Code: Select all
ScreenData(0) = NumberTable(Number1 * 3)
ScreenData(1) = NumberTable(Number1 * 3 + 1)
ScreenData(2) = NumberTable(Number1 * 3 + 2)
ScreenData(3) = %00000000
ScreenData(4) = NumberTable(Number2 * 3)
ScreenData(5) = NumberTable(Number2 * 3 + 1)
ScreenData(6) = NumberTable(Number2 * 3 + 2)
ScreenData(7) = %00000000
ScreenData(8) = NumberTable(Number3 * 3)
ScreenData(9) = NumberTable(Number3 * 3 + 1)
ScreenData(10) = NumberTable(Number3 * 3 + 2)
ScreenData(11) = %00000000
ScreenData(12) = %00000000
ScreenData(13) = %00000111
ScreenData(14) = %00001000
ScreenData(15) = %00000111
ScreenData(16) = %00001000
ScreenData(17) = %00000111
ScreenData(18) = %00000000
ScreenData(19) = %00011111
ScreenData(20) = %00010100
ScreenData(21) = %00011111
Hopefully some of that at least will make sense!