Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Display Numbers on LCD Mikroc

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
207
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,068
I am using MikroC compiler and PIC16F877. I have tried almost all C compilers but I found Mikroc to be the best compiler.
My question is it is very simple to display characters on LCD but I want to display numbers or integer to be displayed on LCD.
for example

int x;
x = 25
lcd_out(1,1,x);

note that this is not actual program it is just for example.
 

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
207
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,068
I tried this code:
void main() {

char txt[4];
int t;
t=255;
ByteToStr(t, txt);
LCD_Out(1,1,txt);

but the problem is that when value of t is bigger than 255 the no resets to 0.
I also tried long int t but nothing happened. and when I type long char txt[4] it is giving error.
 

rajudp

Advanced Member level 2
Joined
May 27, 2006
Messages
643
Helped
123
Reputation
246
Reaction score
96
Trophy points
1,308
Location
India
Activity points
4,055
try
WordToStr(t, txt);


IntToStr(t, txt); for bigger
 

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
207
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,068
Raj you really helped me thanks. Don't mind it if I ask you last two questions.
What is purpose of no in square brackets txt[4] what I learned in C it is an array. Why not it is simply char txt
second below is my program code and output is in image. Can you tell me why there are spaces in second row of LCD.


---------- Post added at 02:35 ---------- Previous post was at 02:34 ----------

void main() {

char txt[6];
int t;
t=255;
ByteToStr(t, txt);
delay_ms(500);
LCD_Out(1,1,txt);

t = 256;
wordToStr(t, txt);
delay_ms(500);
LCD_out(2,1,txt);

}
 

shihab_leo

Member level 1
Joined
Mar 5, 2009
Messages
39
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,288
Activity points
1,508
1. functions like IntToStr() and WordToStr() convert numbers into strings so to store that string, you need to declare a string first which, in C, is an array of characters.
2. These functions convert numbers into a string of fixed length and add spaces to the left if the number is small. you can get rid of those spaces using Ltrim()
try
Lcd_Out(2, 1, Ltrim(txt));

---------- Post added at 23:31 ---------- Previous post was at 23:28 ----------

if you have any confusions about the Library functions of mikroC, just double click the function name in the library manager. it will show you the detailed documentation of that function.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top