/****************************************(abc912-18326.c)***********
* 有機ELカラーグラフィック テスト QT095B(SSD1331)
*******************************************************************/
#include "mcc_generated_files/mcc.h"
//--- SSD1331 初期化 ( []はデフォルト値 )
void SSD1331_Init(){
CS1_SetLow(); // Reset OLED (SSD1331))
__delay_ms(50); // 最終的にOLCDリセットは省略可
CS1_SetHigh();
__delay_ms(500);
gCS_SetLow(); // Select gCS
gDC_SetLow(); // Select Command
SPI1_ExchangeByte(0xAE); // Set Display Off
SPI1_ExchangeByte(0xA0); // Remap & Color Depth setting
SPI1_ExchangeByte(0x20); // =20H [40H],(0b00100000)
// A[7:6] = 00; 256 color
// A[5] = 1; Enable COM Sprit
// A[4] = 0; Scan from 0-COMn
// A[3] = 0; Disable Swaping
// A[2] = 0; Norma Order (RGB)
// A[1] = 0; RAM Colum Seg:95-0
// A[0] = 0; Horizontal Address Incriment
SPI1_ExchangeByte(0xA1); // Set Display Start Line
SPI1_ExchangeByte(0); // = 0 [00H]
SPI1_ExchangeByte(0xA2); // Set Display Offset
SPI1_ExchangeByte(0); // = 0 [00H]
SPI1_ExchangeByte(0xA4); // Set Display Mode (Normal)
SPI1_ExchangeByte(0xA8); // Set Multiplex Ratio
SPI1_ExchangeByte(63); // = 63 [63]
SPI1_ExchangeByte(0xAD); // Set Master Configration
SPI1_ExchangeByte(0x8E); // =8E [8FH],a[0]=0 Select external Vcc supply
SPI1_ExchangeByte(0xB0); // Power Save Mode
SPI1_ExchangeByte(0x1A); // = 1AH [1AH},Enable power save mode
SPI1_ExchangeByte(0xB1); // Phase 1 and 2 period adjustment
SPI1_ExchangeByte(0x74); // = 74H [74H]
SPI1_ExchangeByte(0xB3); // Display Clock DIV
SPI1_ExchangeByte(0xF0); // = F0H [D0H]
SPI1_ExchangeByte(0x8A); // Pre Charge A
SPI1_ExchangeByte(0x81); // = 81H [81H]
SPI1_ExchangeByte(0x8B); // Pre Charge B
SPI1_ExchangeByte(0x82); // = 82H [82H]
SPI1_ExchangeByte(0x8C); // Pre Charge C
SPI1_ExchangeByte(0x83); // = 83H [83H]
SPI1_ExchangeByte(0xBB); // Set Pre-charge level
SPI1_ExchangeByte(0x3A); // = 3AH [3EH]
SPI1_ExchangeByte(0xBE); // Set VcomH
SPI1_ExchangeByte(0x3E); // = 3EH [3EH]
SPI1_ExchangeByte(0x87); // Set Master Current Control
SPI1_ExchangeByte(0x06); // = 06H [0FH]
SPI1_ExchangeByte(0x15); // Set Column Address
SPI1_ExchangeByte(0); // = 00 [00]
SPI1_ExchangeByte(95); // = 95 [95]
SPI1_ExchangeByte(0x75); // Set Row Address
SPI1_ExchangeByte(0); // = 00 [00]
SPI1_ExchangeByte(63); // = 63 [63]
SPI1_ExchangeByte(0x81); // Set Contrast for Color A
SPI1_ExchangeByte(255); // = 255 [80H]
SPI1_ExchangeByte(0x82); // Set Contrast for Color B
SPI1_ExchangeByte(255); // = 255 [80H]
SPI1_ExchangeByte(0x83); // Set Contrast for Color C
SPI1_ExchangeByte(255); // = 255 [80H]
SPI1_ExchangeByte(0xAF); // Set Display On
__delay_ms(110); // 0xAFコマンド後最低100ms必要
gCS_SetHigh(); // DeSelect gCS
}
//--- 画面クリア
void gOLED_Clr(uint8_t x0,uint8_t y0,uint8_t x1,uint8_t y1){
gCS_SetLow(); // Select gCS
gDC_SetLow(); // Select Comand
SPI1_ExchangeByte(0x25); // Line Command
SPI1_ExchangeByte(x0); // Start X
SPI1_ExchangeByte(y0); // Start Y
SPI1_ExchangeByte(x1); // End X
SPI1_ExchangeByte(y1); // End Y
gCS_SetHigh(); // DeSelect gCS
__delay_ms(1);
}
//---- Set 256Color ( R = 0-7, G = 0-7, B = 0-3 )
uint8_t gRGB256(uint8_t r,uint8_t g, uint8_t b){
return (uint8_t)((r << 5) | (g << 2) | b);
}
//--- 塗りつぶし指定
void gOLED_Fill(uint8_t md){
gCS_SetLow(); // Select gCs
gDC_SetLow(); // Select Comand
SPI1_ExchangeByte(0x26); // Fill Command
SPI1_ExchangeByte(md); // set Mode
gCS_SetHigh(); // DeSelect gCs
__delay_ms(1);
}
//---- 線描画
void gOLED_Line(uint8_t x0,uint8_t y0, uint8_t x1,uint8_t y1, uint8_t r, uint8_t g ,uint8_t b){
gCS_SetLow(); // Select gCs
gDC_SetLow(); // Select Comand
SPI1_ExchangeByte(0x21); // Line Command
SPI1_ExchangeByte(x0); // Start X
SPI1_ExchangeByte(y0); // Start Y
SPI1_ExchangeByte(x1); // End X
SPI1_ExchangeByte(y1); // End Y
SPI1_ExchangeByte(r); // Line color Red
SPI1_ExchangeByte(g); // Line color Green
SPI1_ExchangeByte(b); // Line color Blue
gCS_SetHigh(); // DeSelect gCs
__delay_ms(1);
}
//---- 四角形描画
void gOLED_Rect(uint8_t x0,uint8_t y0, uint8_t x1,uint8_t y1, uint8_t r, uint8_t g ,uint8_t b){
gCS_SetLow(); // Select gCs
gDC_SetLow(); // Select Comand
SPI1_ExchangeByte(0x22); // Rect Command
SPI1_ExchangeByte(x0); // Start X
SPI1_ExchangeByte(y0); // Star Y
SPI1_ExchangeByte(x1); // End X
SPI1_ExchangeByte(y1); // End Y
SPI1_ExchangeByte(r); // Line color Red
SPI1_ExchangeByte(g); // Line color Green
SPI1_ExchangeByte(b); // Line color Blue
SPI1_ExchangeByte(r); // Fill color Red
SPI1_ExchangeByte(g); // Fill color Green
SPI1_ExchangeByte(b); // Fill color Blue
gCS_SetHigh(); // DeSelect gCS
__delay_ms(1);
}
//--- Test QT095 (1)
void test1(){
uint8_t i, j;
uint8_t Dot1, Dot2, Dot3, Dot4;
Dot1 = gRGB256(0,7,0);
Dot2 = gRGB256(7,0,0);
Dot3 = gRGB256(0,0,3);
Dot4 = gRGB256(7,7,0);
gOLED_Clr(0,0,95,63);
gCS_SetLow(); // Selct gCS
gDC_SetHigh(); // Selct data
for(j = 0; j < 64; j++){
for(i = 0; i < 96; i++){
if(j < 32){
if(i < 32) SPI1_ExchangeByte(Dot1);
else SPI1_ExchangeByte(Dot3);
}else{
if(i < 48) SPI1_ExchangeByte(Dot2);
else SPI1_ExchangeByte(Dot4);
}
}
}
gCS_SetHigh(); // DeSelect gCS
}
//--- Test QT095 (2) (Color Map)
void test2(){
uint8_t i,j,r,g,b,col;
gOLED_Clr(0,0,95,63);
gCS_SetLow(); // Selct gCS
gDC_SetHigh(); // Selct data
for(g=0; g<8; g++){
for(i=0; i<8; i++){
for(b=0;b<4;b++){
for(r=0;r<8;r++){
col=(uint8_t)((r<<5)+(g<<2)+b);
SPI1_ExchangeByte(col);
SPI1_ExchangeByte(col);
SPI1_ExchangeByte(col);
}
}
}
}
gCS_SetHigh(); // DeSelect gCS
}
//--- Test QT095 (3) (Draw Command)
void test3(){
gOLED_Clr(0,0,95,63);
gOLED_Line( 0, 0,95,63,63,63,63);
gOLED_Line( 0,63,95, 0, 0, 0,63);
gOLED_Fill(0); // 塗りつぶし無し
gOLED_Rect(16,12,78,51,63, 0, 0);
gOLED_Fill(1); // 塗りつぶし有り
gOLED_Rect(32,24,63,40, 0,63, 0);
}
/**************************************
* Main application
***************************************/
void main(void){
SYSTEM_Initialize();
SSP1CON1bits.SSPEN = 1;
SSD1331_Init();
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
IO_RA4_SetHigh();
while (1)
{
test1();
__delay_ms(2000);
IO_RA4_Toggle();
test2();
__delay_ms(2000);
IO_RA4_Toggle();
test3();
__delay_ms(2000);
IO_RA4_Toggle();
}
}
/**** End of File *****/
|