1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Unicorn GLCD demo.

Discussion in 'Microcontrollers' started by Pommie, Jun 20, 2007.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Try the inbuilt function "sprintf()" I know it takes up room but allows you to take a constant and place it in a stream (buffer) for easy manipulation... C18 isn't all that good when casting " rom char* " or even just " const char* "
     
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    Unfortunately, the inbuilt "sprintf()" doesn't know anything about GLCDs or for that matter, normal LCDs.

    Mike.
     
  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    To the problem of printing an integer on the screen,

    Firstly, itoa needs a buffer and so we need to add,
    Code (text):

    unsigned char Buffer[10];
     
    Now, we can convert our integer into a string with,
    Code (text):

        TestInt=12345;
        itoa(TestInt,&Buffer[0]);
     
    Note, we have to send the address of our buffer hence the &.

    And finally print it with,
    Code (text):

        i=0;
        while(Buffer[i])
            PutChar(Buffer[i++]);
     
    Note that we can't use the PutMessage routine as it expects the string to be in rom and ours is in ram.

    HTH

    Mike.
     
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France

    Thanks Pommie, it works now.
    I've forgotten to declare the ascii variable as a table instead of a character. :rolleyes:

    By the way, i've tried to modify PutString function in order to display the result with smaller or larger fonts : i've just replaced PutChar by PutSmallChar or PutHChar but i get outstanding display.

    Can you tell me why PutString is not compatible with other fonts ?
    Is it easy to add new fonts to the GLCD driver, i need a small characters font and another one with large ones.

    Code (text):
    void PutSmallChar(unsigned char data){
    unsigned char i,d;
            if(data<32){
                    switch(data){
                            case 13:
                                    XPos=0;
                            case 10:
                                    XPos=0;
                                    YPos+=8;
                                    YPos=YPos&63;
                    }
                    WritePosition();
            }
            else{
                    for(i=0;i<7;i++){
                            d=FontSmall[data-48][i];
                            if(d!=0x55){
                                    //d=~d;                // Black on white
                                    GLCD_Write_Data(d);
                                    MoveRight();
                            }
                    }
                    GLCD_Write_Data(0x00);                 // Black on white
                    //GLCD_Write_Data(0xff);               // White on black
                    MoveRight();
            }
    }

    Code (text):
    void PutHChar(unsigned char data){
    unsigned char i,d;
            if(data<32){
                    switch(data){
                            case 13:
                                    XPos=0;
                            case 10:
                                    XPos=0;
                                    YPos+=8;
                                    YPos=YPos&63;
                    }
                    WritePosition();
            }
            else{
                    for(i=0;i<8;i++){
                            d=Font18[data-46][i];
                            if(d!=0x55){
                                    GLCD_Write_Data(d);
                                    MoveRight();
                            }
                    }
                    MoveDown ();
                    for(i=8;i<16;i++){
                            d=Font18[data-46][i];
                            if(d!=0x55){
                                    GLCD_Write_Data(d);
                                    MoveRight();
                            }
                    }
                    GLCD_Write_Data(0x00);                //Black on white
                    MoveRightH();
            }
    }
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    New fonts should work fine but remember, they are stored different to most fonts. The first character is the left hand column with the LSB at the top of the column. They're also stored inverted.

    So, doing,
    Code (text):

        GLCD_Write_Data (0xf1);
        GLCD_Write_Data (0xf5);
        GLCD_Write_Data (0xf1);
     
    Will give you a little box (3x3) 1 pixel down from the top.

    Because those numbers represent,
    Code (text):

    111    LSB
    000
    010
    000
    111
    111
    111
    111   MSB
    ^-----0xf1
    -^----0xf5
    --^---0xf1
     

    Mike.
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Mike.... I know that.. but it was a question of trying to print a string literal..... if the string is a constant.... it's not so easy to cast as a variable.... All I was saying was convert the string first with sprintf();

    This is exactly what you are doing in post #343..... Manually!!
     
  8. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France
    Pommie,

    I do not understand well how PutSmallChar and PutHChar works depending of the font size.
    Would you please comment the functions for me, it would help me a lot.

    If a convert a windows true type font with a software, then what should adapt in Putchar function in order to use that font with the GLCD ?
    Do you have other fonts + functions ready to go, if so could you post them here ?

    Many thanks
     
  9. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Variable width and height fonts are not easy to do. I have implemented a simple 1bpp graphics library which you can find here:

    Code: https://github.com/edeca/Electronics/tree/master/Include
    Docs: http://edeca.net/temp/Documentation/html/graphics_8h.html

    This can take Windows TTF fonts (converted using a utility) and display them. Results look like this:

    View attachment 60761

    Please note that the example picture is running on a different screen. I haven't ported it to Pommie's GLCD code yet but all it needs is a compliant glcd_pixel function, so that would take a few minutes at most.

    I was hoping to finish off the documentation this weekend and post some example code.
     
  10. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France
    Thanks edeca, but are these fonts compatible with Pommie's GLCD driver ?

    In your fonts, the definition of each character looks very different as the font included in the Pommie's library.
     
  11. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    It would not take long to port this to the KS0108 controller. However I have not done this yet (as it says above). You cannot just copy and paste the fonts from my code to Pommie's and expect it to work.
     
  12. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
  13. neelam29

    neelam29 New Member

    Joined:
    Nov 15, 2005
    Messages:
    105
    Likes:
    0
    thanks pommie for your code. everything is going good (Logo, Lines, Box) but when I try to write text it dosen't come on right location. Like simply if i try:-

    SetPos(0,2);
    PutMessage((rom char*)"Hello");


    it would display "Hello" but at (0,0). If I set (10,5) it comes on(10,0) If I try (10,9) it comes on (10,8), it's only taking multiple of 8 steps in vertical coordinates. I haven't changed anything still can't understand why this is happening. I have tried this also:- PutMessage((rom char*)"\x16\x10\x05 Hello");

    please help me out.
     
    Last edited: Mar 30, 2012
  14. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    Yes, it only puts characters on byte boundaries. It could be rewritten to make it cross byte boundaries but that is quite difficult.

    Mike.
     
  15. neelam29

    neelam29 New Member

    Joined:
    Nov 15, 2005
    Messages:
    105
    Likes:
    0
    thanks anyway.
     
  16. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    I have done that (see http://edeca.net/temp/Documentation/html/graphics_8h.html and https://github.com/edeca/Electronics/tree/master/Include) but not had time to write the KS0108 driver code yet.

    Note that rewriting the code to work like this makes it much slower and much less efficient, this can't really be avoided. Pommie's code is the best way to draw text if you want speed and smaller code size.
     
  17. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    If I get bored over the weekend I may get around to modifying it to write at any pixel position.

    Mike.
     
  18. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France
    Hello Pommie,

    I use your GLCD driver and i need a very small font.

    I've tried to import a Truetype font but the result is not good ! (missing pixels, some characters are getting shifted )

    I've tried many GLCD font generator without success, maybe some of them are not compliant with your code ?
    Is there a method to get a Truetype font working with your GLCD driver ?

    If not, did you create one by chance and you will be willing to share it here ?

    Thanks,
     
  19. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    You could use a smaller font but it would probably have to be drawn by hand. You would also need to rewrite the putchar routine to work on pixel boundaries.

    I have got a font that is 5 by 3 pixels that was used on another project. See attachment.

    Mike.
     
  20. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France
    Thanks,

    I've tried to display some character from this font with the original Putchar function.
    But i get outstanding and unreadable characters.

    I have modified the original Putchar function as below ( shifted 4 pixels down after each character )

    Code (text):
    void PutChar(unsigned char data){
    unsigned char i,d;
            if(data<32){
                    switch(data){
                            case 13:
                                    XPos=0;
                            case 10:
                                    XPos=0;
                                    YPos+=4;       
                                    YPos=YPos&63;
                    }
                    WritePosition();
            }
            else{
                    for(i=0;i<7;i++){               //7
                            d=Font_3[data-32][i];
                            if(d!=0x55){
                                    d=~d;                                // ADD pour Noir sur Blanc
                                    GLCD_Write_Data(d);
                                    MoveRight();
                            }
                    }
                    GLCD_Write_Data(0x00);                               // Noir sur Blanc
                    //GLCD_Write_Data(0xff);                             // Blanc sur Noir
                    MoveRight();
            }
    }
     
    Last edited: Apr 27, 2012
  21. crocu

    crocu Member

    Joined:
    Feb 20, 2009
    Messages:
    118
    Likes:
    1
    Location:
    France
    Hello Pommie

    Can you tell me what i should modify in the PutChar function in order to use the small font you've posted ?

    I can't get it working.

    Many thanks,
     

Share This Page