The remainder from each division are the digit values in least to most significant order. Note that this works regardless of how large the original number is. In the special case of the input value only being 0-255, various shortcuts are possible. One brute force but simple approach is to use a lookup table. Since you only have 256 possible input values, it doesn't need to be large. The lookup table could result in the 4-bit BCD values for each digit. Since the highest digit can only be 0,1,2, you actually only need 2 bits for its BCD value. That means a 8-bit in 10-bit out lookup table solves this problem very simply. Or, the table could even result in the 7-segment values for each digit directly. That would require a minimum of 21 bits per table entry. Even if you ended up using 32 bits per table entry for convenience, that's still only 1024 bytes of program memory. That's a "small" amount of memory for a modest modern microcontroller.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |