I am starting to write a assembly program for a mc68hc12. I will be reading a 8 bit signed number into PortA and outputting the results to 7 segment LED's, common anode. I will be using Port P to output the segments and PortCan to control the LED's displayed. I assume I need 4 LED's, 1 for the sign and 3 LEDs for the max number of 128. How would I go about pulling the data in from a port and then displaying the number on a set of LED's? Is there a straight forward way to do the signed number conversion using a lookup table or do I need to go through a more in depth conversion algorithm? I'm not sure how to handle the input number once I read it from PORTA, should I store it in memory or work with it directly. I am new to assembly programming so pardon the simple questions, how would I pull off the digits of the inputed number to convert? Thanks
s there a straight forward way to do the signed number conversion using a lookup table or do I need to go through a more in depth conversion algorithm?
s there a straight forward way to do the signed number conversion using a lookup table or do I need to go through a more in depth conversion algorithm? ----------------
I don't see the point of Clayton's posts. Easiest way if you've got the space is a 3*256-byte lookup table (3*256, because if you have 3 7-segment displays plus a sign, that's 22 bits, which will fit into 3 bytes). (You can generate the table with a quick C program on your PC.) You could do it with less space and more code: let's say X is the signed byte. First determine the sign (look at bit 7), then negate X if it's negative. Then modulo X by 10 to get the least significant decimal digit and divide X by 10. If it's zero then you can bail out early. Otherwise modulo X by 10 to get the second least significant decimal digit, divide X by 10 again and what's left should be the final digit. So suppose you have X=-123. Step 1: sign=1, X=123 Step 2: LSD=3 (because 123 mod 10 is 3), X=12. If you have a function that will divide by 10 and give you the dividend and remainder (i.e. input 123, output 12 and 3) then that would be useful here. Step 3: 2LSD=2, X=1 Then you can use a 10-byte lookup table to convert 0-9 to the respective 7-segment bits, which will depend on the wiring. Counting clockwise from the top-most LED with the last one in the middle, 0 would be 01111110, 1 would be 00110000, 2 would be 01101101 etc. Code: One way of numbering the LEDs: +-0-+ | | 5 1 | | +-6-+ | | 4 2 | | +-3-+ Representation of 3: +-1-+ | | 0 1 | | +-1-+ | | 0 1 | | +-1-+ This would be in the lookup table as 01001111 (bit 7 would always be zero). 0 would be 00111111 because you need bits 0,1,2,3,4,5 set; 1 would be 00000110, 2 would be 01011011 etc.