This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

unable to write and read an alphabet from location (0xFF01) & then increment the location

I am using 16x2 lcd display and C8051F120 kit.I am using keil compiler.I have taken an array of size 26 as p[26]={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

I want to select an alphabet from array,write it at location (0xFF01) of flash memory ,read it from same location and then display it on lcd.Next,I want select another alphabet,write it at next location ,read it and then display it.Likewise <i repeat doing so till I form a suitable string of variable length.
could you please let me know how can I write an alphabet in flash memory.

Parents
  • No, no, no, NO!

    A is a character, not an alphabet.
    B is a character, not an alphabet.
    C is a character, not an alphabet.

    The union of A, B, C, ... Z represents an alphabet containing 26 characters.

    The next thing is that the character 'A' in the ASCII encoding has the numeric value 65. The character 'B' has the value 66. The character 'C' has the value 67.

    So you do not need to store the individual characters in memory. Why?

    If you get the numeric value 65 from a serial port, that value represents an 'A'. And if your display is only a tiny bit normal, it will also make use of ASCII and know that when it receivers the numeric value 65, it should display the graphical form of an 'A' at the current cursor position.

    But notice that the ASCII character table has the characters numbered in the normal sort order. So you do not need a lookup table to increment from a 'I' to a 'J'. If you add 1 to the numeric value of an 'I', you will get the numeric value of a 'J' - and can send this value to the display to show a 'J'.

    Another thing. You wrote in your code:

    lcddata(p[i]);  //to send array to lcd.
    


    You are not sending any array. You are sending a single character. So your comment is wrong. An incorrect comment is worse than a missing comment.

    idx = 0;
    for (;;) {
        lcdcmd(0xC0);        // Clear the display
        lcddata('A' + idx);  // Send current character
        do {
            key = get_key();
        } while (key == KEY_NONE);
        switch (key) {
            case KEY_UP:
                idx = (idx+1) % 26;
                break;
            case KEY_DOWN:
                idx = (idx+26-1) % 26;
                break;
            default:
                // Some other key pressed.
                ;
        }
        delay(1000);
    }
    

Reply
  • No, no, no, NO!

    A is a character, not an alphabet.
    B is a character, not an alphabet.
    C is a character, not an alphabet.

    The union of A, B, C, ... Z represents an alphabet containing 26 characters.

    The next thing is that the character 'A' in the ASCII encoding has the numeric value 65. The character 'B' has the value 66. The character 'C' has the value 67.

    So you do not need to store the individual characters in memory. Why?

    If you get the numeric value 65 from a serial port, that value represents an 'A'. And if your display is only a tiny bit normal, it will also make use of ASCII and know that when it receivers the numeric value 65, it should display the graphical form of an 'A' at the current cursor position.

    But notice that the ASCII character table has the characters numbered in the normal sort order. So you do not need a lookup table to increment from a 'I' to a 'J'. If you add 1 to the numeric value of an 'I', you will get the numeric value of a 'J' - and can send this value to the display to show a 'J'.

    Another thing. You wrote in your code:

    lcddata(p[i]);  //to send array to lcd.
    


    You are not sending any array. You are sending a single character. So your comment is wrong. An incorrect comment is worse than a missing comment.

    idx = 0;
    for (;;) {
        lcdcmd(0xC0);        // Clear the display
        lcddata('A' + idx);  // Send current character
        do {
            key = get_key();
        } while (key == KEY_NONE);
        switch (key) {
            case KEY_UP:
                idx = (idx+1) % 26;
                break;
            case KEY_DOWN:
                idx = (idx+26-1) % 26;
                break;
            default:
                // Some other key pressed.
                ;
        }
        delay(1000);
    }
    

Children
  • May be my comments are wrong but when I send the data to lcd it shows characters.But,i am not able to write it at location (0xFF01 ),read from same and then display on the lcd. could you tell me what is this symbol '%' in the code which you sent to me.I am not able to get it.selecting a character each time I want to form a string of variable length.I want to write ,read the characters in flash memory location starting at (0xFF01).

  • could you tell me what is this symbol '%' in the code which you sent to me
    that makes it crystal clear that you desperately need to read a 'C' book. in mine it is in chapter 2

    Erik