Author Topic: Writing 13 bit numbers on an LCD display using 8051  (Read 6936 times)

0 Members and 1 Guest are viewing this topic.

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Writing 13 bit numbers on an LCD display using 8051
« on: January 25, 2013, 01:16:58 pm »
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.
 :)
 

Offline ptricks

  • Frequent Contributor
  • **
  • Posts: 672
  • Country: us
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #1 on: January 25, 2013, 01:23:58 pm »
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.
 

Offline Harvs

  • Super Contributor
  • ***
  • Posts: 1204
  • Country: au
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #2 on: January 25, 2013, 01:38:59 pm »
In C it's simple using a division and remainder. I.e.

first_digit = number % 10
number /= 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.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #3 on: January 25, 2013, 02:10:30 pm »
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.
On 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.
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #4 on: January 25, 2013, 02:18:28 pm »
This http://www.atmel.com/Images/doc0938.pdf will show you how convert between binary and BCD. You can use a cut down version of their 16 bit example.
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8415
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #5 on: January 25, 2013, 08:18:49 pm »
On the HD44780 (8bit), you just add 30x to your 8bit number and load it to the LCD, this convert the number to ascii.
That 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.
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #6 on: January 26, 2013, 03:57:47 am »
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.html

After 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 w
andlw 0x0f                                     ;mask out upper 4 bits
addlw 0x30                                   ;convert to ascii
movwf Sdata                                 ;put into sdata ready for RS232 sending
call RS232   

RS232 or LCD, it's the same format.

Hope it helps  :-+

 :)
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #7 on: January 26, 2013, 11:11:35 pm »
Man, that was impressive , I just tried it with 16 bit word and 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. example
if 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


 
« Last Edit: January 28, 2013, 01:05:25 pm by Arrow »
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #8 on: January 28, 2013, 01:47:31 pm »
I have add the 9 bit and 11 bit example. The highlighted words are the words that have been added with 3.
« Last Edit: January 28, 2013, 01:50:32 pm by Arrow »
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #9 on: January 28, 2013, 07:47:36 pm »
No to adding 3 before you start shifting.  :palm:

You shift, check, shift, check, shift, check  :-/O

IF 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  :-+
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #10 on: January 28, 2013, 08:40:25 pm »

I just tried it with 16 bits and there are no probs  :-+

If 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
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #11 on: January 28, 2013, 08:53:31 pm »
Hi,

No probs... But, how did you do your table ?

 :)
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #12 on: January 28, 2013, 10:02:44 pm »
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.  ;)
« Last Edit: January 29, 2013, 02:25:43 am by Arrow »
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #13 on: January 29, 2013, 12:56:42 am »
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 10111111111

Software 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  :-+
« Last Edit: January 29, 2013, 01:05:52 am by Mr Smiley »
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #14 on: January 29, 2013, 02:52:36 am »
Great man, thanks,
Tomorrow I will start with the code.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #15 on: January 29, 2013, 02:54:41 am »

That uC has a multiplier but no divider, so you'll need to do shift-and-subtract for division.
The 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  ;)
« Last Edit: January 29, 2013, 04:11:41 pm by Arrow »
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #16 on: January 29, 2013, 07:09:16 pm »
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?
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #17 on: January 29, 2013, 10:27:19 pm »
It's just 16 bit binary maths  :-+ if 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  :-DMM

 :)
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline ArrowTopic starter

  • Contributor
  • Posts: 42
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #18 on: January 31, 2013, 10:28:23 pm »
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.
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: Writing 13 bit numbers on an LCD display using 8051
« Reply #19 on: February 03, 2013, 04:02:14 pm »
Hi,

Divide just as easy, just watch your carry's.

Clear answer file,
clear carry
shift multiplier right into carry
if carry set add the number your multiplying to the answer, don't forget any carry's  :-/O
if it's not set don't add multiplier to your answer
clear carry
shift number your multiplying one to the left ( remember to pass on any carry's)  :-/O
do all the above till all your multiplier bits have been checked

finished.

 :-+

 :)
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf