Writing 13 bit numbers on an LCD display using 8051 - Page 1
Forum section: electronics / projects

author: Arrow
author_rank: Contributor
timestamp: January 25, 2013, 01:16:58 pm
content: Hello all,I'm working on a tripple PS and I would like to display the Voltage on the display. I used to write 8 bit numbers on an LCD display, but I've never tried a 13 bit number.Is there any one that can help me or give me some hints?? I was thinking of changing the 13 bit first to BCD. I'm busy to figured out how to do it, and I was thinking, maybe there is some one with some hints or decent code that may help. I'm using the Atmel AT89LP51ED2 , and assembly code.

author: ptricks
author_rank: Frequent Contributor
timestamp: January 25, 2013, 01:23:58 pm
content: Your losing me on the 8/13 bit number part. To the LCD the number doesn't matter, it is just displaying whatever you tell it to display. In your code you need to take whatever number you have and convert that to the format the LCD controller understands.All controllers are different so specific code to display numbers requires knowing what LCD is used.

author: Harvs
author_rank: Super Contributor
timestamp: January 25, 2013, 01:38:59 pm
content: In C it's simple using a division and remainder. I.e.first_digit = number % 10number /= 10;etc...Then print it to the LCD.In assembly I'm sure you could just do exactly the same thing if you've got a division routine.

author: Arrow
author_rank: Contributor
timestamp: January 25, 2013, 02:10:30 pm
content: Quote from: ptricks on January 25, 2013, 01:23:58 pmOn the HD44780 (8bit), you just add 30x to your 8bit number and load it to the LCD, this convert the number to ascii. If you have a 13bit or 16bit number you can not do that. But like Harvs suggested you have to create a dividing subroutine for that.

author: deephaven
author_rank: Frequent Contributor
timestamp: January 25, 2013, 02:18:28 pm
content: Thishttp://www.atmel.com/Images/doc0938.pdfwill show you how convert between binary and BCD. You can use a cut down version of their 16 bit example.

author: amyk
author_rank: Super Contributor
timestamp: January 25, 2013, 08:18:49 pm
content: Quote from: Arrow on January 25, 2013, 02:10:30 pmThat only works for a single digit as ASCII '0' ~ '9' is conveniently at 30h ~ 39h.As said above you will need to divide the number successively by 10 and collect remainders until the dividend becomes 0. The remainders in reverse order are the digits.That uC has a multiplier but no divider, so you'll need to do shift-and-subtract for division.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 26, 2013, 03:57:47 am
content: Hi,I write in Asm (Can't stand the XC8 compiler from microchip, utter unoptimized crap ) and do it with divide by 10 or recently i've been using the shift and add 3 system shown in the link below.http://www.johnloomis.org/ece314/notes/devices/binary_to_BCD/bin_to_bcd.htmlAfter the conversion i mask out the top 4 bits, add 30 (to convert to ascii decimal ) and send to the lcd, for the top 4 bits, swap the bits ( i use pic and it's swapf ) and again mask out the top 4 add 30 and send to the lcd.swapf BCD_1,w ;swap file and put into wandlw 0x0f ;mask out upper 4 bitsaddlw 0x30 ;convert to asciimovwf Sdata ;put into sdata ready for RS232 sendingcall RS232RS232 or LCD, it's the same format.Hope it helps

author: Arrow
author_rank: Contributor
timestamp: January 26, 2013, 11:11:35 pm
content: Man, that was impressive , I just tried it with16 bit wordand it works!!!! I mean 11bit.I tried it with 9,10,11, and 12bit. The 12 bit seems not to work. I think I have to do some more thing to make it work. I also discovered that the rule of adding 3 also count if your 3 MSB are more then 5. You have to do this prior the shifting. exampleif you have this 11 bit word 11011111111. The three BCD MSB are 110 . So instead of beginning with shifting you have to change this also, so it become 1001 . It was first 6dec and it became 9 (6+3). Now you can start your shifting with the new word.After 8 shifting it will be 1011110010001 1791 dec

author: Arrow
author_rank: Contributor
timestamp: January 28, 2013, 01:47:31 pm
content: I have add the 9 bit and 11 bit example. The highlighted words are the words that have been added with 3.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 28, 2013, 07:47:36 pm
content: No to adding 3 before you start shifting.You shift, check, shift, check, shift, checkIF you follow the algorithm, it works.If you do it on paper, the last shift moves the result one place PAST(to the left of) the msb of the number you started with, on your diagram you still have the last 3 bits or the result sitting under the 3 msb's of the original number.I just tried it with 16 bits and there are no probs

author: Arrow
author_rank: Contributor
timestamp: January 28, 2013, 08:40:25 pm
content: Quote from: Mr Smiley on January 28, 2013, 07:47:36 pmIf it is not to much asking can you do it with this 12 bit word so I can see?1 0 1 1 1 1 1 1 1 1 1 1

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 28, 2013, 08:53:31 pm
content: Hi,No probs... But, how did you do your table ?

author: Arrow
author_rank: Contributor
timestamp: January 28, 2013, 10:02:44 pm
content: I think I got it right now!!! check!! for 9 bit and 12 bit. No need to write the code. Thanks anyway!!!I give thanks to all who gave their support!!!And now is time to write the code. I hope that it will not be a nasty code.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 29, 2013, 12:56:42 am
content: Hi,Did the table before you replied.It's a pdf, it shows all lines from start to finish so anybody can follow it.< indicates line shifted left,+ indicates result after adding 3.It's the example you requested 10111111111Software should be a doddle, as an example for an 8 bit binary number, two 8 bit registers, one holding the binary the other the result, clear the carry, left shift binary into carry, left shift carry into result, add 0x0b and save in a temp register, if DC flag is set add 0x03, then add 0xb0, save result in temp register, if DC flag set add 0x30 to the result, clear the carry, left shift binary into carry, left shift carry into result, loop for 8,,,, DONE

author: Arrow
author_rank: Contributor
timestamp: January 29, 2013, 02:52:36 am
content: Great man, thanks,Tomorrow I will start with the code.

author: Arrow
author_rank: Contributor
timestamp: January 29, 2013, 02:54:41 am
content: Quote from: amyk on January 25, 2013, 08:18:49 pmThe mcs51 can do all arithmetic function, it can also divide. So tomorrow I will also try the conversion with the divider code. And see which fits me best

author: Arrow
author_rank: Contributor
timestamp: January 29, 2013, 07:09:16 pm
content: I think it will not be possible to use the divide algorithm because the 12 bit is divide between two registers.Any comment on this?

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 29, 2013, 10:27:19 pm
content: It's just 16 bit binary mathsif your using asm, it your using C you use long int.In asm you just have to pass any carry's over to the top 8 bit register, everything is in the carry

author: Arrow
author_rank: Contributor
timestamp: January 31, 2013, 10:28:23 pm
content: I'm busy with ASM code, shifting and adding, it will be a universal code it handles 2 to 16 bit it convert all to BCD. When I finish I gonna check the divide code.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: February 03, 2013, 04:02:14 pm
content: Hi,Divide just as easy, just watch your carry's.Clear answer file,clear carryshift multiplier right into carryif carry set add the number your multiplying to the answer, don't forget any carry'sif it's not set don't add multiplier to your answerclear carryshift number your multiplying one to the left ( remember to pass on any carry's)do all the above till all your multiplier bits have been checkedfinished.