??? 02/08/09 03:26 Read: times |
#162178 - Final answer and it works Responding to: ???'s previous message |
Per Westermark said:
long value = 1388; digit1 = (value / 1000) + '0'; digit2 = ((value / 100) % 10) + '0'; digit3 = ((value / 10) % 10) + '0'; digit4 = (value % 10) + '0'; This is the hot ticket item that solved my problem. I understand now why it is being done, and I am able to convert a long hex value to decimal to convert to ASCII to use a fast lookup ASCII table. Phew....that's a mouth full, but it appears to work just fine under simulation and should be fine in my project.....thanks again to all for your help. I pasted the final result below code uchar DataLookup[] ={ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x6F, 0x76, 0x30, 0x0E, 0x80, 0x38, 0x80, 0x80, 0x5C, 0x73, 0x80, 0x80, 0x6D, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x80, 0x80}; uchar D6,D5,D4,D3,D2,D1,D0; I2C_Data_Array[0] = Count[0]; D0 = (( I2C_Data_Array[0] / 1000000) + '0') - 0x30; D1 = (((I2C_Data_Array[0] / 100000) % 10) + '0') - 0x30; D2 = (((I2C_Data_Array[0] / 10000) % 10) + '0') - 0x30; D3 = (((I2C_Data_Array[0] / 1000) % 10) + '0') - 0x30; D4 = (((I2C_Data_Array[0] / 100) % 10) + '0') - 0x30; D5 = (((I2C_Data_Array[0] / 10) % 10) + '0') - 0x30; D6 = (( I2C_Data_Array[0] % 10) + '0') - 0x30; transmit_bytes[6] = DataLookup[D6]; transmit_bytes[5] = DataLookup[D5]; transmit_bytes[4] = DataLookup[D4]; transmit_bytes[3] = DataLookup[D3]; transmit_bytes[2] = DataLookup[D2]; transmit_bytes[1] = DataLookup[D1]; transmit_bytes[0] = DataLookup[D0]; MAX_NUMBYTE_TX[0] = 6; //Send 7 Bytes of data i2c_init(0x20, 0); //Set to master with address of 0x20, no general call i2c_transmit(device_address); while (i2c_getstatus() & I2C_BUSY); // wait until complete Regards, Chris |
Topic | Author | Date |
Looking for a fast elegant solution to an SAA1064 | 01/01/70 00:00 | |
several ways | 01/01/70 00:00 | |
Simple Table Lookup | 01/01/70 00:00 | |
Constructing the table symbolically | 01/01/70 00:00 | |
That looks like it will do the trick | 01/01/70 00:00 | |
Ok I'm here now....... | 01/01/70 00:00 | |
first convert to decimal, then to ASCII | 01/01/70 00:00 | |
So... | 01/01/70 00:00 | |
Keep track of binary/BCD/hex/ASCII | 01/01/70 00:00 | |
Final answer and it works | 01/01/70 00:00 | |
But '0' - 0x30 is zero :)![]() | 01/01/70 00:00 | |
not exactly | 01/01/70 00:00 |