Library for DogM163 text display 3x16 character
Dependents: DogMTest WavPlayerSD_CB_using_RiceGulumb WavPlayer_CB
DogM163.cpp@1:1e693c7d1389, 2010-12-15 (annotated)
- Committer:
- FrankWeissenborn
- Date:
- Wed Dec 15 00:02:48 2010 +0000
- Revision:
- 1:1e693c7d1389
- Parent:
- 0:f7a30e1476bd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
FrankWeissenborn | 0:f7a30e1476bd | 1 | #include "DogM163.h" |
FrankWeissenborn | 0:f7a30e1476bd | 2 | |
FrankWeissenborn | 0:f7a30e1476bd | 3 | DogM163::DogM163(PinName miso, PinName clk, PinName cs, PinName rs):_spi(miso,NC,clk),_rs(rs),_cs(cs) { |
FrankWeissenborn | 0:f7a30e1476bd | 4 | _spi.format(8,0); |
FrankWeissenborn | 0:f7a30e1476bd | 5 | _spi.frequency(250000); |
FrankWeissenborn | 0:f7a30e1476bd | 6 | Init(); |
FrankWeissenborn | 0:f7a30e1476bd | 7 | } |
FrankWeissenborn | 0:f7a30e1476bd | 8 | |
FrankWeissenborn | 0:f7a30e1476bd | 9 | void DogM163::Init() { |
FrankWeissenborn | 0:f7a30e1476bd | 10 | _cs=0; |
FrankWeissenborn | 0:f7a30e1476bd | 11 | wait_ms(50); |
FrankWeissenborn | 1:1e693c7d1389 | 12 | WriteCommandByte( 0x39 ); // Function set; 8 bit Datenl�nge, 2 Zeilen, Instruction table 1 |
FrankWeissenborn | 1:1e693c7d1389 | 13 | wait_us(27); // mehr als 26,3�s warten |
FrankWeissenborn | 0:f7a30e1476bd | 14 | WriteCommandByte( 0x15 ); // Bias Set; BS 1/4; 3 zeiliges Display |
FrankWeissenborn | 1:1e693c7d1389 | 15 | wait_us(30); // mehr als 26,3�s warten |
FrankWeissenborn | 0:f7a30e1476bd | 16 | WriteCommandByte( 0x70 ); // Kontrast C3, C2, C1 setzen |
FrankWeissenborn | 0:f7a30e1476bd | 17 | wait_us(30); |
FrankWeissenborn | 0:f7a30e1476bd | 18 | WriteCommandByte( 0x55 ); // Booster aus; Kontrast C5, C4 setzen |
FrankWeissenborn | 0:f7a30e1476bd | 19 | wait_us(30); |
FrankWeissenborn | 1:1e693c7d1389 | 20 | WriteCommandByte( 0x6e ); // Spannungsfolger und Verst�rkung setzen /6c |
FrankWeissenborn | 0:f7a30e1476bd | 21 | wait_ms(200); // mehr als 200ms warten !!! |
FrankWeissenborn | 0:f7a30e1476bd | 22 | WriteCommandByte( 0x0f ); // Display EIN, Cursor EIN, Cursor BLINKEN /0f |
FrankWeissenborn | 0:f7a30e1476bd | 23 | wait_us(30); |
FrankWeissenborn | 1:1e693c7d1389 | 24 | WriteCommandByte( 0x01 ); // Display l�schen, Cursor Home |
FrankWeissenborn | 0:f7a30e1476bd | 25 | wait_ms(50); |
FrankWeissenborn | 0:f7a30e1476bd | 26 | WriteCommandByte( 0x06 ); // Cursor Auto-Increment |
FrankWeissenborn | 0:f7a30e1476bd | 27 | wait_us(30); |
FrankWeissenborn | 0:f7a30e1476bd | 28 | WriteCommandByte( 0x02 ); // Cursor Auto-Increment |
FrankWeissenborn | 0:f7a30e1476bd | 29 | wait_us(30); |
FrankWeissenborn | 0:f7a30e1476bd | 30 | _cs=1; |
FrankWeissenborn | 0:f7a30e1476bd | 31 | } |
FrankWeissenborn | 0:f7a30e1476bd | 32 | |
FrankWeissenborn | 0:f7a30e1476bd | 33 | void DogM163::WriteCommandByte(char cmd) { |
FrankWeissenborn | 0:f7a30e1476bd | 34 | _rs = 0; |
FrankWeissenborn | 0:f7a30e1476bd | 35 | _spi.write(cmd); |
FrankWeissenborn | 0:f7a30e1476bd | 36 | } |
FrankWeissenborn | 0:f7a30e1476bd | 37 | void DogM163::WriteDataByte(char cmd) { |
FrankWeissenborn | 0:f7a30e1476bd | 38 | _rs = 1; |
FrankWeissenborn | 0:f7a30e1476bd | 39 | _spi.write(cmd); |
FrankWeissenborn | 0:f7a30e1476bd | 40 | } |
FrankWeissenborn | 0:f7a30e1476bd | 41 | |
FrankWeissenborn | 0:f7a30e1476bd | 42 | /** Clear Display |
FrankWeissenborn | 0:f7a30e1476bd | 43 | * |
FrankWeissenborn | 0:f7a30e1476bd | 44 | * Write spaces into DDRAM and set address to (0,0) |
FrankWeissenborn | 0:f7a30e1476bd | 45 | * |
FrankWeissenborn | 0:f7a30e1476bd | 46 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 47 | void DogM163::Clear() |
FrankWeissenborn | 0:f7a30e1476bd | 48 | { |
FrankWeissenborn | 0:f7a30e1476bd | 49 | _cs = 0; |
FrankWeissenborn | 0:f7a30e1476bd | 50 | WriteCommandByte(0x01); |
FrankWeissenborn | 0:f7a30e1476bd | 51 | wait_ms(50); |
FrankWeissenborn | 0:f7a30e1476bd | 52 | _cs = 1; |
FrankWeissenborn | 0:f7a30e1476bd | 53 | } |
FrankWeissenborn | 0:f7a30e1476bd | 54 | |
FrankWeissenborn | 0:f7a30e1476bd | 55 | /** Set Position to (x,line) |
FrankWeissenborn | 0:f7a30e1476bd | 56 | * |
FrankWeissenborn | 0:f7a30e1476bd | 57 | * @param x new x position |
FrankWeissenborn | 0:f7a30e1476bd | 58 | * @param line new line (LINE_1,LINE_2 or LINE_3) |
FrankWeissenborn | 0:f7a30e1476bd | 59 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 60 | void DogM163::SetPosition(unsigned char x, unsigned char line) |
FrankWeissenborn | 0:f7a30e1476bd | 61 | { |
FrankWeissenborn | 0:f7a30e1476bd | 62 | _cs=0; |
FrankWeissenborn | 0:f7a30e1476bd | 63 | WriteCommandByte(0x80 + line*16 + x); |
FrankWeissenborn | 0:f7a30e1476bd | 64 | _cs=1; |
FrankWeissenborn | 0:f7a30e1476bd | 65 | } |
FrankWeissenborn | 0:f7a30e1476bd | 66 | |
FrankWeissenborn | 0:f7a30e1476bd | 67 | /** Write a character at the current position |
FrankWeissenborn | 0:f7a30e1476bd | 68 | * |
FrankWeissenborn | 0:f7a30e1476bd | 69 | * @param character character |
FrankWeissenborn | 0:f7a30e1476bd | 70 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 71 | void DogM163::WriteCharacter(char character) { |
FrankWeissenborn | 0:f7a30e1476bd | 72 | _cs=0; |
FrankWeissenborn | 0:f7a30e1476bd | 73 | WriteDataByte(character); |
FrankWeissenborn | 0:f7a30e1476bd | 74 | _cs=1; |
FrankWeissenborn | 0:f7a30e1476bd | 75 | } |
FrankWeissenborn | 0:f7a30e1476bd | 76 | |
FrankWeissenborn | 0:f7a30e1476bd | 77 | /** Write a character at position (x,line) |
FrankWeissenborn | 0:f7a30e1476bd | 78 | * |
FrankWeissenborn | 0:f7a30e1476bd | 79 | * @param character character |
FrankWeissenborn | 0:f7a30e1476bd | 80 | * @param x x-position (starting with 0) |
FrankWeissenborn | 0:f7a30e1476bd | 81 | * @param line (LINE_1, LINE_2 or LINE3) |
FrankWeissenborn | 0:f7a30e1476bd | 82 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 83 | void DogM163::WriteCharacter(char character,unsigned char x,unsigned char line) |
FrankWeissenborn | 0:f7a30e1476bd | 84 | { |
FrankWeissenborn | 0:f7a30e1476bd | 85 | SetPosition(x,line); |
FrankWeissenborn | 0:f7a30e1476bd | 86 | WriteCharacter(character); |
FrankWeissenborn | 0:f7a30e1476bd | 87 | } |
FrankWeissenborn | 0:f7a30e1476bd | 88 | |
FrankWeissenborn | 0:f7a30e1476bd | 89 | /** Write a null terminated string at the current position |
FrankWeissenborn | 0:f7a30e1476bd | 90 | * |
FrankWeissenborn | 0:f7a30e1476bd | 91 | * @param string string |
FrankWeissenborn | 0:f7a30e1476bd | 92 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 93 | void DogM163::WriteString(char* string) |
FrankWeissenborn | 0:f7a30e1476bd | 94 | { |
FrankWeissenborn | 0:f7a30e1476bd | 95 | _rs = 1; |
FrankWeissenborn | 0:f7a30e1476bd | 96 | _cs = 0; |
FrankWeissenborn | 0:f7a30e1476bd | 97 | while (string[0] != 0x00) |
FrankWeissenborn | 0:f7a30e1476bd | 98 | { |
FrankWeissenborn | 0:f7a30e1476bd | 99 | wait_us(30); |
FrankWeissenborn | 0:f7a30e1476bd | 100 | _spi.write( string[0] ); |
FrankWeissenborn | 0:f7a30e1476bd | 101 | string++; |
FrankWeissenborn | 0:f7a30e1476bd | 102 | } |
FrankWeissenborn | 0:f7a30e1476bd | 103 | _cs = 1; |
FrankWeissenborn | 0:f7a30e1476bd | 104 | } |
FrankWeissenborn | 0:f7a30e1476bd | 105 | |
FrankWeissenborn | 0:f7a30e1476bd | 106 | /** Write a null terminated string at position (x,line) |
FrankWeissenborn | 0:f7a30e1476bd | 107 | * |
FrankWeissenborn | 0:f7a30e1476bd | 108 | * @param string string |
FrankWeissenborn | 0:f7a30e1476bd | 109 | * @param x x-position (starting with 0) |
FrankWeissenborn | 0:f7a30e1476bd | 110 | * @param line (LINE_1, LINE_2 or LINE3) |
FrankWeissenborn | 0:f7a30e1476bd | 111 | */ |
FrankWeissenborn | 0:f7a30e1476bd | 112 | void DogM163::WriteString(char* string, unsigned char x, unsigned char line) |
FrankWeissenborn | 0:f7a30e1476bd | 113 | { |
FrankWeissenborn | 0:f7a30e1476bd | 114 | SetPosition(x,line); |
FrankWeissenborn | 0:f7a30e1476bd | 115 | WriteString(string); |
FrankWeissenborn | 0:f7a30e1476bd | 116 | } |
FrankWeissenborn | 0:f7a30e1476bd | 117 |