summaryrefslogtreecommitdiff
path: root/trunk/users/erik/OpenRapMan/EriksBranch/bfb-firmware-dev3/OLED.c
blob: 71c88b35f0ed87c4ff43ca9dc8aa078f551b8dbf (plain)
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/**********************************************************************
 ***************************  OLED.c  *********************************
 **********************************************************************
 * 
 * Company:         Bits From Bytes Ltd
 *
 * Software License Agreement
 *
 * Copyright (C) 2009 Bits From Bytes Ltd.  All rights reserved.
 *
 * Bits From Bytes Ltd licenses to you the right to use, modify, 
 * copy, and distribute this software under the 
 * Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported
 * licence (see 
 * CreativeCommons-by-nc-sa-3.0-summary.pdf which is a copy of the 
 * text at http://creativecommons.org/licenses/by-nc-sa/3.0/ for a 
 * summary and CreativeCommons-by-nc-sa-3.0.pdf which is a copy of the 
 * text at http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
 * for the full legal text).
 * 
 * You should refer to the license agreement (Bits From Bytes Ltd Software 
 * Licence.pdf) accompanying this Software for additional information 
 * regarding your rights and obligations.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 
 * BITS FROM BYTES LTD BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT
 * OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
 *
 * Author(s)                   		Date    	Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Tony Fletcher (& Ian Adkins) 	16/11/2009	Initial Release
 ***********************************************************************/
#include <p32xxxx.h>
#include "OLED.h"
#include "Screens.h"
#include "stepper.h"
#include "extruder.h"

//SPI2 pins for OLED 
#define OLED_CS 		PORTBbits.RB5 //Analog pin
#define DC      		PORTEbits.RE6	//Digital
#define RES     		PORTEbits.RE7	//Digital


extern int RPM_Setting;
extern long SetTemperature;
extern float temperature1;
extern int HeaterON;
extern int LineNumber;
extern char SaveFileName[12];

float ExtrusionRate;
/**************************************************/
/*                Forward Declarations            */
/**************************************************/
int  WriteSPI(int i);
void write_command(unsigned char command);
void write_data(unsigned char data);
void Fill_RAM(unsigned char Data); 

/***********************************************************/ 
void OLED_Printing_Screen(void) //Static Lables only
{
extern int ToolType;
	
	OLED_FastText57(0, 0, OLED_Header_VerNo,0);
	OLED_FastText57(1, 28, SaveFileName,0);
	OLED_FastText57(2, 0, "G-Code Line:",0);    	//Display G Code line number       
	OLED_FastText57(3, 0, "Head Speed:",0);    		//Display Feed Rate
	if (ToolType==2)OLED_FastText57(4, 0, "Ext. Rate:",0); 	//Display Extrusion Rate
	             	
}//OLED_Printing_Screen  
    
/***********************************************************/ 
void OLED_UpdatePrintScreen(void) //Info updated every G_Code line
{
char AsciiString[10];
float data1;
extern int S_F_Code;
extern int ToolType;

	sprintf(AsciiString, "%1u", LineNumber);	//Converts number to text
	OLED_FastText57(2, 90, AsciiString,0);     	//Write the new number
	
	if (S_F_Code > 0 )
	{
		data1 = (float)S_F_Code/60;
		sprintf(AsciiString, "%5.1fmm/s", data1);	//Converts number to text
		OLED_FastText57(3, 75, AsciiString,0);     	//Write the new number
		ExtrusionRate = (float)RPM_Setting*0.056;	//factor is 0.0563814
		sprintf(AsciiString, "%5.1fmm/s", ExtrusionRate);	//Converts number to text
		OLED_FastText57(4, 75, AsciiString,0);     	//Write the new number
	}
	else
		OLED_FastText57(3, 75, "Not Set",0);
	
	
	ShowBufferFillState();						//ln6 Show how full the look ahead buffer is
	ShowPrintProgress();						//ln5 Progress through the file	
	
	if (ToolType==2)//Extruder
	{
		OLED_UpdateThermistorReading();
		if (Temp_Change)OLED_UpdateSetTemperature();  //Update only if changed
		if (RPM_Change)OLED_UpdateSetRPM();			  //Update only if changed
	}
	
}//OLED_UpdatePrintScreen

/***********************************************************/ 
void OLED_Extruder_Screen(void)
{
	OLED_FastText57(0, 0, OLED_Header_VerNo,0);
	OLED_FastText57(1, 0, "Extruder Control",0);
	
	if(HEATER)OLED_FastText57(5, 0, "Heater On ",0);
	else OLED_FastText57(5, 0, "Heater Off",0);
	
	if (temperature1 < 100)
	{
		OLED_FastText57(3, 0, " <100C Motor OFF",0);
	}
	else
		OLED_ClearLine(3);
	
	OLED_UpdateSetTemperature();		
	OLED_UpdateThermistorReading();
	OLED_UpdateSetRPM();
	
}//OLED_Extruder_Screen

/***********************************************************/ 
void OLED_UpdateThermistorReading(void)
{
char AsciiString[10];
int data1;

	if (temperature1 == 999||temperature1 == -1){
		OLED_ClearLine(7);
		if (temperature1 == 999)OLED_FastText57(7, 10,"TEMPERATURE ERROR",0);
		if (temperature1 == -1)OLED_FastText57(7, 10, "THERMISTOR ERROR",0);
		return;
	}	
	
	data1=(int)temperature1;						//Display actual temperature
	sprintf(AsciiString, "%3uC", (int)data1);    	//Converts number to text
	OLED_FastText57(7, 45, AsciiString,0);         	//Write the new number
	if(HEATER)OLED_FastText57(7, 35, "*",0); 		//Heater indication
	else OLED_FastText57(7, 35, " ",0);
	
}//	OLED_UpdateThermistorReading

/***********************************************************/
void OLED_UpdateSetRPM(void)
{
char AsciiString[10];	
int data1;
extern char RPM_Change;  //set if RPM has changed
	
	data1=RPM_Setting/10;							//Display RPM Setting
	sprintf(AsciiString, "%3uRPM", (int)data1);    	//Converts number to text 
	OLED_FastText57(7, 85, AsciiString,0);          //Write the new number
	
	OLED_FastText57(4, 0, "Ext. Rate:",0);    	//Display Extrusion Rate
	ExtrusionRate= (float)RPM_Setting*0.04643;
	sprintf(AsciiString, "%5.1fmm/s", ExtrusionRate);	//Converts number to text
	OLED_FastText57(4, 75, AsciiString,0);     	//Write the new number
	
	RPM_Change = 0;
	
}//OLED_UpdateSetRPM
	
/***********************************************************/
void OLED_UpdateSetTemperature(void)
{
char AsciiString[10];
extern char Temp_Change; //set if Temperature has changed	

	if (SetTemperature <0)SetTemperature = 0;
	sprintf(AsciiString, "%3uC", (int)SetTemperature); //Converts number to text
	OLED_FastText57(7, 0, AsciiString,0);           //Write the new number
	Temp_Change = 0;
	
}//OLED_UpdateSetTemperature

/***********************************************************/	
void OLED_Fill_RAM(unsigned char Data)
{
unsigned char i,j;

	for(i=0;i<8;i++){
        write_command(0xB0+i);
        write_command(0x00);
        write_command(0x10);             
		for(j=0;j<128;j++)write_data(Data);
	}
}//OLED_Fill_RAM
     
/***********************************************************/ 
void OLED_ProgressBar(unsigned char Line, int Value)
{
unsigned char j;

   write_command(0xB0+Line);
   write_command(0x00);
   write_command(0x10);
             
	for(j=0;j<Value;j++)
	{
		write_data(0x18);
	}
	for(j=Value;j<128;j++)
	{
		write_data(0x00);
	}
}//OLEDProgressBar

/***********************************************************/  
void OLED_ClearLine(unsigned char Line)	{
	
unsigned char j;

   write_command(0xB0+Line);
   write_command(0x00);
   write_command(0x10);
             
	for(j=0;j<128;j++)
	{
		write_data(0x00);
	}	
}//OLEDClearLine

/***********************************************************/  
void OLED_BitMapFill_RAM(unsigned char screen)
{
unsigned char i,j;
const unsigned char *screen_ptr;
int offset;

switch(screen)
	{
		case DSP_RAPMAN_LOGO:
		{
			screen_ptr = RAPMAN_LOGO;
			break;
		}
		case DSP_BfB_LOGO:
		{
			screen_ptr = BfB_LOGO;
			break;
		}
		case DSP_EXTRUDER_SCREEN:
		{
			screen_ptr = EXTRUDER_SCREEN;
			break;
		}
	}
 
 for(i=0;i<8;i++)   //loop through 8 pages
 {
  offset = i*128;
  write_command(0xB0+i); //set start of page
  write_command(0x00);
  write_command(0x10);
  
      	for(j=0;j<128;j++) //loop through each col on page
  	{
   		write_data(screen_ptr[offset+j]);
  	}
 }
}//BitMapFill_RAM

/***********************************************************/  
void OLED_FastText57(int txtpage, int txtcol, unsigned char* textptr, unsigned char colour)
{

unsigned char  add, lAddr, hAddr; 
int i, j, k;                       				// Loop counters
unsigned char pixelData[5];                  	// Stores character data
 	
  k = 0;
  add = txtcol;
  lAddr = 0x0F & add;    // Low address
  hAddr = 0x10 | (add >> 4);  // High address
  
  write_command(0xB0 + txtpage); //set start page
  write_command(lAddr);
  write_command(hAddr);
  
   for(i=0; textptr[i] != '\0'; ++i) // Loop through the passed string
   {
      if(textptr[i] < 'S')       // Checks if the letter is in the first text array
         memcpy(pixelData, TEXT[textptr[i]-' '], 5);
      else 
      	if(textptr[i] <= '~')     // Check if the letter is in the second array
		{
      		if (textptr[i]>91)//if ascii char is > [ then realign
       		{
      			memcpy(pixelData, TEXT2[textptr[i]- 84], 5); //1 more than S to realign the lower case letters
       		}
       		else
         	memcpy(pixelData, TEXT2[textptr[i]-'S'], 5);
      	}  
      	else
        memcpy(pixelData, TEXT[0], 5);   // Default to space
 	
      for(j=0; j<5; ++j)         // Loop through character byte data
      {    
	      if (k <128){
		    if (colour == 0)
		    {   
          		write_data(pixelData[j]);
      		} 
      		else
      		{
	      		write_data(~pixelData[j]);	
	      	}   	
          	++k;
       	  }
       	  else{ //text wrap if required
       	  	write_command(0xB0 + txtpage+1);
       	  	write_data(pixelData[j]); 
       	  }	  
      }
      write_data(0x00);
      ++k;
	}
}//OLED_FastText

/***********************************************************/  
void OLED_Start_Menu(void)
{
	OLED_Fill_RAM(BLANK_SCREEN); //clear screen
	OLED_FastText57(0, 10, OLED_Header_VerNo,0);
	OLED_FastText57(1, 20, OLED_Menu_Title0,0);	
	OLED_FastText57(2, 20, OLED_Menu_0,0);	
	OLED_FastText57(3, 20, OLED_Menu_1,0);	
	OLED_FastText57(4, 20, OLED_Menu_2,0);	
	OLED_FastText57(5, 20, OLED_Menu_3,0);
			
}//OLED_Start_Menu

