Skip to content

Instantly share code, notes, and snippets.

@vijfhoek
Created December 12, 2013 20:01
Show Gist options
  • Save vijfhoek/7934444 to your computer and use it in GitHub Desktop.
Save vijfhoek/7934444 to your computer and use it in GitHub Desktop.
namespace Z80
{
public partial class HD44780 : UserControl
{
#region font
private byte[,] font = new byte[256,8] {
/* 01 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 0
/* 00 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 1
/* 02 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 2
/* 03 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 3
/* 04 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 4
/* 05 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 5
/* 06 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 6
/* 07 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // cgram 7
/* 08 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 09 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0A */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0B */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0C */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0D */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 0F */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 10 */ { 0x08, 0x0C, 0x0E, 0x0F, 0x0E, 0x0C, 0x08, 0x00 },
/* 11 */ { 0x02, 0x06, 0x0E, 0x1E, 0x0E, 0x06, 0x02, 0x00 },
/* 12 */ { 0x09, 0x12, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 13 */ { 0x1C, 0x09, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 14 */ { 0x04, 0x0E, 0x1F, 0x00, 0x04, 0x0E, 0x1F, 0x00 },
/* 15 */ { 0x1F, 0x0E, 0x04, 0x00, 0x1F, 0x0E, 0x04, 0x00 },
/* 16 */ { 0x00, 0x0E, 0x1F, 0x1F, 0x1F, 0x0E, 0x00, 0x00 },
/* 17 */ { 0x01, 0x01, 0x05, 0x09, 0x1F, 0x09, 0x05, 0x00 },
/* 18 */ { 0x04, 0x0E, 0x15, 0x04, 0x04, 0x04, 0x04, 0x00 },
/* 19 */ { 0x04, 0x04, 0x04, 0x04, 0x15, 0x0E, 0x04, 0x00 },
/* 1A */ { 0x00, 0x04, 0x02, 0x1F, 0x02, 0x04, 0x00, 0x00 },
/* 1B */ { 0x00, 0x04, 0x08, 0x1F, 0x08, 0x04, 0x00, 0x00 },
/* 1C */ { 0x02, 0x04, 0x08, 0x04, 0x02, 0x00, 0x1F, 0x00 },
/* 1D */ { 0x08, 0x04, 0x02, 0x04, 0x08, 0x00, 0x1F, 0x00 },
/* 1E */ { 0x00, 0x04, 0x04, 0x0E, 0x0E, 0x1F, 0x00, 0x00 },
/* 1F */ { 0x00, 0x1F, 0x0E, 0x0E, 0x04, 0x04, 0x00, 0x00 },
/* 20 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // ' '
/* 21 */ { 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04, 0x00 }, // '!'
/* 22 */ { 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '"'
/* 23 */ { 0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A, 0x00 }, // '#'
/* 24 */ { 0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04, 0x00 }, // '$'
/* 25 */ { 0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03, 0x00 }, // '%'
/* 26 */ { 0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D, 0x00 }, // '&'
/* 27 */ { 0x0C, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '''
/* 28 */ { 0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02, 0x00 }, // '('
/* 29 */ { 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00 }, // ')'
/* 2A */ { 0x00, 0x08, 0x15, 0x0E, 0x15, 0x08, 0x00, 0x00 }, // '*'
/* 2B */ { 0x00, 0x08, 0x08, 0x1F, 0x08, 0x08, 0x00, 0x00 }, // '+'
/* 2C */ { 0x00, 0x00, 0x00, 0x00, 0x0C, 0x04, 0x08, 0x00 }, // ','
/* 2D */ { 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00 }, // '-'
/* 2E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // '.'
/* 2F */ { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00 }, // '/'
/* 30 */ { 0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E, 0x00 }, // '0'
/* 31 */ { 0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E, 0x00 }, // '1'
/* 32 */ { 0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F, 0x00 }, // '2'
/* 33 */ { 0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E, 0x00 }, // '3'
/* 34 */ { 0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02, 0x00 }, // '4'
/* 35 */ { 0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E, 0x00 }, // '5'
/* 36 */ { 0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E, 0x00 }, // '6'
/* 37 */ { 0x1F, 0x11, 0x01, 0x02, 0x04, 0x04, 0x04, 0x00 }, // '7'
/* 38 */ { 0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E, 0x00 }, // '8'
/* 39 */ { 0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C, 0x00 }, // '9'
/* 3A */ { 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x00, 0x00 }, // ':'
/* 3B */ { 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x04, 0x08, 0x00 }, // ';'
/* 3C */ { 0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02, 0x00 }, // '<'
/* 3D */ { 0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00, 0x00 }, // '='
/* 3E */ { 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x00 }, // '>'
/* 3F */ { 0x0E, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04, 0x00 }, // '?'
/* 40 */ { 0x0E, 0x11, 0x01, 0x0D, 0x1D, 0x1D, 0x0E, 0x00 }, // '@'
/* 41 */ { 0x04, 0x0A, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x00 }, // 'A'
/* 42 */ { 0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E, 0x00 }, // 'B'
/* 43 */ { 0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E, 0x00 }, // 'C'
/* 44 */ { 0x1C, 0x12, 0x11, 0x11, 0x11, 0x12, 0x1C, 0x00 }, // 'D'
/* 45 */ { 0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F, 0x00 }, // 'E'
/* 46 */ { 0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10, 0x00 }, // 'F'
/* 47 */ { 0x0E, 0x11, 0x10, 0x17, 0x11, 0x11, 0x0F, 0x00 }, // 'G'
/* 48 */ { 0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11, 0x00 }, // 'H'
/* 49 */ { 0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E, 0x00 }, // 'I'
/* 4A */ { 0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C, 0x00 }, // 'J'
/* 4B */ { 0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11, 0x00 }, // 'K'
/* 4C */ { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00 }, // 'L'
/* 4D */ { 0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11, 0x00 }, // 'M'
/* 4E */ { 0x11, 0x11, 0x19, 0x15, 0x13, 0x10, 0x10, 0x00 }, // 'N'
/* 4F */ { 0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00 }, // 'O'
/* 50 */ { 0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10, 0x00 }, // 'P'
/* 51 */ { 0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D, 0x00 }, // 'Q'
/* 52 */ { 0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11, 0x00 }, // 'R'
/* 53 */ { 0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E, 0x00 }, // 'S'
/* 54 */ { 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00 }, // 'T'
/* 55 */ { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00 }, // 'U'
/* 56 */ { 0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04, 0x00 }, // 'V'
/* 57 */ { 0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A, 0x00 }, // 'W'
/* 58 */ { 0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11, 0x00 }, // 'X'
/* 59 */ { 0x11, 0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x00 }, // 'Y'
/* 5A */ { 0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F, 0x00 }, // 'Z'
/* 5B */ { 0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E, 0x00 }, // '['
/* 5C */ { 0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00 }, // '\'
/* 5D */ { 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00 }, // ']'
/* 5E */ { 0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '^'
/* 5F */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00 }, // '_'
/* 60 */ { 0x08, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '`'
/* 61 */ { 0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00 }, // 'a'
/* 62 */ { 0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E, 0x00 }, // 'b'
/* 63 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'c'
/* 64 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'd'
/* 65 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'e'
/* 66 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'f'
/* 67 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'g'
/* 68 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'h'
/* 69 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'i'
/* 6A */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'j'
/* 6B */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'k'
/* 6C */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'l'
/* 6D */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'm'
/* 6E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'n'
/* 6F */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'o'
/* 70 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'p'
/* 71 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'q'
/* 72 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'r'
/* 73 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 's'
/* 74 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 't'
/* 75 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'u'
/* 76 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'v'
/* 77 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'w'
/* 78 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'x'
/* 79 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'y'
/* 7A */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 'z'
/* 7B */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '{'
/* 7C */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '|'
/* 7D */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '}'
/* 7E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // '~'
/* 7F */ { 0x00, 0x04, 0x0A, 0x11, 0x11, 0x11, 0x1F, 0x00 },
/* 80 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 81 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 82 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 83 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 84 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 85 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 86 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 87 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 88 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 89 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8A */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8B */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8C */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8D */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 8F */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 90 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 91 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 92 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 93 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 94 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 95 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 96 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 97 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 98 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 99 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9A */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9B */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9C */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9D */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9E */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* 9F */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* A9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AD */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* AF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* B9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BD */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* BF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* C9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CD */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* CF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* D9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DD */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* DF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* E9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* EA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* EB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* EC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* ED */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* EE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* EF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F2 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F3 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F4 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F5 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F6 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F7 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F8 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* F9 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FA */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FB */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FC */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FD */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FE */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
/* FF */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
#endregion
private byte[] ddram = new byte[80];
// True when writing to CGRAM
private bool cgramActive;
public byte DDRAMAddress { get; private set; }
public byte CGRAMAddress { get; private set; }
public int ShiftCount { get; private set; }
public bool CursorMoveDirection { get; private set; }
public bool ShiftDisplay { get; private set; }
public bool DisplayPower { get; private set; }
public bool ShowCursor { get; private set; }
public bool BlinkCursor { get; private set; }
public bool ShiftMode { get; private set; }
public bool ShiftDirection { get; private set; }
public bool DataLength { get; private set; }
public bool DisplayLines { get; private set; }
public bool CharacterFont { get; private set; }
public HD44780()
{
InitializeComponent();
}
/// <summary>
/// Clears display and returns cursor to the home position.
/// </summary>
public void ClearDisplay()
{
// Clear the display
for (int i = 0; i < ddram.Length; i++)
ddram[i] = 0;
// Home the cursor
DDRAMAddress = 0;
}
/// <summary>
/// Returns cursor to the home position. Also returns display being
/// shifted to the original position. DDRAM content remains unchanged.
/// </summary>
public void CursorHome()
{
// Home the cursor
DDRAMAddress = 0;
// Returns shift
ShiftCount = 0;
}
/// <summary>
/// Set cursor move direction and whether to shift the display. These
/// operations are performed during data read/write.
/// </summary>
/// <param name="direction">The direction to move the cursor to.</param>
/// <param name="shiftdisplay">Whether to shift the display when writing.</param>
public void EntryModeSet(bool direction, bool shiftdisplay)
{
CursorMoveDirection = direction;
ShiftDisplay = shiftdisplay;
}
/// <summary>
/// Turns display, cursor and cursor blink on or off.
/// </summary>
/// <param name="power">Turn on/off display.</param>
/// <param name="cursor">Whether to show the cursor.</param>
/// <param name="blink">Whether to make the cursor blink.</param>
public void DisplayOnOffControl(bool power, bool cursor, bool blink)
{
DisplayPower = power;
ShowCursor = cursor;
BlinkCursor = blink;
}
/// <summary>
/// Sets shift mode and direction. DDRAM content remains unchanged.
/// </summary>
/// <param name="shift">Whether to move the cursor (false) or shift the display (true).</param>
/// <param name="direction">Whether to shift right (false) or left (true).</param>
public void CursorDisplayShift(bool shift, bool direction)
{
ShiftMode = shift;
ShiftDirection = direction;
}
/// <summary>
/// Sets interface data length, display line count and character font.
/// </summary>
/// <param name="datalength">Set the data length to 4-bit (false) or 8-bit (true).</param>
/// <param name="displaylines">Set the display line count to 1 (false) or 2 (true).</param>
/// <param name="characterfont">Set the font to 5x8 (false) or 5x10 (true).</param>
public void FunctionSet(bool datalength, bool displaylines, bool characterfont)
{
DataLength = datalength;
DisplayLines = displaylines;
CharacterFont = characterfont;
}
/// <summary>
/// Set the CGRAM address. CGRAM data are sent and received after
/// this setting.
/// </summary>
/// <param name="address">The address to set the CGRAM address to.</param>
public void SetCGRAMAddress(byte address)
{
CGRAMAddress = address;
cgramActive = true;
}
/// <summary>
/// Set the DDRAM address. DDRAM data are sent and
/// received after this settings.
/// </summary>
/// <param name="address">The address to set the DDRAM address to.</param>
public void SetDDRAMAddress(byte address)
{
DDRAMAddress = address;
cgramActive = false;
}
/// <summary>
/// Reads busy flag (bit 7, always 0) and reads CGRAM or DDRAM
/// address counter contents (depending on previous instruction).
/// </summary>
/// <returns>The busy flag (bit 7) ORed with the address (bit 0:6)</returns>
public byte ReadBusyFlagAddressCounter()
{
return cgramActive ? CGRAMAddress : DDRAMAddress;
}
/// <summary>
/// Writes a byte of data to the current address in CGRAM or DDRAM.
/// </summary>
/// <param name="b">The byte of data to write.</param>
public void WriteData(byte b)
{
if (cgramActive) font[CGRAMAddress / 8, CGRAMAddress % 8] = b;
else ddram[DDRAMAddress] = b;
}
/// <summary>
/// Reads a byte of data from the current address in CGRAM or DDRAM.
/// </summary>
/// <returns>A byte of data from the current address.</returns>
public byte ReadData()
{
return cgramActive ? font[CGRAMAddress / 8, CGRAMAddress % 8] : ddram[DDRAMAddress];
}
private void drawCharacter(Graphics g, Rectangle r, char c)
{
for (int i = 0; i < 8; i++)
{
byte line = font[c, i];
for (int j = 0; j < 5; j++)
{
Rectangle rect = new Rectangle();
rect.Width = r.Width / 5;
rect.Height = r.Height / 8;
rect.X = r.X + (j * rect.Width);
rect.Y = r.Y + (i * rect.Height);
if ((line & (0x10 >> j)) == 0)
g.FillRectangle(new SolidBrush(LCDCharBackgroundColor), rect);
else
g.FillRectangle(new SolidBrush(LCDForegroundColor), rect);
}
}
}
protected override void OnPaint(PaintEventArgs pe)
{
for (int i = 0; i < LCDCharacterRows; i++)
{
for (int j = 0; j < LCDCharacterColumns; j++)
{
//Rectangle rect = new Rectangle();
//rect.X = ClientRectangle.X + (ClientRectangle.Width / LCDCharacterColumns * j) + 2;
//rect.Y = ClientRectangle.Y + (ClientRectangle.Height / LCDCharacterRows * i) + 2;
//rect.Width = (ClientRectangle.Width - 4) / LCDCharacterColumns - 1;
//rect.Height = (ClientRectangle.Height - 4) / LCDCharacterRows - 1;
//pe.Graphics.FillRectangle(new SolidBrush(LCDCharBackgroundColor), rect);
Rectangle r = new Rectangle();
r.Width = ClientRectangle.Width / LCDCharacterColumns;
r.Height = ClientRectangle.Height / LCDCharacterRows;
r.X = ClientRectangle.X + (j * r.Width) + 1;
r.Y = ClientRectangle.Y + (i * r.Height) + 2;
drawCharacter(pe.Graphics, r, (char)(j % 10 + '0'));
}
}
}
protected override void OnPaintBackground(PaintEventArgs pe)
{
pe.Graphics.FillRectangle(new SolidBrush(LCDBackgroundColor), ClientRectangle);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment