rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Dec 22, 2004 3:26 pm |
|
|
Here are two possiblities for representing how to light the segments. I didn't bother putting in the 1's vs 0's since I don't know how you are wired up so just fill in the table appropriately.
Code: | const int8 seg7[10][7] =
//g,f,e,d,c,b,a
{ 0,0,0,0,0,0,0, // 0
0,0,0,0,0,0,0, // 1
0,0,0,0,0,0,0, // 2
0,0,0,0,0,0,0, // 3
0,0,0,0,0,0,0, // 4
0,0,0,0,0,0,0, // 5
0,0,0,0,0,0,0, // 6
0,0,0,0,0,0,0, // 7
0,0,0,0,0,0,0, // 8
0,0,0,0,0,0,0 // 9
};
|
In this example, I used a 2d array where each column element represents a single segment. This is pretty inefficient (70 bytes) but depending on how you are controlling the display, it may work better than the more straight forward version below.
Code: |
const int8 seg7b[10] =
// gfedcba
{ 0b00000000, // 0
0b00000000, // 1
0b00000000, // 2
0b00000000, // 3
0b00000000, // 4
0b00000000, // 5
0b00000000, // 6
0b00000000, // 7
0b00000000, // 8
0b00000000 // 9
};
|
Here I only used 10 bytes and each byte would have its bits encoded to a particular segment LED.
To get the magic word for a number, you will take apart the number to find the 100's, 10's and 1's. You can tweak the display code for leading zero blank.
If you want a single table to hold all possible combinations, you can expand the second example to be either a 3 x 361 array of int8's or a 361 entry array of int32s and waste one byte of the 32-bit word. You may run into memory allocation problems with an array of this size, depending on the PIC chip you have selected.
Unless I had no other choice, I'd use a small table to represent the 10 combinations I need for a single digit and just make 3 passes through the table. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|