-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patholed.c
454 lines (419 loc) · 15.3 KB
/
oled.c
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/////////////////////////////////////////////////////////////////////////
//
// I2C Routines
//
//Modified by L. BAGHLI 03/2017
// Help
// d:\users\baghli\orcad\gyro\C2000_IMU6050\3583.F28335 - I2C.pdf
// https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/416428
//
// Included Files
//
//#include <stddef.h>
//#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include <math.h>
//#include <ctype.h>
#include <stdint.h>
//#include <stdbool.h>
#include "F2802x_PieCtrl.h"
#include "F2802x_I2c.h"
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include "F2802x_Device.h" // F2802x Headerfile Include File
#include "oled.h"
// USER_SYSTEM_FREQ_MHz is 60 MHz
//---------------------------------------------Delay
void __delay_ms(unsigned long t)
{
unsigned long i;
for (i=0;i<t;i++)
DSP28x_usDelay(1000); //usDelay
}
//-----------------------------------------------------------------------------
// InitI2C - This function initializes the I2C to a known state.
void InitI2C()
{
// Initialize I2C-A
/*
I2caRegs.I2CSAR = I2C_SLAVE_ADDR; // Slave address - OLED control code
// ( I2C_SLAVE_ADDR << 1 ) | ( hasWrite ? 0x00 : 0x01 );
I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts
// Take I2C out of reset. Stop I2C when suspended
I2caRegs.I2CMDR.all = 0x0020;
I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
i2c1Reset();
// i2c1Enable( kI2C_400KHZ );
*/
I2caRegs.I2CMDR.all = 0x0000;
I2caRegs.I2CSAR = I2C_SLAVE_ADDR; // Slave address
// 90 MHz/( (8+1)(10+5 + 5+5)) = 400 kHz
// 60 MHz/( (5+1)(10+5 + 5+5)) = 400 kHz
//
// I2CCLK = SYSCLK/(I2CPSC+1)
I2caRegs.I2CPSC.all = 5; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
//I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts 0010 0100
I2caRegs.I2CIER.all = 0x00; // No interrupt
// I2caRegs.I2CIER.bit.AAS = 0; // Addressed as slave interrupt enable bit
// I2caRegs.I2CIER.bit.SCD = 1; // Stop condition detected interrupt enable bit
// I2caRegs.I2CIER.bit.XRDY = 0; // Transmit-data-ready interrupt enable bit
// I2caRegs.I2CIER.bit.RRDY = 0; // Receive-data-ready interrupt enable bit
// I2caRegs.I2CIER.bit.ARDY = 1; // Register-access-ready interrupt enable bit
// I2caRegs.I2CIER.bit.NACK = 0; // No-acknowledgment interrupt enable bit
// I2caRegs.I2CIER.bit.ARBL = 0; // Arbitration-lost interrupt enable bit
//I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFTX.bit.I2CFFEN = 1; // Enable the I2C FIFO mode
I2caRegs.I2CFFTX.bit.TXFFRST = 1; // Enable the transmit FIFO operation
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1; // Clear the TXFFINT flag
I2caRegs.I2CFFTX.bit.TXFFIENA = 0; // TXFFINT flag generates an interrupt when set
I2caRegs.I2CFFTX.bit.TXFFIL = 0; // Transmit FIFO interrupt level
//I2caRegs.I2CFFRX.all = 0x0000; // No RXFIFO, no clear RXFFINT
I2caRegs.I2CFFRX.bit.RXFFRST = 0; // **Disable** the receive FIFO operation
I2caRegs.I2CFFRX.bit.RXFFINTCLR = 0; // Clear the RXFFINT flag
I2caRegs.I2CFFRX.bit.RXFFIENA = 0; // RXFFINT flag does generate an interrupt when set
I2caRegs.I2CFFRX.bit.RXFFIL = 0; // Receive FIFO interrupt level
//I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset,Stop I2C when suspended
I2caRegs.I2CMDR.bit.NACKMOD = 0; // NACK mode bit
I2caRegs.I2CMDR.bit.FREE = 0; // Stop I2C when suspended
I2caRegs.I2CMDR.bit.STT = 0; // START condition bit
I2caRegs.I2CMDR.bit.STP = 0; // STOP condition bit
I2caRegs.I2CMDR.bit.MST = 0; // Slave mode
I2caRegs.I2CMDR.bit.TRX = 0; // Receiver mode
I2caRegs.I2CMDR.bit.XA = 0; // 7-bit addressing mode
I2caRegs.I2CMDR.bit.RM = 0; // Nonrepeat mode
I2caRegs.I2CMDR.bit.DLB = 0; // Digital loopback mode is disabled
I2caRegs.I2CMDR.bit.IRS = 1; // The I2C module is enabled
I2caRegs.I2CMDR.bit.STB = 0; // The I2C module is not in the START byte mode
I2caRegs.I2CMDR.bit.FDF = 0; // Free data format mode is disabled
I2caRegs.I2CMDR.bit.BC = 0; // 8 bits per data byte
oledInit();
oledClear();
oledGotoYX( 0, 0 );
oledPrint( "Ring" );
oledGotoYX( 1, 0 );
oledPrint( "Vdc" );
oledGotoYX( 1, 10 );
oledPrint( "V" );
oledGotoYX( 2, 0 );
oledPrint("Vref");
oledGotoYX( 3, 0 );
oledPrint("Thanks");
}
//-----------------------------------------------------------------------------
void i2c_Xfer(
Uint8 address,
Uint8* wdata, int wsize,
Uint8* rdata, int rsize )
{
Uint16 i;
// I2caRegs.I2CMDR.bit.IRS = 0;
// usDelay(10);
// I2caRegs.I2CMDR.bit.IRS = 1;
// usDelay(10);
// // Make sure I2C is not busy and has stopped
// while (I2caRegs.I2CSTR.bit.BB == 1); // busy loop
// I2caRegs.I2CSTR.bit.SCD = 1; // Clear the SCD bit (stop condition bit)
// while(I2caRegs.I2CMDR.bit.STP == 1); // stop bit loop
I2caRegs.I2CSAR = address; // I2C slave address
// while (I2caRegs.I2CSTR.bit.BB == 1); // still busy?
I2caRegs.I2CCNT = wsize; // Setup number of bytes to send
// I2caRegs.I2CMDR.all = 0x6E20; // Send the TX FIFO : 0110 1110 0010 0000
// I2caRegs.I2CMDR.all = 0x6620; // STT=1 : 0110 0110 0010 0000
I2caRegs.I2CMDR.all = 0x66A0; // STT=1 : 0110 0110 1010 0000 RM, STT
// I2caRegs.I2CMDR.bit.NACKMOD = 0; // NACK mode bit
// I2caRegs.I2CMDR.bit.FREE = 1; // Run free I2C when suspended
// I2caRegs.I2CMDR.bit.STT = 1; // START condition bit
// I2caRegs.I2CMDR.bit.STP = 1; // STOP condition bit
// I2caRegs.I2CMDR.bit.MST = 1; // Master mode
// I2caRegs.I2CMDR.bit.TRX = 1; // Transmitter mode
// I2caRegs.I2CMDR.bit.XA = 0; // 7-bit addressing mode
// I2caRegs.I2CMDR.bit.RM = 0; // Nonrepeat mode
// I2caRegs.I2CMDR.bit.DLB = 0; // Digital loopback mode is disabled
// I2caRegs.I2CMDR.bit.IRS = 1; // The I2C module is enabled
// I2caRegs.I2CMDR.bit.STB = 0; // The I2C module is not in the START byte mode
// I2caRegs.I2CMDR.bit.FDF = 0; // Free data format mode is disabled
// I2caRegs.I2CMDR.bit.BC = 0; // 8 bits per data byte
// int WaitTimeOut=0;
//start transfer of 4 bytes max
for (i=0; i<wsize; i++)
{
I2caRegs.I2CDXR = *(wdata+i);
while(!I2caRegs.I2CSTR.bit.XRDY);
}
I2caRegs.I2CMDR.bit.STP = 1; // manual set of Stop
while(I2caRegs.I2CMDR.bit.STP == 1); // stop bit loop
}
//-----------------------------------------------------------------------------
void i2c_Reset()
{
}
//-----------------------------------------------------------------------------
// SSD1308 OLED Routines
//
#define SSD1308_Address I2C_SLAVE_ADDR
#define SSD1308_Command_Mode 0x80
#define SSD1308_Data_Mode 0x40
#define SSD1308_Display_Off_Cmd 0xAE
#define SSD1308_Display_On_Cmd 0xAF
#define SSD1308_Normal_Display_Cmd 0xA6
#define SSD1308_Inverse_Display_Cmd 0xA7
#define SSD1308_Activate_Scroll_Cmd 0x2F
#define SSD1308_Dectivate_Scroll_Cmd 0x2E
#define SSD1308_Set_Brightness_Cmd 0x81
const Uint8 OledFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
void oledCommand( Uint8 ch )
{
Uint8 bytes[2];
bytes[0] = SSD1308_Command_Mode;
bytes[1] = ch;
i2c_Xfer( SSD1308_Address, bytes, 2, NULL, 0 );
}
void oledDisplayOffset( Uint8 offset )
{
Uint8 bytes[3];
bytes[0] = SSD1308_Command_Mode;
bytes[1] = 0xD3;
bytes[2] = offset;
i2c_Xfer( SSD1308_Address, bytes, 3, NULL, 0 );
}
void oledData( Uint8 data )
{
Uint8 bytes[2];
bytes[0] = SSD1308_Data_Mode;
bytes[1] = data;
i2c_Xfer( SSD1308_Address, bytes, 2, NULL, 0 );
}
void oledGotoYX(unsigned char Row, unsigned char Column)
{
oledCommand( 0xB0 + Row);
oledCommand( 0x00 + (8*Column & 0x0F) );
oledCommand( 0x10 + ((8*Column>>4)&0x0F) );
}
void oledPutChar( char ch )
{
if ( ( ch < 32 ) || ( ch > 127 ) ) ch = ' ';
const Uint8 *base = &OledFont[ch - 32][0];
Uint8 bytes[9];
bytes[0] = SSD1308_Data_Mode;
memmove( bytes + 1, base, 8 );
i2c_Xfer( SSD1308_Address, bytes, 9, NULL, 0 );
}
void oledPutHexa( unsigned int Var )
{
int tmp;
tmp=Var>>12 & 0x000F;
if (tmp<=9) tmp+=0x30;
else tmp+=0x37;
oledPutChar(tmp);
tmp=Var>>8 & 0x000F;
if (tmp<=9) tmp+=0x30;
else tmp+=0x37;
oledPutChar(tmp);
tmp=Var>>4 & 0x000F;
if (tmp<=9) tmp+=0x30;
else tmp+=0x37;
oledPutChar(tmp);
tmp=Var & 0x000F;
if (tmp<=9) tmp+=0x30;
else tmp+=0x37;
oledPutChar(tmp);
}
void oledPutDec( unsigned int Var )
{
unsigned int k;
unsigned char c;
// Char
k = Var;
c = k/1000;
if (c > 0)
k = k - c*1000;
oledPutChar(c + 0x30);
c = k/100;
if (c > 0)
k = k - c*100;
oledPutChar(c + 0x30);
c = k/10;
if (c > 0)
k = k - c*10;
oledPutChar(c + 0x30);
// oledPutChar('.');
oledPutChar(k + 0x30);
}
void oledPrint( char *s )
{
while (*s) oledPutChar( *s++);
}
void oledClear()
{
Uint16 row, col;
for ( row = 0; row < 8; row++ ) {
for ( col = 0; col < 16; col++ ) {
oledGotoYX( row, col );
oledPutChar( ' ' );
}
}
}
void oledInit()
{
// olex way :
#define OLED_SETCONTRAST 0x81
#define OLED_DISPLAYALLON_RESUME 0xA4
#define OLED_DISPLAYALLON 0xA5
#define OLED_NORMALDISPLAY 0xA6
#define OLED_INVERTDISPLAY 0xA7
#define OLED_DISPLAYOFF 0xAE
#define OLED_DISPLAYON 0xAF
#define OLED_SETDISPLAYOFFSET 0xD3
#define OLED_SETCOMPINS 0xDA
#define OLED_SETVCOMDETECT 0xDB
#define OLED_SETDISPLAYCLOCKDIV 0xD5
#define OLED_SETPRECHARGE 0xD9
#define OLED_SETMULTIPLEX 0xA8
#define OLED_SETLOWCOLUMN 0x00
#define OLED_SETHIGHCOLUMN 0x10
#define OLED_SETSTARTLINE 0x40
#define OLED_MEMORYMODE 0x20
#define OLED_COLUMNADDR 0x21
#define OLED_PAGEADDR 0x22
#define OLED_COMSCANINC 0xC0
#define OLED_COMSCANDEC 0xC8
#define OLED_SEGREMAP 0xA0
#define OLED_CHARGEPUMP 0x8D
oledCommand( OLED_DISPLAYOFF );
__delay_ms( 100 );
oledCommand( OLED_SETDISPLAYCLOCKDIV );
oledCommand( 0x80 ); // the suggested ratio 0x80
__delay_ms( 100 );
oledCommand( OLED_SETMULTIPLEX );
oledCommand( 0x1F );
__delay_ms( 100 );
oledCommand( OLED_SETDISPLAYOFFSET );
oledCommand( 0x0 ); // no offset
__delay_ms( 100 );
oledCommand(OLED_SETSTARTLINE | 0x0); // line #0
__delay_ms( 100 );
oledCommand( OLED_CHARGEPUMP );
oledCommand( 0xAF );
__delay_ms( 100 );
oledCommand( OLED_MEMORYMODE );
oledCommand( 0x0 ); // 0x0 act like ks0108
__delay_ms( 100 );
// 0x0 act like ks0108
oledCommand(OLED_SEGREMAP | 0x1);
oledCommand(OLED_COMSCANDEC);
oledCommand(OLED_SETCOMPINS); // 0xDA
oledCommand(0x02);
oledCommand(OLED_SETCONTRAST); // 0x81
oledCommand(0x8F);
oledCommand(OLED_SETPRECHARGE); // 0xd9
oledCommand(0xF1);
oledCommand(OLED_SETVCOMDETECT); // 0xDB
oledCommand(0x40);
oledCommand(OLED_DISPLAYALLON_RESUME);// 0xA4
oledCommand(OLED_NORMALDISPLAY); // 0xA6
oledCommand(OLED_DISPLAYON); //--turn on oled panel
}