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.

a single charcter displaying in lcd using pointer

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,602
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Visit site
Activity points
10,625
hello experts ,
I want to display "*" in the following codes - for memory reduction please help me
Code:
switch (keyCode) //generating key characeter to display on LCD
        {
            case (11):
            string("1");    [COLOR=#ff0000] // want change  string(*g);    *g contain star "*"[/COLOR]
            dis_cmd(k++);
            key[x]=1;
            x++;
            pos++;
            break;
            
            
            case (10):
            //dis_cmd(k++);
            string("2");        [COLOR=#ff0000]// want change  string(*g);    *g contain star "*"    [/COLOR]
            dis_cmd(k++);
            key[x]=2;
            x++;
            pos++;
            break;
            
            case (9):
            string("3");
            dis_cmd(k++);
            key[x]=3;
            x++;
            pos++;
            break;
            
            case (8):
            string("4"); [COLOR=#ff0000]// want change  string(*g);    *g contain star "*"[/COLOR]
            dis_cmd(k++);
            key[x]=4;
            x++;
            pos++;
            break;
            
            case (7):
            //dis_cmd(k++);
            string("5");     [COLOR=#ff0000]// want change  string(*g);    *g contain star "*"[/COLOR]
            dis_cmd(k++);
            key[x]=5;
            x++;
            pos++;
            break;
            
            case (6):
            string("6");   [COLOR=#ff0000]// want change  string(*g);    *g contain star "*"[/COLOR]
            dis_cmd(k++);
            key[x]=6;
            x++;
            pos++;
            break;
            
            case (5):
            string("7");    [COLOR=#ff0000]// want change  string(*g);    *g contain star "*"[/COLOR]
            dis_cmd(k++);
            key[x]=7;
            x++;
            pos++;
            break;
            
            case (4):
            string("8");
            dis_cmd(k++);
            key[x]=8;
            x++;
            pos++;
            break;
            
            case (3):
            string("9");
            dis_cmd(k++);
            key[x]=9;
            x++;
            pos++;
            break;
            
            case (2):
            //string("*");
            //dis_cmd(k++);
            //key[x]=0;
            //x++;
            //pos++;
            break;

            case (1):
            string("0");
            dis_cmd(k++);
            key[x]=0;
            x++;
            pos++;
            break;

            //case (12):
            //break;
            
            //default: ;
            //loop: ;
        }

        _delay_loop_2(300);

here the string function writes only star "*" . then how to change it
please help me.
thanks
 

Hello!

Some ideas:
- You don't say what the variable x is. You don't specify pos either, but I can more
or less that it's a position somewhere, possibly on the screen
- You don't need the "key" array, because for any value, key[x] = keycode.

So basically (just guessing), you get a key code and you want to display another value.
For 12, display nothing and return, for 11, display 1, for 10, display 2, etc...
Why not writing:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
char str[2];  // This should not be placed in your loop as it does not change
str[1] = 0;  // This should not be placed in your loop as it does not change
 
if((key code < 12) && (ketycode > 2)) {
    str[0] = '0' + 12 - keycode;
    string(str);
    pos++;
}
else if(keycode == 1) {
   str[0] = '0';
    string(str);
    pos++;
}



And you ignore cases 2 (which is commented out) and 12. The str array has 2 characters
because a C string is supposed to be 0 terminated. Now you may also consider a simpler
way than a string, a kind of put char(c) which would write a single char to the screen.
Then if g is a string, you function would write pitcher(*g).

Now for your question, you cannot directly change to something like *g. Your function called string
expects a string, which is usually a pointer to char. You can use string(*g) only if g is a char**.
Then *g would be a char * (and **g a char).
Just a question: if you tell me I want a function that displays one character, I would understand.
Now what is the purpose of changing to string(*g);? Just for the beauty of string(*g);? What is
the final purpose of this change?

Now as a general advice, (please don't think this is rude): think first, or in other words, don't
program first. Look at what you have to do (in this case displaying the value 12 - keycode for
most of the codes, and then put it into code.
The code you wrote is long, subject to bugs. I'm not pretending I am an expert, but at least
the code I wrote and which should do roughly the same thing as yours is about 1/10 the size of
yours.
Besides this, I have another personal "rule", I know that some may not agree, but here it is:
NEVER write a function that takes more than one screen to display. You should be able to see
any function you write in a single page. On a modern screen, this allows you about 50 lines,
which is a lot.
If your function is about to take more than one screen, then split it.

Dora.
 
See the dis_cmd() function> In that you are passing *msg++. You are passing strings instead of *msg++. Whether you use some string like str[] or *str the function which calls should pass a string value like string("1"). If you use *g where will be the strings "1", "2", etc... Yo again have to pass strings like "1", "2", etc... to the function.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top