It is currently 20 Apr 2018 15:05

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 08 Nov 2017 09:18 
Offline

Joined: 08 Nov 2017 08:48
Posts: 3
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.


Top
 Profile  
 
PostPosted: 08 Nov 2017 15:44 
Offline
mikroElektronika team
User avatar

Joined: 02 Feb 2017 14:21
Posts: 780
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.
memset(yourArray,0,7);


Best Regards,

_________________
Dusan Poluga.


Top
 Profile  
 
PostPosted: 09 Nov 2017 06:04 
Offline

Joined: 08 Nov 2017 08:48
Posts: 3
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.


Top
 Profile  
 
PostPosted: 09 Nov 2017 15:30 
Offline
mikroElektronika team
User avatar

Joined: 02 Feb 2017 14:21
Posts: 780
Hi,

Try using our library functions for printing out the characters.
Here is a usage example.
  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.


Top
 Profile  
 
PostPosted: 10 Nov 2017 10:02 
Offline

Joined: 08 Nov 2017 08:48
Posts: 3
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 :( .


Attachments:
hardware.JPG
hardware.JPG [ 51.63 KiB | Viewed 202 times ]
simulation.JPG
simulation.JPG [ 160.77 KiB | Viewed 202 times ]
Top
 Profile  
 
PostPosted: 13 Nov 2017 17:57 
Offline
mikroElektronika team
User avatar

Joined: 02 Feb 2017 14:21
Posts: 780
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.
Lcd_Out(/*row*/,/*column*/,yourArray);


Best Regards,

_________________
Dusan Poluga.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: