int WriteCommand(int cmdd) {send_command(cmdd); } //****************************************************************************** // SENDET EIN KOMMANDOBYTE Hardware SPI int send_command(int cmd) { PORTGbits.RG14 = 0; //CS,FALSE PORTGbits.RG13 = 0; //D/C, FALSE WriteSPI2(cmd); int i=100; while(i>0) i--; PORTGbits.RG14 = 1; //CS,TRUE PORTGbits.RG13 = 1; //D/C, TRUE return 0; //keine Rückgabe } int WriteCommand(int cmdd) {send_command(cmdd); } //****************************************************************************** // SENDET EIN DATENBYTE Hardware SPI void send_data(int data) { PORTGbits.RG14 = 0; //CS,FALSE PORTGbits.RG13 = 0; //D/C, FALSE WriteSPI2(data); PORTGbits.RG14 = 0; //CS,FALSE PORTGbits.RG13 = 0; //D/C, FALSE } //****************************************************************************** //****************************************************************************** // INITSALISIERT DAS OLED DISPALY // Hier werden einige Daten wie z.B. Displaygröße und Kontrast eingestellt // Dies ist notwendig damit das Display richtig arbeitet void init_oled(void) { // Column Address WriteCommand(0x15); /* Set Column Address */ WriteCommand(0x00); /* Start = 0 */ WriteCommand(0x3F); /* End = 127 */ // Row Address WriteCommand(0x75); /* Set Row Address */ WriteCommand(0x00); /* Start = 0 */ WriteCommand(0x3F); /* End = 63 */ // Contrast Control WriteCommand(0x81); /* Set Contrast Control */ WriteCommand(0x33); /* 0 ~ 127 */ // Current Range WriteCommand(0x86); /* Set Current Range 84h:Quarter, 85h:Half, 86h:Full*/ // Re-map WriteCommand(0xA0); /* Set Re-map */ WriteCommand(0x52); /* [0]:MX, [1]:Nibble, [2]:H/V address [4]:MY, [6]:Com Split Odd/Even "1000010"*/ // Display Start Line WriteCommand(0xA1); /* Set Display Start Line */ WriteCommand(0x00); /* Top */ // Display Offset WriteCommand(0xA2); /* Set Display Offset */ WriteCommand(0x40); /* No offset */ // Display Mode WriteCommand(0xA4); /* Set DisplaMode,A4:Normal, A5:All ON, A6: All OFF, A7:Inverse */ // Multiplex Ratio WriteCommand(0xA8); /* Set Multiplex Ratio */ WriteCommand(0x3F); /* [6:0]16~128, 64 rows=3Fh*/ // Phase Length WriteCommand(0xB1); /* Set Phase Length */ WriteCommand(0x22); /* [3:0]:Phase 1 period of 1~16 clocks */ /* [7:4]:Phase 2 period of 1~16 clocks /* POR = 0111 0100 */ // Row Period WriteCommand(0xB2); /* Set Row Period */ WriteCommand(0x46); /* [7:0]:18~255, K=P1+P2+GS15 (POR:4+7+29)*/ // Display Clock Divide WriteCommand(0xB3); /* Set Clock Divide */ WriteCommand(0x41); /* [3:0]:1~16, [7:4]:0~16 */ /* POR = 0000 0001 */ // VSL WriteCommand(0xBF); /* Set VSL */ WriteCommand(0x0D); /* [3:0]:VSL */ // CCOMH WriteCommand(0xBE); /* Set VCOMH */ WriteCommand(0x00); /* [7:0]:VCOMH */ // VP WriteCommand(0xBC); /* Set VP */ WriteCommand(0x0B); /* [7:0]:VP */ // Gamma WriteCommand(0xB8); /* Set Gamma with next 8 bytes*/ WriteCommand(0x01); /* L1[2:1] */ WriteCommand(0x11); /* L3[6:4], L2[2:0] 0001 0001*/ WriteCommand(0x22); /* L5[6:4], L4[2:0] 0010 0010*/ WriteCommand(0x32); /* L7[6:4], L6[2:0] 0011 1011*/ WriteCommand(0x43); /* L9[6:4], L8[2:0] 0100 0100*/ WriteCommand(0x54); /* LB[6:4], LA[2:0] 0101 0101*/ WriteCommand(0x65); /* LD[6:4], LC[2:0] 0110 0110*/ WriteCommand(0x76); /* LF[6:4], LE[2:0] 1000 0111*/ // Set DC-DC WriteCommand(0xAD); /* Set DC-DC */ WriteCommand(0x02); /* 03=ON, 02=Off */ // Display ON/OFF WriteCommand(0xAF); /* AF=ON, AE=Sleep Mode */ WriteCommand(0xA5); }