Creating custom characters for LCD printing
#1
Posted 17 September 2012 - 08:30 PM
#2
Posted 18 September 2012 - 06:13 AM
I've done that before, for this project:
The code isn't published yet, but the method for the custom characters is this one:
public static void main() { // To play snake on a 2x16 LCD, we need 7 custom characters (0x00 to 0x06): _CustomizeCharacter(0x00, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e, 0x00 }); // b000: ₒ (fruit at the bottom) _CustomizeCharacter(0x01, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }); // b001: ° (fruit at the top) _CustomizeCharacter(0x02, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00 }); // b010: ▀ (snake at the top) _CustomizeCharacter(0x03, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x0e, 0x0e, 0x00 }); // b011: ▀ + ₒ (snake at the top + fruit at the bottom) _CustomizeCharacter(0x04, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b100: ▄ (snake at the bottom) _CustomizeCharacter(0x05, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b101: ▄ + ° (snake at the bottom + fruit at the top) _CustomizeCharacter(0x06, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }); // b110: █ (snake at the bottom + snake at the top) } /// <summary> /// Creates a customized character on a HD44780 LCD /// </summary> /// <param name="Index">Character index (0 to 7)</param> /// <param name="Character">Character bitmap</param> private static void _CustomizeCharacter(int Index, byte[] CharacterBitmap) { if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7"); if (CharacterBitmap.Length != 8) throw new ArgumentOutOfRangeException("CharacterBitmap must have 8 byte values"); _disp.Write((byte)(0x40 + 8 * Index), true); // Set CGRAM Address _disp.Write(CharacterBitmap); // Writes the character _disp.Write(0x80, true); // Set DDRAM Address }Maybe that'll help you?
_disp is an instance of Toolbox.NETMF.Hardware.Hd44780Lcd
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 21 September 2012 - 08:11 AM
#4
Posted 21 September 2012 - 08:30 AM
Thanks!By the way I watched your video, it's really great. I like the idea of using a 2-lines screen and custom characters to use it as a 4-line screen.
I hope to release the code next week
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#5
Posted 21 September 2012 - 08:40 AM
#6
Posted 21 September 2012 - 08:42 AM
Yep, only 8do you know how many custom characters can be set on these LCD screens ?
Hence this line of code:
if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7");
I wish it could do more, but it's still very nice for such cheap displays I reccon.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#7
Posted 21 September 2012 - 09:49 AM
#8
Posted 21 September 2012 - 10:49 AM
That's a good thing to do; dynamically. My app will do that too. While playing the game, it'll contain 8 characters required for the snake, but I will also have a graphical splash screen, composed with 8 other charactersYes, that's what I understood. I need way more than 8 custom chars, but I think I can deal with 8 custom chars displayed at a given time. I think I will do something like redefine the custom chars dynamically. should work
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#9
Posted 21 September 2012 - 11:26 AM
#10
Posted 22 September 2012 - 08:12 AM
Lcd.WriteBigCharacters("14");
- Arron Chapman likes this
#11
Posted 25 September 2012 - 06:35 PM
- Arron Chapman likes this
#12
Posted 25 September 2012 - 07:05 PM
Nice use of the dynamic characters, terb.Here it is ! a short demo video showing every character (number) several times over a 1-minute loop : http://rutube.ru/vid...79d27361df83d1/
it works by dynamic characters definition, as we said before.
Chris
#13
Posted 25 September 2012 - 07:07 PM
#14
Posted 05 October 2012 - 09:37 AM
just a quick update : a simple waiting screen (will be used when the GPS will be searching for satellites). It's a 16-steps sequence loop that uses dynamic custom characters definition. It uses 20 custom characters (+ 40 other ones for the numbers) in total, 8 at a given time.
here it is : http://rutube.ru/vid...b238eb5298c8c36
#15
Posted 02 February 2013 - 06:38 PM
Hi Terb,
I've done that before, for this project:
The code isn't published yet, but the method for the custom characters is this one:public static void main() { // To play snake on a 2x16 LCD, we need 7 custom characters (0x00 to 0x06): _CustomizeCharacter(0x00, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e, 0x00 }); // b000: ₒ (fruit at the bottom) _CustomizeCharacter(0x01, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }); // b001: ° (fruit at the top) _CustomizeCharacter(0x02, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00 }); // b010: ▀ (snake at the top) _CustomizeCharacter(0x03, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x0e, 0x0e, 0x00 }); // b011: ▀ + ₒ (snake at the top + fruit at the bottom) _CustomizeCharacter(0x04, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b100: ▄ (snake at the bottom) _CustomizeCharacter(0x05, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b101: ▄ + ° (snake at the bottom + fruit at the top) _CustomizeCharacter(0x06, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }); // b110: █ (snake at the bottom + snake at the top) } /// <summary> /// Creates a customized character on a HD44780 LCD /// </summary> /// <param name="Index">Character index (0 to 7)</param> /// <param name="Character">Character bitmap</param> private static void _CustomizeCharacter(int Index, byte[] CharacterBitmap) { if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7"); if (CharacterBitmap.Length != 8) throw new ArgumentOutOfRangeException("CharacterBitmap must have 8 byte values"); _disp.Write((byte)(0x40 + 8 * Index), true); // Set CGRAM Address _disp.Write(CharacterBitmap); // Writes the character _disp.Write(0x80, true); // Set DDRAM Address }Maybe that'll help you?
_disp is an instance of Toolbox.NETMF.Hardware.Hd44780Lcd
Hi,
I just bought the Adafruit 16x2 LCD with a RCB LCD in a package and it works fine for standard character.
Now I tried you code above, but nothing is shown...do I have to call the character somehow to actually write it to the screen?
Thanks
#16
Posted 04 February 2013 - 07:40 AM
Hi,
I just bought the Adafruit 16x2 LCD with a RCB LCD in a package and it works fine for standard character.
Now I tried you code above, but nothing is shown...do I have to call the character somehow to actually write it to the screen?
Thanks
Yes, you must call the character. You can best check out this sample code:
http://netmftoolbox....ew/21723#339006
/// <summary> /// Shows the splash screen /// </summary> public static void Splash() { _disp.ClearDisplay(); _NetduinoLogo(); _disp.Write(" HD44780 Snake"); _disp.ChangePosition(1, 2); _disp.Write("for "); _disp.Write(new byte[] { 0, 1, 2, 3, 4, 5, 0, 6 }, false); }
The last line writes the characters by their index.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users