/***********************************************************/  
void OLED_Manual_Screen(void)
{
	OLED_Fill_RAM(BLANK_SCREEN); //clear screen
	OLED_FastText57(0, 10, OLED_Header_VerNo,0);
	OLED_FastText57(1, 0, "MANUAL", 0);
	OLED_FastText57(4, 0, "X_Step:",0);      
	OLED_FastText57(5, 0, "Y_Step:",0);    
	OLED_FastText57(6, 0, "Z_Step:",0); 
	
}//OLED_Manual_Screen

/***********************************************************/  
void OLED_Auto_Screen(void)
{
	OLED_Fill_RAM(BLANK_SCREEN); //clear screen
	OLED_FastText57(0, 10, OLED_Header_VerNo,0);
	OLED_FastText57(1, 20,OLED_Auto_Load,0);
	
}//OLED_Auto_Screen
	
/***********************************************************/ 
 void OLED_ToolSetup_Screen(void)
{
	OLED_ClearLine(1);
	OLED_FastText57(1, 20,OLED_ToolSet,0);
	
}//OLED_ToolSetup_Screen
	
/***********************************************************/  
void OLED_Home_Screen(void)
{
	OLED_Fill_RAM(BLANK_SCREEN); //clear screen	
	OLED_FastText57(1, 0,OLED_Home,0);
	
}//OLED_Home_Screen

/***********************************************************/  
void OLED_RapManMove_Screen(float X_pos, float Y_pos, float Z_pos, char DoZmove)
{
char AsciiString[10];

	OLED_Fill_RAM(BLANK_SCREEN); //clear screen	
	OLED_FastText57(1, 0, "MOVE TO:",0);
	sprintf(AsciiString, "X=%6.2f",X_pos);		// Converts number to text
	OLED_FastText57(3, 0, AsciiString,0);    	// Write the new number	
	sprintf(AsciiString, "Y=%6.2f",Y_pos);	    // Converts number to text
	OLED_FastText57(4, 0, AsciiString,0);    	// Write the new number	
	if (DoZmove)
	{  
		sprintf(AsciiString, "Z=%6.2f",Z_pos);	// Converts number to text
		OLED_FastText57(5, 0, AsciiString,0);   // Write the new number
	}
	else OLED_FastText57(5, 0, "NO Z MOVE",0);
	
}//OLED_Home_Screen

/***********************************************************/  
void OLED_FileEnd_Screen(void)
{
	OLED_Fill_RAM(BLANK_SCREEN);
	OLED_FastText57(0, 0, "Prog.End",0);
	OLED_FastText57(2, 0, "Return to Menu",0);
	OLED_FastText57(4, 0, "<<< Press Esc.",0);
		
}//OLED_FileEnd_Screen

/***********************************************************/  
void OLED_SetCursor(int txtpage, int txtcol, unsigned char colour)
{
	//Cursor
	switch (txtpage)
	{
		case 0: //txtpage 0 reserved for headings
		{
		//	OLED_FastText57(0, txtcol, OLED_Cursor, colour);	
		//	OLED_FastText57(1, txtcol, "  ",0);
		//	OLED_FastText57(2, txtcol, "  ",0);
		//	OLED_FastText57(3, txtcol, "  ",0);
		//	OLED_FastText57(4, txtcol, "  ",0);
		//	OLED_FastText57(5, txtcol, "  ",0);
		//	OLED_FastText57(6, txtcol, "  ",0);
		//	OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 1:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, OLED_Cursor, colour);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 2:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, OLED_Cursor, colour);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 3:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, OLED_Cursor, colour);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 4:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, OLED_Cursor, colour);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 5:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, OLED_Cursor, colour);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 6:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, OLED_Cursor, colour);
			OLED_FastText57(7, txtcol, "  ",0);
			break;
		}
		case 7:
		{
		//	OLED_FastText57(0, txtcol, "  ",0);	
			OLED_FastText57(1, txtcol, "  ",0);
			OLED_FastText57(2, txtcol, "  ",0);
			OLED_FastText57(3, txtcol, "  ",0);
			OLED_FastText57(4, txtcol, "  ",0);
			OLED_FastText57(5, txtcol, "  ",0);
			OLED_FastText57(6, txtcol, "  ",0);
			OLED_FastText57(7, txtcol, OLED_Cursor, colour);
			break;
		}
	}
	
}//OLED_SetCursor

