1 | #include "i2cmaster.h" // Peter Fleury's lib... Danke, Peter!
|
2 | #define FONTHEIGHT 9
|
3 | #define Touch128x64 0xDE //bei mir
|
4 | #define Touch160x104 0xDC //bei mir
|
5 | unsigned char ctdfont2[] = {0x04, 0x1b, 'Z','F', 2}; //Sum ESC Z F n1 Font 2: 6x8 monospaced
|
6 |
|
7 | i2c_init();
|
8 | sendCommandToTouch(Touch128x64, ctdfont2);
|
9 | SendAsciiInFont(Touch128x64, 0, 0*FONTHEIGHT, "Hallo Welt");
|
10 |
|
11 |
|
12 |
|
13 | Aufgerufen wird er mit folgenden Funktionen:
|
14 | /************************************************************************/
|
15 | unsigned char sendCommandToTouch (unsigned char i2cDestination , unsigned char* commandToDisplay) {
|
16 |
|
17 | unsigned char retvalue;
|
18 |
|
19 | i2c_start_wait(i2cDestination);
|
20 | SendCommand(commandToDisplay);
|
21 | i2c_start_wait(i2cDestination + 1);
|
22 | retvalue = i2c_readAck();
|
23 | i2c_stop();
|
24 |
|
25 | return retvalue;
|
26 |
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 | /************************************************************************/
|
32 | void SendCommand(unsigned char buf[])
|
33 | { unsigned char i, len, bcc;
|
34 | len = buf[0];
|
35 | i2c_write(0x11); // Send DC1
|
36 | bcc = 0x11;
|
37 | i2c_write(len); // Send data length
|
38 | bcc = bcc + len;
|
39 | for(i = 1; i < len + 1 ; i++) // Send buf
|
40 | {
|
41 | i2c_write(buf[i]);
|
42 | bcc = bcc + buf[i];
|
43 | };
|
44 | i2c_write(bcc); // Send checksum
|
45 |
|
46 | // Eigentlich gehört noch eine Fehlerbehandlung mit rein...
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | /************************************************************************
|
53 | *
|
54 | * SendAsciiInFont (device, xpos, ypos, string)
|
55 | *
|
56 | ************************************************************************/
|
57 | void SendAsciiInFont(unsigned char i2cDestination, uint8_t x, uint8_t y, char *buf)
|
58 | {
|
59 | // example:
|
60 | // unsigned char ctdchars[] = {13, 0x1b, 'Z','L',1,1,'D','i','s','p','l','a','y', 0x10 }; //
|
61 |
|
62 | unsigned char i, j, bcc;
|
63 | unsigned char test; //DEBUG
|
64 | j = strlen(buf) + 6 ; // 6 = esc + Z + L + xpos + ypos + NUL
|
65 |
|
66 | i2c_start_wait(i2cDestination + 0); //write a bunch of asciis
|
67 |
|
68 | //1.
|
69 | test = i2c_write(0x11); // send starter DC1
|
70 | bcc = 0x11;
|
71 |
|
72 | //2.
|
73 | test += i2c_write(j); // send data length
|
74 | bcc += j;
|
75 |
|
76 | //3.
|
77 | test += i2c_write(0x1b); // send esc
|
78 | bcc += 0x1b;
|
79 |
|
80 | //4.
|
81 | test += i2c_write('Z'); // send 'Z'
|
82 | bcc += 'Z';
|
83 |
|
84 | //5.
|
85 | test += i2c_write('L'); // send 'L'
|
86 | bcc += 'L';
|
87 |
|
88 | //6.
|
89 | test += i2c_write(x); // send xpos
|
90 | bcc += x;
|
91 |
|
92 | //7.
|
93 | test += i2c_write(y); // send ypos
|
94 | bcc += y;
|
95 |
|
96 | //8.
|
97 | for(i = 0; i < strlen(buf); i++) {// send buf
|
98 | test += i2c_write(buf[i]);
|
99 | bcc = bcc + buf[i];
|
100 | };
|
101 |
|
102 | //9.
|
103 | test += i2c_write(0x00); // send NUL for sequence end
|
104 | bcc += 0x0;
|
105 |
|
106 | test += i2c_write(bcc); // send checksum
|
107 |
|
108 | i2c_start_wait(i2cDestination + 1);
|
109 | i2c_readAck();
|
110 | i2c_stop();
|
111 |
|
112 | }
|