-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayBoardTester.ino
415 lines (367 loc) · 13.1 KB
/
displayBoardTester.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
Test Keiyhley 197A display board with Arduino Nano
(C) ALX2009
Licensed under GPL-2.0 license, see file LICENSE
Acknowledgments:
This work wouldn't have been possible without eevblog user rastro reverse engineering work: https://www.eevblog.com/forum/projects/keithley-197-led-display-hack/msg493365/#msg493365
Thanks goes also to Technogeeky, I have re-used part of this code (https://github.com/technogeeky/keithley-197), turning it around, so to speak, to simulate the motherboard
See README.md for more information
Arduino Nano connections (please see Fritzing diagram for the full circuit):
RCL: pin D2
STO: pin D3
RCL: pin D4
dB: pin D5
RESET: pin D6
C/D: pin D7
CS: pin D8
Clock: pin D9
MOSI: pin D11
SCK: pin D13
*/
// Useful Strings:
// 123456789A123456789B123456789C
// MIN BAT RCL AC dB STO REL AUTO
// mA k V u M mV
// RMT A OHM C
// 1-6abcdefgp
#include <string.h>
#include <TimerOne.h>
#include <SPI.h>
// pins used for the connection with the board (the
// other you need are controlled by the SPI library):
#include "aButton.h"
#include "K197_set.h"
const int rclPin = 2;
const int stoPin = 3;
const int relPin = 4;
const int dbPin = 5;
const int chipResetPin = 6;
const int chipCdPin = 7;
const int chipSelectPin = 8;
const int clockPin = 9;
// SPI MOSI, D11
// SPI SCK, D13
aButtonGroup buttons;
#define SHOWTEXT_SIZE 8 //size of the buffer for the show text command
byte startupSeq[] = {};
byte initSeq[] = { 0x10, 0x20, 0x30, 0x4A, 0x14, 0x00, 0x18, 0x11, 0x20 };
byte cmdSeq[] = { 0x20, 0x30, 0x4A, 0x14, 0x00, 0x18, 0x11, 0x20 };
byte dataSeq[] = { 0x01, 0x00, 0x00, 0xEB, 0x23, 0x00, 0x00, 0x02, 0x02 };
void myButtonCallback(uint8_t buttonPin, uint8_t buttonEvent) {
short mbit=MODE_BIT_NONE;
switch(buttonPin) {
case dbPin: Serial.print(F("BUTTON dB: ")); mbit=MODE_BIT_dB; break;
case relPin: Serial.print(F("BUTTON REL: ")); mbit=MODE_BIT_REL; break;
case stoPin: Serial.print(F("BUTTON STO: ")); mbit=MODE_BIT_STO; break;
case rclPin: Serial.print(F("BUTTON RCL: ")); mbit=MODE_BIT_RCL; break;
default: Serial.print(F("")); Serial.print(buttonPin); Serial.print(F(": "));
}
aButtonGroup::Serial_printEventName(buttonEvent); Serial.println();
if ( (buttonEvent == aButtonGroup::eventClick) && (mbit!=MODE_BIT_NONE) ) {
toggle_mode_bit(dataSeq, mbit);
}
}
/// --------------------------------------------------------------------------------
/// Serial Menu
/// --------------------------------------------------------------------------------
void printPrompt() {
Serial.println(); Serial.print(F("> ")); Serial.flush();
}
void printHelp(void) {
Serial.println();
Serial.println(F(" ? - print this help text"));
Serial.println(F(" MIN[US] | BAT | RCL | AC | dB | STO | REL | AUTO ==> toggle mode bit"));
Serial.println(F(" mA | k | V | u | M | mV ==> toggle unit bit"));
Serial.println(F(" RMT | A | OHM | C ==> toggle unit2 bit"));
Serial.println(F(" show text> ==> show text"));
Serial.println(F(" clear ==> clear the display"));
Serial.println(F(" n[-m]<seg> to turn on segments on display n[to m]"));
Serial.println(F(" where n,m: 1-6, <seg> any combination of "));
printPrompt();
}
#define INPUT_BUFFER_SIZE 30
inline boolean validDigit(char c) {
return ( c >= '1') && (c <='6');
}
inline boolean validSegment(char c) {
boolean result=false;
switch(c) {
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'p': result=true; break;
}
return result;
}
//7 6 5 4 3 2 1 0
//c, b, d, g, a,dp, e, f
inline uint8_t segment2bit_number(char c) {
uint8_t result=0;
switch(c) {
case 'a': result=3; break;
case 'b': result=6; break;
case 'c': result=7; break;
case 'd': result=5; break;
case 'e': result=1; break;
case 'f': result=0; break;
case 'g': result=4; break;
case 'p': result=2; break;
}
return result;
}
inline boolean isDash(char c) {
return c == '-' ? true : false;
}
void handleSegments(char*token, uint8_t seg1, uint8_t seg2) {
uint8_t segdata=0x00;
while (*token!=0x00) {
if (!validSegment(*token)) {
printError(token);
return;
}
bitSet(segdata, segment2bit_number(*token));
token++;
}
if (seg2<seg1) {
Serial.println(F("Internal error in handleSegments"));
return;
}
for(int i=seg1; i<=seg2; i++) {
dataSeq[digit2index(i)] = segdata;
}
}
#define DP_bm char(0x04);
char char2segment(int c, bool dp) {
static char c2s[90] = {
char(0x00), char(0x00), char(0x00), char(0x00), char(0x00), char(0x00), char(0xF3), char(0x40),
char(0x00), char(0x00), char(0xA8), char(0x00), char(0x00), char(0x10), char(0x00), char(0x52), // row 2 (0x20-0x2f) ==> row 0
char(0xEB), char(0xC0), char(0x7A), char(0xF8), char(0xD1), char(0xB9), char(0xBB), char(0xC9),
char(0xFB), char(0xF9), char(0x00), char(0x00), char(0x00), char(0x30), char(0x00), char(0x48), // row 3 (0x30-0x3f) ==> row 1
char(0x73), char(0xDB), char(0xB3), char(0x2B), char(0xE8), char(0x3B), char(0x1B), char(0xAB),
char(0xD3), char(0x03), char(0xE0), char(0x9B), char(0x23), char(0x69), char(0xCB), char(0xB2), // row 4 (0x40-0x4f) ==> row 2
char(0x5B), char(0x79), char(0x7B), char(0x0B), char(0xE3), char(0xA2), char(0xE1), char(0xAA),
char(0x38), char(0x71), char(0x00), char(0x00), char(0x91), char(0x00), char(0x08), char(0x20), // row 5 (0x50-0x5f) ==> row 3
char(0x00), char(0xFA), char(0xB3), char(0x32), char(0xF2), char(0x22), char(0x13), char(0x3A),
char(0x93), char(0x80), char(0xA0), char(0x9B), char(0x23), char(0x69), char(0x92), char(0xB2), // row 6 (0x60-0x6f) ==> row 4
char(0x5B), char(0xD9), char(0x12), char(0x0B), char(0x33), char(0xA2), char(0xE1), char(0xAA),
char(0x38), char(0xF1) // row 7 (0x70-0x7f) ==> row 5
};
if (c<32 || c >=(90+32)) c=32;
char s = c2s[c-32];
if (dp) s |= DP_bm;
return s;
}
void printError(char*buf) {
Serial.print(F("Invalid command: ")); Serial.println(buf);
printHelp();
}
void handleSerial(void) {
static char buf[INPUT_BUFFER_SIZE];
size_t i =Serial.readBytesUntil(' ', buf, INPUT_BUFFER_SIZE);
buf[i]=0;
if (i==0) { // no characters read
return;
}
// Check help
if (strcasecmp("?", buf) == 0 ) {
printHelp();
return;
}
// Check MODE_BIT commands
short xbit=MODE_BIT_NONE;
if ( strcasecmp("AUTO", buf) == 0 ) {
xbit = MODE_BIT_AUTO;
} else if ( strcasecmp("REL", buf) == 0 ) {
xbit = MODE_BIT_REL;
} else if ( strcasecmp("STO", buf) == 0 ) {
xbit = MODE_BIT_STO;
} else if ( strcasecmp("dB", buf) == 0 ) {
xbit = MODE_BIT_dB;
} else if ( strcasecmp("AC", buf) == 0 ) {
xbit = MODE_BIT_AC;
} else if ( strcasecmp("RCL", buf) == 0 ) {
xbit = MODE_BIT_RCL;
} else if ( strcasecmp("BAT", buf) == 0 ) {
xbit = MODE_BIT_BAT;
} else if ( strcasecmp("MIN", buf) == 0 ) {
xbit = MODE_BIT_MINUS;
} else if ( strcasecmp("MINUS", buf) == 0 ) {
xbit = MODE_BIT_MINUS;
}
if (xbit!=MODE_BIT_NONE) {
toggle_mode_bit(dataSeq, xbit);
return;
}
// Check UNITS_BIT commands
xbit=UNITS_BIT_NONE;
if ( strcasecmp("mV", buf) == 0 ) {
xbit = UNITS_BIT_mV;
} else if ( strcasecmp("M", buf) == 0 ) {
xbit = UNITS_BIT_M;
} else if ( strcasecmp("u", buf) == 0 ) {
xbit = UNITS_BIT_micro;
} else if ( strcasecmp("V", buf) == 0 ) {
xbit = UNITS_BIT_V;
} else if ( strcasecmp("K", buf) == 0 ) {
xbit = UNITS_BIT_K;
} else if ( strcasecmp("mA", buf) == 0 ) {
xbit = UNITS_BIT_mA;
}
if (xbit!=UNITS_BIT_NONE) {
toggle_units_bit(dataSeq, xbit);
return;
}
// Check UNIT2_BIT commands
xbit=UNIT2_BIT_NONE;
if ( strcasecmp("C", buf) == 0 ) {
xbit = UNIT2_BIT_C;
} else if ( strcasecmp("OHM", buf) == 0 ) {
xbit = UNIT2_BIT_OHM;
} else if ( strcasecmp("A", buf) == 0 ) {
xbit = UNIT2_BIT_A;
} else if ( strcasecmp("RMT", buf) == 0 ) {
xbit = UNIT2_BIT_RMT;
}
if (xbit!=UNIT2_BIT_NONE) {
toggle_unit2_bit(dataSeq, xbit);
return;
}
if (strcasecmp("clear", buf) == 0 ) {
for (int i=1; i<7; i++) dataSeq[i] = 0x00;
return;
}
if (strcasecmp("show", buf) == 0 ) {
char showtext[SHOWTEXT_SIZE+1];
size_t text_len=Serial.readBytesUntil('>', showtext, SHOWTEXT_SIZE);
if (text_len<=0) {
return;
}
buf[text_len]=0;
unsigned int i_src=0;
bool dp = false;
for (int i=1; i<7; i++) {
dataSeq[i]=char(0x00);
}
for (int i_dst=1; i_dst<7; i_dst++) {
if (showtext[i_src] == '.') {
i_src++;
dp=true;
} else {
dp=false;
}
if (i_src>=text_len) {
return;
}
dataSeq[i_dst] = char2segment(showtext[i_src], dp);
i_src++;
}
return;
}
//check if 7 segment (+dp) specification
char*token=buf;
uint8_t seg1; uint8_t seg2;
if ( validDigit(*token) ) {
seg1 = ((*token)-'0');
seg2=seg1;
token++;
if (isDash(*token)) {
token++;
if (validDigit(*token)) {
seg2 = ((*token)-'0');
token++;
} else {
printError(token);
return;
}
}
handleSegments(token, seg1, seg2);
return;
} else {
printError(token);
return;
}
}
void setup() {
Timer1.initialize(12); // 12 us = 83.333 kHz instead of 81.92 (according to display controller data sheet 2-16 us is acceptable)
Timer1.pwm(clockPin, (50.0 / 100) * 1023 );
Serial.begin(115200);
delay(2000);
Serial.println(F(""));
Serial.print(F("startupSeq:"));Serial.println(sizeof(startupSeq)/sizeof(byte));
Serial.print(F("initSeq:"));Serial.println(sizeof(initSeq)/sizeof(byte));
Serial.print(F("dataSeq:"));Serial.println(sizeof(dataSeq)/sizeof(byte));
buttons.add(dbPin, myButtonCallback);
buttons.add(relPin, myButtonCallback);
buttons.add(stoPin, myButtonCallback);
buttons.add(rclPin, myButtonCallback);
pinMode(11, OUTPUT);
digitalWrite(11, LOW);
// initialize the data ready and chip select pins:
pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, HIGH); // This pin is active low
pinMode(chipCdPin, OUTPUT);
digitalWrite(chipCdPin, LOW); // Prepare for data
// start the SPI library:
SPI.begin();
// Reset the LCD driver chip
pinMode(chipResetPin, OUTPUT);
digitalWrite(chipResetPin, LOW);
delay(2000);
digitalWrite(chipResetPin, HIGH);
beginTransaction();
writeInitialCommandSequence(startupSeq, sizeof(startupSeq)/sizeof(byte));
writeCommandDataSequence(initSeq, sizeof(initSeq)/sizeof(byte), dataSeq, sizeof(dataSeq)/sizeof(byte));
endTransaction();
delay(1000);
}
static unsigned long display_seq_timer = 0L;
void loop() {
unsigned long now = millis();
if (now-display_seq_timer>300) {
display_seq_timer=now;
beginTransaction();
writeCommandDataSequence(cmdSeq, sizeof(cmdSeq)/sizeof(byte), dataSeq, sizeof(dataSeq)/sizeof(byte));
endTransaction();
}
buttons.check();
if (Serial.available() ) {
handleSerial();
}
}
void beginTransaction(void) { // All transactions begin as Command. Set chipCdPin to LOW when it's time to transfer data
SPI.beginTransaction(SPISettings(50000, MSBFIRST, SPI_MODE0));
// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
delayMicroseconds(5);
digitalWrite(chipCdPin, HIGH);
delayMicroseconds(1000);
}
void endTransaction(void) {
delayMicroseconds(2500);
digitalWrite(chipCdPin, LOW);
digitalWrite(chipSelectPin, HIGH);
SPI.endTransaction();
}
void writeInitialCommandSequence(const byte *cmd, short cmdlen) { //Note: this will overwrite cmd[]! Use with a dedicated buffer and only during setup!
for (int i=0; i<cmdlen; i++) {
SPI.transfer(cmd[i]); // Send one byte at a time
delayMicroseconds(368); // Give it time... this is an old, slow display driver!!!
if (i==7) {
delayMicroseconds(810);
}
}
delayMicroseconds(1000);
}
void writeCommandDataSequence(const byte *cmd, short cmdlen, const byte *data, short datalen) {
for (int i=0; i<cmdlen; i++) {
SPI.transfer(cmd[i]); // Send one byte at a time
delayMicroseconds(368); // Give it time... this is an old, slow display driver!!!
if (i==6) {
delayMicroseconds(810);
}
}
digitalWrite(chipCdPin, LOW);
delayMicroseconds(230);
for (int i=0; i<datalen; i++) {
SPI.transfer(data[i]); // Send one byte at a time
delayMicroseconds(368); // Give it time... this is an old, slow display driver!!!
}
delayMicroseconds(2500);
}