Is there a way to display a byte on LCD, so you can actually see it?
it's not part of a project,
just for educational purposes
Thanks
can I see a byte?
Re: can I see a byte?
OK so you were probably expecting an explanation. I'll try, but some of the local experts can do a better job.
A byte is just 8 bits of data (1's and 0's).
The LCD typically requires you to send the data as a byte (an ASCII byte in most cases).
So if your byte is 0x21 that corresponds to the decimal number 33 or the ASCII character "!".
Now, lets assume that the byte you want to keep track of is some counting value and that value has reached 114. If you send that byte to the LCD it will show "r" on the LCD. This is probably not helpful. One of the cool functions that mE provides is ByteToStr(consult the help file). This allows you to take some byte and convert it to easily display the decimal value is ascii. So you will now have a string of characters that represents "114" .
Hopefully that helps.
A byte is just 8 bits of data (1's and 0's).
The LCD typically requires you to send the data as a byte (an ASCII byte in most cases).
So if your byte is 0x21 that corresponds to the decimal number 33 or the ASCII character "!".
Now, lets assume that the byte you want to keep track of is some counting value and that value has reached 114. If you send that byte to the LCD it will show "r" on the LCD. This is probably not helpful. One of the cool functions that mE provides is ByteToStr(consult the help file). This allows you to take some byte and convert it to easily display the decimal value is ascii. So you will now have a string of characters that represents "114" .
Hopefully that helps.
Re: can I see a byte?
I have never seen a byte. I have seen the value of a byte in many formats: in binary, in hex, in decimal, in BCD and in ascii, so I know a byte actually exists.Olivia wrote:Is there a way to display a byte on LCD, so you can actually see it?
it's not part of a project,
just for educational purposes
Thanks
Anyway, to see the value of a byte you will have to convert it to a format that the LCD can handle, and this is the character/string format.
In the library set of the different compilers one can fins several conversion routines to convert the value of a byte to a string that can be sent to the LCD, e.g. "bytetostr" (example from mikroPascal).
have fun!
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: can I see a byte?
I was thinking if it is possible to put on dispaly a byte, let's say 0b10011011
I know you can put the same in hex on display 0x9B
But is there a function that will convert the hex being transmitted to the LCD so it will be displayed as 0b10011011?
And if the original message read from the chip was in binary (0b10011011) why should I tranform it into hex, then back into binary so I can see it on the LCD as I want?
I thought I can take the original binary reading and using a function or a magical crystall ball, I can put it on LCD to see it.
You know, like in the Matrix!!!
Well almost. Not top to bottom, but left to right.
Regards.
I know you can put the same in hex on display 0x9B
But is there a function that will convert the hex being transmitted to the LCD so it will be displayed as 0b10011011?
And if the original message read from the chip was in binary (0b10011011) why should I tranform it into hex, then back into binary so I can see it on the LCD as I want?
I thought I can take the original binary reading and using a function or a magical crystall ball, I can put it on LCD to see it.
You know, like in the Matrix!!!
Well almost. Not top to bottom, but left to right.
Regards.
Re: can I see a byte?
Yes, in the "Conversions" library of Yo2Lio (Florin) there is a "Byte2Bin" routine, which transforms the value of a byte to a string displayable on LCD. See http://www.mikroe.com/forum/viewtopic.php?t=21871 (for Pascal, but I think there is one for C too).Olivia wrote:I thought I can take the original binary reading and using a function or a magical crystall ball, I can put it on LCD to see it.
Otherwise you can use the following code: after translation to C:
Code: Select all
procedure ByteToBinStr(Value: byte; var S: string[8]);
var I: byte;
begin
I := 0;
while I < 8 do
begin
if Value.I = 0
then S[7 - I] := '0'
else S[7 - I] := '1';
Inc(I);
end;
S[8] := 0; // terminator
end;
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: can I see a byte?
Thought you would say that.MikroC_888 wrote:Besides the fact that C code is easier-to-read and forces the programmer to think "structured code" ...
Please do not spoil this thread.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: can I see a byte?
I have just written the same procedure in mikroBasic
Code: Select all
sub procedure ByteToBin(dim InByte as byte, dim byref OutStr as string[8])
dim cnt as byte
for cnt = 0 to 7
if InByte.cnt = 1 then
OutStr[7 - cnt] = "1"
else
OutStr[7 - cnt] = "0"
end if
next cnt
OutStr[8] = 0
end sub
Re: can I see a byte?
There you go :
Code: Select all
/*
* Project name:
Lcd_Test (Simple demonstration of the LCD Library functions)
* Copyright:
(c) Mikroelektronika, 2005.
* Description:
This is a simple demonstration of LCD library functions. LCD is first
initialized (PORTD, 4-bit data interface, default pin settings), then some
text is written at the first row.
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC4
Oscillator: HS, 08.0000 MHz
Ext. Modules: LCD 2x16
SW: mikroC v8.2
* NOTES:
None.
*/
//----------------------------------------------------------------------------
void lcd_out_bin (unsigned char value)
{
char i,*text;
for(i=0;i<=7;i++)
{
if(value&(1<<i)) text[7-i] = '1' ;
else text[7-i] = '0' ;
}
text[8] = 0;
lcd_out(2,1,"0b");
lcd_out(2,3,text);
}
//----------------------------------------------------------------------------
void main()
{
LCD_Init(&PORTD); // Initialize LCD connected to PORTD
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
lcd_out(1,1,"0xf0") ;
lcd_out_bin(0xf0) ;
}