Continue to Site

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.

  • 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.

Unicorn GLCD demo.

Status
Not open for further replies.
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* "
 
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* "

Unfortunately, the inbuilt "sprintf()" doesn't know anything about GLCDs or for that matter, normal LCDs.

Mike.
 
To the problem of printing an integer on the screen,

Firstly, itoa needs a buffer and so we need to add,
Code:
unsigned char Buffer[10];

Now, we can convert our integer into a string with,
Code:
    TestInt=12345;
    itoa(TestInt,&Buffer[0]);
Note, we have to send the address of our buffer hence the &.

And finally print it with,
Code:
    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.
 
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:
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:
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();
        }
}
 
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:
    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:
111    LSB
000
010
000
111
111
111
111   MSB
^-----0xf1
-^----0xf5
--^---0xf1


Mike.
 
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!!
 
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
 
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 ?

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: **broken link removed**

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.
 
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.
 
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.

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.

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.
 
Also for those who are still watching this topic after many years, I documented Pommie's code:

**broken link removed**
 
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:
Yes, it only puts characters on byte boundaries. It could be rewritten to make it cross byte boundaries but that is quite difficult.

Mike.
 
Yes, it only puts characters on byte boundaries. It could be rewritten to make it cross byte boundaries but that is quite difficult.

I have done that (see **broken link removed** 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.
 
If I get bored over the weekend I may get around to modifying it to write at any pixel position.

Mike.
 
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,
 
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.
 
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:
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:
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,
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top