Hi fellas,
I'm totally new to MicroC IDE but I managed to do things. I'm using LCD and tried to display integer.
1.I'm getting the number in LCD but with extra garbage values. How to remove those?
Code::
void LCDdata (unsigned char value)
{
RS=1;
RW=0;
TRISD = 0;
DATALCD = value;
E=1;
LCDDelay();
LCDDelay();
E=0;
}
void StringtoLCD(unsigned char *m)
{
while(m)
LCDdata(*m++);
}
void main(){
int i=4203;
char txt[7];
LCDinit();
LCDdelay();
while(1){
LCDcmd(0x01);
LCDcmd(0x02);
IntToStr(i,txt);
StringtoLCD(txt);
LCDdata('G');
}
}
2. Also if i used ByteToStr(), the maximum number obtained is 255 and beyond 256,it gives wrong answer. While for IntToStr() upto 19000, I'm getting correct values (I hope it will be correct up to 65535). Why is this? Can someone explain this?
3.Also if i use "const" in StringtoLCD attributes, I'm not getting correct answer. Please explain why is that also.
How to remove extra garbage values from IntToStr(int,str)?
- dusan.poluga
- mikroElektronika team
- Posts: 780
- Joined: 02 Feb 2017 14:21
Re: How to remove extra garbage values from IntToStr(int,str
Hi,
IntToStr function converts signed integers to string.
You should get correct values to this number 32767. I am not aware what is happening in your case.
To get the range from 0 to 65535 you need to use WordToStr function instead of IntToString.
If you want to clear the array before you input new data to it you can use the memset function.
Usage of the memset function is shown below.
Best Regards,
IntToStr function converts signed integers to string.
You should get correct values to this number 32767. I am not aware what is happening in your case.
To get the range from 0 to 65535 you need to use WordToStr function instead of IntToString.
If you want to clear the array before you input new data to it you can use the memset function.
Usage of the memset function is shown below.
Code: Select all
memset(yourArray,0,7);
Dusan Poluga.
Re: How to remove extra garbage values from IntToStr(int,str
Hi dusan.poluga,
Thanks for your first point about the size of unsigned int man. Now I'm clear about that part (question #2). But the problem with garbage(q #1) is like, if the output is like "23" followed by "G".it prints like
23.....garbage values (beyond 16th charater) 1st line
#BLANK + garbage (beyond 16th charater) 2nd line
#BLANK + garbage (beyond 16th charater) 1st line
#BLANK + garbage (beyond 16th charater) 2nd line
Again continues from top,as I used while(1).
So the "G" might be lost somewhere behind 16th character. Someone please help me out.
Thanks for your first point about the size of unsigned int man. Now I'm clear about that part (question #2). But the problem with garbage(q #1) is like, if the output is like "23" followed by "G".it prints like
23.....garbage values (beyond 16th charater) 1st line
#BLANK + garbage (beyond 16th charater) 2nd line
#BLANK + garbage (beyond 16th charater) 1st line
#BLANK + garbage (beyond 16th charater) 2nd line
Again continues from top,as I used while(1).
So the "G" might be lost somewhere behind 16th character. Someone please help me out.
- dusan.poluga
- mikroElektronika team
- Posts: 780
- Joined: 02 Feb 2017 14:21
Re: How to remove extra garbage values from IntToStr(int,str
Hi,
Try using our library functions for printing out the characters.
Here is a usage example.
Try using our library functions for printing out the characters.
Here is a usage example.
Code: Select all
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1)
{
number++;
WordToString(number,yourArray);
Lcd_Out(1,6,yourArray); // print values converted by
Delay_ms(100);
}
Dusan Poluga.
Re: How to remove extra garbage values from IntToStr(int,str
Hi dusan.poluga,
I hope for that inbuilt library, it will definitely. But I just want to know what is the problem here and to fix it. Meantime I tried with UART,but surprising I got output correctly in simulation (Proteus) while in case of hardware,I'm getting but the value is not updated right from the starting. It gives correct reading at the very beginning and it keep on giving that one only. I've attached the pics of those as follows.
PS:Still LCD is not working,by the way,I'm worried about it .
I hope for that inbuilt library, it will definitely. But I just want to know what is the problem here and to fix it. Meantime I tried with UART,but surprising I got output correctly in simulation (Proteus) while in case of hardware,I'm getting but the value is not updated right from the starting. It gives correct reading at the very beginning and it keep on giving that one only. I've attached the pics of those as follows.
PS:Still LCD is not working,by the way,I'm worried about it .
- Attachments
-
- hardware.JPG (51.63 KiB) Viewed 2102 times
-
- simulation.JPG (160.77 KiB) Viewed 2102 times
- dusan.poluga
- mikroElektronika team
- Posts: 780
- Joined: 02 Feb 2017 14:21
Re: How to remove extra garbage values from IntToStr(int,str
Hi,
You need to send the command that will reset the position from where you will start to write your next sequence of characters.
I am not seeing that you are doing that in your code above.
If you look at our library function it is doing just that at the begging of every write.
Best Regards,
You need to send the command that will reset the position from where you will start to write your next sequence of characters.
I am not seeing that you are doing that in your code above.
If you look at our library function it is doing just that at the begging of every write.
Code: Select all
Lcd_Out(/*row*/,/*column*/,yourArray);
Dusan Poluga.