Binary number on lcd

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Binary number on lcd

Post by dazz »

Hi
Im having a play with eeprom reads etc trying to get my head around it ,my issue is i can display the eeprom adedress, contents in decimal and hex, binary via led's im trying to get the binary to display on lcd but im getting the number backwards on the lcd ie 00000001 shows as 10000000 etc , i cant seem to get it the right way round, can someone give me some pointers
Attachments
eeprom read.fcf
(20.34 KiB) Downloaded 308 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Binary number on lcd

Post by medelec35 »

Hi dazz,
I have altered your flowchart so binary is displayed the other way round.

Martin
Attachments
eeprom read1.fcf
(20.52 KiB) Downloaded 315 times
Martin

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Binary number on lcd

Post by dazz »

Hi martin
many thanks , im going to be cheeky now can you explain how you got it working as im at a loss, i understand the shift variable =128 which is the max binary number, what i cant get my head around is how it inverts the number to display correctly
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Binary number on lcd

Post by medelec35 »

Hi dazz, No I don't think asking is cheeky :)

If you have a number e.g 5 then AND it with a number that's used to make up 5 but uses the power of two (i.e 4,1) , then result will always be that same number your ANDing the 5 with.
In this example 5 AND 4 = 4, 5 AND 1 = 1. 5 AND any other value = 0
So in effect the AND is determine if the number in question contains any number to the power of 2.
I started with 128 since you wanted Most significant bit(MSB) first and 128 is MSB
so

Code: Select all

5 AND 128 = 0. Is result >0?....No, so result  = 0
>>1= shift one place to the right = same as dividing by 2 = 64  
5 AND 64 = 0. Is result >0?....No, so result  = 0
>>1
5 AND 32 = 0. Is result >0?....No, so result  = 0
>>1
5 AND 16 = 0. Is result >0?....No, so result  = 0
>>1
5 AND 8= 0. Is result >0?....No, so result  = 0
>>1
5 AND 4 = 4. Is result >0?....Yes, so result  = 1
>>1
5 AND 2 = 0. Is result >0?....No, so result  = 0
>>
5 AND 1 = 1. Is result >0?....Yes, so result  = 1
You should now see how the binary pattern is formed.

Hopefully I have explained it Ok?

Martin
Martin

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Binary number on lcd

Post by dazz »

hmm
i got it just :lol: , christ alive i went off searching for twos compliment and power of 2(got to be nearly 30 years since i did any of that at tech college) and can honestly say i was as confused as a monkey on crack reading a charles dickens novel, so i then opened windows calc in programmer mode and started typing in your numbers now it all makes sense, even your changing the decision in the binary macro from 1 to >0. once again many thanks, im finding learning this stuff addictive. so im going to keep my flowchart as a reference, and modify it to display numbers in bin,dec and hex based on input, and an additional digit to display ascii characters(which i had fun playing with whilst writing my chart, so rather than use windows calc i simply start up my chart and have all that info to hand
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Binary number on lcd

Post by medelec35 »

Ah that's good. Glad you can decipher my wording enough, to be able to understand it :lol:

As for hex conversions have you seen this:?
http://www.matrixmultimedia.com/mmforum ... 394#p24449

Martin
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Binary number on lcd

Post by Spanish_dude »

Hello,
I have a solution too, but Martin's solution is much much easier to understand for beginners.

So your problem was that the LSB was written first and the MSB last. This is because you get the first bit first and then write it on the display. Then you get the second one and write it on the display at position X+1 (X+1 is done automatically by the LCD).
So this is what I would do to solve it (whithout adding a variable):
Instead of doing "Binary = Eeprom_Value & 0x01" and then "Eeprom_Value = Eeprom_Value >> 1".
I did "Binary = !!(Eeprom_Value & 0x80)" and then "Eeprom_Value = Eeprom_Value << 1".

The Eeprom_Value & 0x80 will get the highest bit in the Eeprom_Value variable. The two '!' are to convert the 8 bit value to a boolean value (1 or 0, true or false).
One '!' means a bytewise NOT.
This little calculation can be done with an if-statement like so :
if ((Eeprom_Value & 0x80) == 0) // If the MSB is equal to 0
Binary = 0; // write 0
else
Binary = 1; // else write 1

Then instead of shifting the bits to the right, I shift them to the left.

Nicolas

PS: I tested this on your program and it seemed to work ;).

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Binary number on lcd

Post by dazz »

cheers spanish dude
Thats 2 solutions that are great,i worked out this bit the other day (Eeprom_Value & 0x80)" ( from martins post) and then "Eeprom_Value = Eeprom_Value << 1 . thanks for explaining the !! now i know that it will make things easier as theres so many ways to do this stuff again many thanks
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Post Reply