/***********************************************************/
//SCREEN DRIVER
//Col address 0 to 127 is made up of a high and low nibble screen address
//col 1 is lower nibble 1, higher nibble 0
//col 127 is lower nibble = f, higher nibble 7
/***********************************************************/
int WriteSPI(int i)	{

     SPI2BUF = i;
     while( !SPI2STATbits.SPIRBF);
     return SPI2BUF;
     
}//WriteSPI

/***********************************************************/
void write_command(unsigned char command){		
     
     DC = 0;		//When Low send Display command
     OLED_CS = 0;  //OLED chip select
     WriteSPI(command);
     OLED_CS = 1;
     DC =1;	 
      
}//write_command

/***********************************************************/
void write_data(unsigned char data)	{

     DC =1;	
     OLED_CS = 0;
     WriteSPI(data);
     OLED_CS = 1;
	 DC =1;	
	 
}//write_data

/***********************************************************/             
void Fill_RAM(unsigned char Data)
{
unsigned char i,j;
	
	for(i=0;i<8;i++)
	{
        write_command(0xB0+i);
        write_command(0x00);
        write_command(0x10);
             
		for(j=0;j<128;j++)
		{
			write_data(Data);
		}
	} 
}//Fill_RAM

/***********************************************************/
int OLED_Init(void)
{
unsigned int i = 0;

	SPI2CON = 0x8120; //Enable & configure SPI port

    DC = 0;					//When Low D7-D0 is Display command
    OLED_CS = 0;				//Communication with chip only when Low
    RES = 0;					//Reset when pin is low
    for(i=0;i<2000;i++);		//10ms delay
    RES = 1;					//Reset complete		
	for(i=0;i<2000;i++);		//10ms delay
	OLED_CS = 1;

//LCD commands
//panel_128x64
	write_command(0xd5);		//SetDisplayClock(0x10)
	write_command(0x10);
	
	write_command(0xd3);		//SetDisplayOffset(0)
	write_command(0);
	
	write_command(0xa8);		//SetMultiplex(63)
	write_command(63);
	
	write_command(0xd8);		//SetAreaColor(0)
	write_command(0);
	
	write_command(0x40);		//SetStartLine(0)
	
	write_command(0xa0);		//SetSegmentReMap(0)
	
	write_command(0xc8);		//SetCOMScan(8)
	
	write_command(0xda);		//SetCOMHWConfig(0x12)
	write_command(0x12);
	
	write_command(0x81);		//SetContrast(0xff)
	write_command(0xf0);
	
	write_command(0xa4);		//SetEntireDisplay(0)
	
	write_command(0xd9);		//Setprecharge(0xf2)
	write_command(0xf2);
		
	write_command(0xa6);		//SetNormal_Inverse_Display(0xa6 or 0xa7)
	
	write_command(0x26);     	//horizontal scroll setup           
	write_command(0x01);
	write_command(0x00);
	write_command(0x00);
	write_command(0x01);
	
	Fill_RAM(0x00);   			//Clear screen
	for(i=0;i<2000;i++);
	write_command(0xAF);		//display on 
	
}//InitOLED

/***********************************************************/ 
void OLED_Start_Msg(void)
{
	// Start Message  
    OLED_Fill_RAM(BLANK_SCREEN); //Clear screen
    OLED_BitMapFill_RAM(DSP_BfB_LOGO);
    Delayms(200);
    OLED_Fill_RAM(BLANK_SCREEN); //Clear screen
    OLED_BitMapFill_RAM(DSP_RAPMAN_LOGO);
    Delayms(200);
    	
}//OLED_Start_Msg

/***********************************************************/