convert int to 4 binary numbers and display at glcd

General discussion on mikroC.
Post Reply
Author
Message
saharul
Posts: 489
Joined: 08 Jul 2010 08:11

convert int to 4 binary numbers and display at glcd

#1 Post by saharul » 09 Jan 2019 08:54

Hi, can anybody share idea to write code on how to convert the integer to only four binary numbers and display it to GLCD.
I tried below code, but it displayed more than 4 binary numbers with unknown character.

for declaration

Code: Select all

bit tmp_bit;
char txt[var_size ]; //+ 1 One byte for zero terminating character.
char txt1[var_size ];
char txt_tmp[4]; 

Code: Select all

     var_num=8;
  for( i = 0 ; i < var_size ; i++ ) {
    tmp_bit = var_num;                  // tmp_bit takes last bit of var_num
    ByteToStr(tmp_bit, txt_tmp);        // converting bit to string
    txt[var_size - 1 - i] = txt_tmp[2]; // placing char to the appropriate place in string
    var_num >>= 1; } chrom[1]=txt;]
for display

Code: Select all

Glcd_Fill(0x00);                             // Clear GLCD
    Glcd_Set_Font(font5x7, 5, 7, 32);            // Change font
       // ByteToStr(txt, tErr); //floatToStr(value,tErr);
     //Glcd_Write_Text( "b" , 5, 6, 2);                // Write string
    //Glcd_Write_Text( txt , 15, 6, 2);
    //ByteToStr(chrom[1], tErr); //floatToStr(value,tErr);
     Glcd_Write_Text( "c" , 5, 0, 2);                // Write string
    Glcd_Write_Text( chrom[1] , 27, 0, 2);
    //ByteToStr(chrom1[1], tErr); //floatToStr(value,tErr);
     Glcd_Write_Text( "d" , 67, 0, 2);                // Write string
    Glcd_Write_Text( chrom1[1] , 87, 0, 2);     
Many thanks

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: convert int to 4 binary numbers and display at glcd

#2 Post by stefan.filipovic » 10 Jan 2019 12:47

Hi,

You have to convert a binary number to the array of characters, and then display this string on the GLCD.

I believe that the solution is on this topic:
viewtopic.php?f=13&t=74000&p=296405#p296405

Kind regards,
Stefan Filipović

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: convert int to 4 binary numbers and display at glcd

#3 Post by saharul » 11 Jan 2019 01:28

Many thanks Stefan

:D :D :D

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: convert int to 4 binary numbers and display at glcd

#4 Post by stefan.filipovic » 11 Jan 2019 10:56

Hi,

You're welcome.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroC General”