//****************************************************************************** // OLED SSD1336 Color // ***************************************************************************** /** Generated Main Source File Company: Microchip Technology Inc. File Name: main.c Summary: This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs Description: This header file provides implementations for driver APIs for all modules selected in the GUI. Generation Information : Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2 Device : PIC16F18857 Driver Version : 2.00 */ /* (c) 2018 Microchip Technology Inc. and its subsidiaries. Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. It is your responsibility to comply with third party license terms applicable to your use of third party software (including open source software) that may accompany Microchip software. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. */ //--------------------------------- // 定義エリア //--------------------------------- #include "mcc_generated_files/mcc.h" #include #define _XTAL_FREQ 32000000 #define on 0 #define off 1 #define Reset_SLED LATC1 #define Monitor LATC0 #define Horiz 0x00 #define Vert 0x01 #define Page 0x02 #define Scrl 0 #define Page 1 //------------------------------------------- // ASCII Font Data //------------------------------------------- const unsigned char ASCII_font[193][5] = { { 0x00, 0x00, 0x00, 0x00, 0x00}, // " " 0x20 { 0x00, 0x00, 0x4f, 0x00, 0x00}, // ! 0x21 { 0x00, 0x07, 0x00, 0x07, 0x00}, // " 0x22 { 0x14, 0x7f, 0x14, 0x7f, 0x14}, // # 0x23 { 0x24, 0x2a, 0x7f, 0x2a, 0x12}, // $ 0x24 { 0x23, 0x13, 0x08, 0x64, 0x62}, // % 0x25 { 0x36, 0x49, 0x55, 0x22, 0x50}, // & 0x26 { 0x00, 0x05, 0x03, 0x00, 0x00}, // ' 0x27 { 0x00, 0x1c, 0x22, 0x41, 0x00}, // ( 0x28 { 0x00, 0x41, 0x22, 0x1c, 0x00}, // ) 0x29 { 0x14, 0x08, 0x3e, 0x08, 0x14}, // * 0x2A { 0x08, 0x08, 0x3e, 0x08, 0x08}, // + 0x2B { 0x00, 0x50, 0x30, 0x00, 0x00}, // , 0x2C { 0x08, 0x08, 0x08, 0x08, 0x08}, // - 0x2D { 0x00, 0x60, 0x60, 0x00, 0x00}, // . 0x2E { 0x20, 0x10, 0x08, 0x04, 0x02}, // / 0x2F { 0x3e, 0x51, 0x49, 0x45, 0x3e}, // 0 0x30 { 0x00, 0x42, 0x7f, 0x40, 0x00}, // 1 0x31 { 0x42, 0x61, 0x51, 0x49, 0x46}, // 2 0x32 { 0x21, 0x41, 0x45, 0x4b, 0x31}, // 3 0x33 { 0x18, 0x14, 0x12, 0x7f, 0x10}, // 4 0x34 { 0x27, 0x45, 0x45, 0x45, 0x39}, // 5 0x35 { 0x3c, 0x4a, 0x49, 0x49, 0x30}, // 6 0x36 { 0x01, 0x71, 0x09, 0x05, 0x03}, // 7 0x37 { 0x36, 0x49, 0x49, 0x49, 0x36}, // 8 0x38 { 0x06, 0x49, 0x49, 0x29, 0x1e}, // 9 0x39 { 0x00, 0x36, 0x36, 0x00, 0x00}, // : 0x3A { 0x00, 0x56, 0x36, 0x00, 0x00}, // ; 0x3B { 0x08, 0x14, 0x22, 0x41, 0x00}, // 0x3C { 0x14, 0x14, 0x14, 0x14, 0x14}, // = 0x3D { 0x00, 0x41, 0x22, 0x14, 0x08}, // > 0x3E { 0x02, 0x01, 0x51, 0x09, 0x06}, // ? 0x3F { 0x32, 0x49, 0x79, 0x41, 0x3e}, // @ 0x40 { 0x7e, 0x11, 0x11, 0x11, 0x7e}, // A 0x41 { 0x7f, 0x49, 0x49, 0x49, 0x36}, // B 0x42 { 0x3e, 0x41, 0x41, 0x41, 0x22}, // C 0x43 { 0x7f, 0x41, 0x41, 0x22, 0x1c}, // D 0x44 { 0x7f, 0x49, 0x49, 0x49, 0x41}, // E 0x45 { 0x7f, 0x09, 0x09, 0x09, 0x01}, // F 0x46 { 0x3e, 0x41, 0x49, 0x49, 0x7a}, // G 0x47 { 0x7f, 0x08, 0x08, 0x08, 0x7f}, // H 0x48 { 0x00, 0x41, 0x7f, 0x41, 0x00}, // I 0x49 { 0x20, 0x40, 0x41, 0x3f, 0x01}, // J 0x4A { 0x7f, 0x08, 0x14, 0x22, 0x41}, // K 0x4B { 0x7f, 0x40, 0x40, 0x40, 0x40}, // L 0x4C { 0x7f, 0x02, 0x0c, 0x02, 0x7f}, // M 0x4D { 0x7f, 0x04, 0x08, 0x10, 0x7f}, // N 0x4E { 0x3e, 0x41, 0x41, 0x41, 0x3e}, // O 0x4F { 0x7f, 0x09, 0x09, 0x09, 0x06}, // P 0X50 { 0x3e, 0x41, 0x51, 0x21, 0x5e}, // Q 0X51 { 0x7f, 0x09, 0x19, 0x29, 0x46}, // R 0X52 { 0x46, 0x49, 0x49, 0x49, 0x31}, // S 0X53 { 0x01, 0x01, 0x7f, 0x01, 0x01}, // T 0X54 { 0x3f, 0x40, 0x40, 0x40, 0x3f}, // U 0X55 { 0x1f, 0x20, 0x40, 0x20, 0x1f}, // V 0X56 { 0x3f, 0x40, 0x38, 0x40, 0x3f}, // W 0X57 { 0x63, 0x14, 0x08, 0x14, 0x63}, // X 0X58 { 0x07, 0x08, 0x70, 0x08, 0x07}, // Y 0X59 { 0x61, 0x51, 0x49, 0x45, 0x43}, // Z 0X5A { 0x00, 0x7f, 0x41, 0x41, 0x00}, // [ 0X5B { 0x02, 0x04, 0x08, 0x10, 0x20}, // "\" 0X5C { 0x00, 0x41, 0x41, 0x7f, 0x00}, // ] 0X5D { 0x04, 0x02, 0x01, 0x02, 0x04}, // ^ 0X5E { 0x40, 0x40, 0x40, 0x40, 0x40}, // _ 0X5F { 0x00, 0x01, 0x02, 0x04, 0x00}, // ` 0X60 { 0x20, 0x54, 0x54, 0x54, 0x78}, // a 0X61 { 0x7f, 0x48, 0x44, 0x44, 0x38}, // b 0X62 { 0x38, 0x44, 0x44, 0x44, 0x20}, // c 0X63 { 0x38, 0x44, 0x44, 0x48, 0x7f}, // d 0X64 { 0x38, 0x54, 0x54, 0x54, 0x18}, // e 0X65 { 0x08, 0x7e, 0x09, 0x01, 0x02}, // f 0X66 { 0x0c, 0x52, 0x52, 0x52, 0x3e}, // g 0X67 { 0x7f, 0x08, 0x04, 0x04, 0x78}, // h 0X68 { 0x00, 0x44, 0x7d, 0x40, 0x00}, // i 0X69 { 0x20, 0x40, 0x44, 0x3d, 0x00}, // j 0X6A { 0x7f, 0x10, 0x28, 0x44, 0x00}, // k 0X6B { 0x00, 0x41, 0x7f, 0x40, 0x00}, // l 0X6C { 0x7c, 0x04, 0x18, 0x04, 0x78}, // m 0X6D { 0x7c, 0x08, 0x04, 0x04, 0x78}, // n 0X6E { 0x38, 0x44, 0x44, 0x44, 0x38}, // o 0X6F { 0x7c, 0x14, 0x14, 0x14, 0x08}, // p 0X70 { 0x08, 0x14, 0x14, 0x18, 0x7c}, // q 0X71 { 0x7c, 0x08, 0x04, 0x04, 0x08}, // r 0X72 { 0x48, 0x54, 0x54, 0x54, 0x20}, // s 0X73 { 0x04, 0x3f, 0x44, 0x40, 0x20}, // t 0X74 { 0x3c, 0x40, 0x40, 0x20, 0x7c}, // u 0X75 { 0x1c, 0x20, 0x40, 0x20, 0x1c}, // v 0X76 { 0x3c, 0x40, 0x30, 0x40, 0x3c}, // w 0X77 { 0x44, 0x28, 0x10, 0x28, 0x44}, // x 0X78 { 0x0c, 0x50, 0x50, 0x50, 0x3c}, // y 0X79 { 0x44, 0x64, 0x54, 0x4c, 0x44}, // z 0X7A { 0x00, 0x08, 0x36, 0x41, 0x00}, // { 0X7B { 0x00, 0x00, 0x7f, 0x00, 0x00}, // | 0X7C { 0x00, 0x41, 0x36, 0x08, 0x00}, // } 0X7D { 0x08, 0x08, 0x2a, 0x1c, 0x08}, // -> 0X7E { 0x08, 0x1c, 0x2a, 0x08, 0x08}, // - 0X7F { 0x00, 0x00, 0x0f, 0x08, 0x08}, // 0x80 { 0x08, 0x08, 0x0f, 0x00, 0x00}, // 0x81 { 0x2c, 0x32, 0x02, 0x32, 0x2c}, // ohm 0x82 { 0x44, 0x3c, 0x04, 0x7c, 0x44}, // pi 0x83 { 0x63, 0x55, 0x49, 0x41, 0x41}, // siguma0x84 { 0x14, 0x14, 0x7c, 0x14, 0x12}, // sec 0x85 { 0x44, 0x3c, 0x14, 0x14, 0x74}, // man 0x86 { 0x7c, 0x14, 0x1c, 0x14, 0x7c}, // en 0x87 { 0x10, 0x10, 0x54, 0x10, 0x10}, // waru0x88 { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f}, // 0x89 { 0x0f, 0x0f, 0x0f, 0x0f, 0x0f}, // 0x8A { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x8B { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x8C { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x8D { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x8E { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x8F { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x90 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x91 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x92 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x93 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x94 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x95 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x96 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x97 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x98 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x99 { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9A { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9B { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9C { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9D { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9E { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x9F { 0x00, 0x00, 0x00, 0x00, 0x00}, // 0xA0 { 0x70, 0x50, 0x70, 0x00, 0x00}, // . 0xA1 { 0x00, 0x00, 0x0f, 0x01, 0x01}, // [ 0xA2 { 0x40, 0x40, 0x78, 0x00, 0x00}, // ] 0xA3 { 0x10, 0x20, 0x40, 0x00, 0x00}, // , 0xA4 { 0x00, 0x18, 0x18, 0x00, 0x00}, // . 0xA5 { 0x0a, 0x0a, 0x4a, 0x2a, 0x1e}, // wo 0xA6 { 0x04, 0x24, 0x34, 0x14, 0x0c}, // a 0xA7 { 0x20, 0x10, 0x78, 0x04, 0x00}, // i 0xA8 { 0x18, 0x08, 0x4c, 0x48, 0x38}, // u 0xA9 { 0x48, 0x48, 0x78, 0x48, 0x48}, // e 0xAA { 0x48, 0x28, 0x18, 0x7c, 0x08}, // o 0xAB { 0x08, 0x7c, 0x08, 0x28, 0x18}, // ya 0xAC { 0x40, 0x48, 0x48, 0x78, 0x40}, // yu 0xAD { 0x54, 0x54, 0x54, 0x7c, 0x00}, // yo 0xAE { 0x18, 0x00, 0x58, 0x40, 0x38}, // tu 0xAF { 0x08, 0x08, 0x08, 0x08, 0x08}, // - 0xB0 { 0x01, 0x41, 0x3d, 0x09, 0x07}, // a 0xB1 { 0x20, 0x10, 0x7c, 0x02, 0x01}, // i 0xB2 { 0x0e, 0x02, 0x43, 0x22, 0x1e}, // u 0xB3 { 0x42, 0x42, 0x7e, 0x42, 0x42}, // e 0xB4 { 0x22, 0x12, 0x0a, 0x7f, 0x02}, // o 0xB5 { 0x42, 0x3f, 0x02, 0x42, 0x3e}, // ka 0xB6 { 0x0a, 0x0a, 0x7f, 0x0a, 0x0a}, // ki 0xB7 { 0x08, 0x46, 0x42, 0x22, 0x1e}, // ku 0xB8 { 0x04, 0x03, 0x42, 0x3e, 0x04}, // ke 0xB9 { 0x42, 0x42, 0x42, 0x42, 0x7e}, // ko 0xBA { 0x02, 0x4f, 0x22, 0x1f, 0x02}, // sa 0xBB { 0x4a, 0x4a, 0x40, 0x20, 0x1c}, // si 0xBC { 0x42, 0x22, 0x12, 0x2a, 0x46}, // su 0xBD { 0x02, 0x3f, 0x42, 0x4a, 0x46}, // se 0xBE { 0x06, 0x48, 0x40, 0x20, 0x1e}, // so 0xBF { 0x08, 0x46, 0x4a, 0x32, 0x1e}, // ta 0xC0 { 0x0a, 0x4a, 0x3e, 0x09, 0x08}, // ti 0xC1 { 0x0e, 0x00, 0x4e, 0x20, 0x1e}, // tu 0xC2 { 0x04, 0x45, 0x3d, 0x05, 0x04}, // te 0xC3 { 0x00, 0x7f, 0x08, 0x10, 0x00}, // to 0xC4 { 0x44, 0x24, 0x1f, 0x04, 0x04}, // na 0xC5 { 0x40, 0x42, 0x42, 0x42, 0x40}, // ni 0xC6 { 0x42, 0x2a, 0x12, 0x2a, 0x06}, // nu 0xC7 { 0x22, 0x12, 0x7b, 0x16, 0x22}, // ne 0xC8 { 0x00, 0x40, 0x20, 0x1f, 0x00}, // no 0xC9 { 0x78, 0x00, 0x02, 0x04, 0x78}, // ha 0xCA { 0x3f, 0x44, 0x44, 0x44, 0x44}, // hi 0xCB { 0x02, 0x42, 0x42, 0x22, 0x1e}, // hu 0xCC { 0x04, 0x02, 0x04, 0x08, 0x30}, // he 0xCD { 0x32, 0x02, 0x7f, 0x02, 0x32}, // ho 0xCE { 0x02, 0x12, 0x22, 0x52, 0x0e}, // ma 0xCF { 0x00, 0x2a, 0x2a, 0x2a, 0x40}, // mi 0xD0 { 0x38, 0x24, 0x22, 0x20, 0x70}, // mu 0xD1 { 0x40, 0x28, 0x10, 0x28, 0x06}, // me 0xD2 { 0x0a, 0x3e, 0x4a, 0x4a, 0x4a}, // mo 0xD3 { 0x04, 0x7f, 0x04, 0x14, 0x0c}, // ya 0xD4 { 0x40, 0x42, 0x42, 0x7e, 0x40}, // yu 0xD5 { 0x4a, 0x4a, 0x4a, 0x4a, 0x7e}, // yo 0xD6 { 0x04, 0x05, 0x45, 0x25, 0x1c}, // ra 0xD7 { 0x0f, 0x40, 0x20, 0x1f, 0x00}, // ri 0xD8 { 0x7c, 0x00, 0x7e, 0x80, 0x30}, // ru 0xD9 { 0x7e, 0x40, 0x20, 0x10, 0x08}, // re 0xDA { 0x7e, 0x42, 0x42, 0x42, 0x7e}, // ro 0xDB { 0x0e, 0x02, 0x42, 0x22, 0x1e}, // wa 0xDC { 0x42, 0x42, 0x40, 0x20, 0x18}, // n 0xDD { 0x02, 0x04, 0x01, 0x02, 0x00}, // " 0xDE { 0x07, 0x05, 0x07, 0x00, 0x00} // . 0xDF }; //-------------------------------------------- // Color Code 設定 //-------------------------------------------- unsigned char Color_Set[9][3] = {// Red(3) Green(3) Blue(2) {0, 0, 0}, // CC = 0 黒 {0, 0, 3}, // CC = 1 青 {0, 7, 0}, // CC = 2 緑 {0, 7, 3}, // CC = 3 水色 {7, 0, 0}, // CC = 4 赤 {7, 0, 3}, // CC = 5 紫 {7, 7, 0}, // CC = 6 黄 {7, 7, 3}, // CC = 7 白 {0, 0, 0}, // CC = 0 }; //------------------------------------------------- // 表示用フォント全画面バッファ ( 6 x 8) ( 21 x 8 ) //------------------------------------------------- unsigned char Font_Buff_Page[8][128]; // [page] [column] //--------------------------------------- // 一文字表示用フォントバッファ //--------------------------------------- //unsigned char Font_Buff_CHR[6] = 0; // 8 x 6 (右と下のスペースを含む) unsigned char Text_Buff[169] = 0; // 一回分の最大テキスト(21x8行) //----------------------------------- // グローバル変数定義 //----------------------------------- int i, j; //---------------------------------- //----------------------------------------------------------------------------- // 各種処理関数定義 //----------------------------------------------------------------------------- void SPI_Send_8(unsigned char, unsigned char); //基本SPI送信 void SPI_Send_88(unsigned char, unsigned char, unsigned char); void SSD1331_OLED_Init(void); //OLED初期化 void SSD1331_OLED_Reset(void); //初期セットアップ void SSD1331_OLED_ClearAll(void); //画面(内蔵バッファ)クリア void SSD1331_OLED_ClearWindow(unsigned char, unsigned char, unsigned char, unsigned char); //指定画面クリア void SSD1331_OLED_ColorCont(unsigned char); //3色共通カラーコントラストセット void SSD1331_OLED_SetWindow(unsigned char, unsigned char, unsigned char, unsigned char); void SSD1331_OLED_DrawLine(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char); // 直線描画 void SSD1331_OLED_DataSetAll(int); // カラーコードをセット void SSD1331_OLED_Cursor(int, int, int, int); // カーソルセット(X=0?15、Y=0?8) void SSD1331_OLED_CDisp(unsigned char *, int, int, int, int, int); //------------------------------------------------------------------------- // 標準出力対応設定 //------------------------------------------------------------------------- void main(void) { __delay_ms(1000); // initialize the device SYSTEM_Initialize(); // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits // Use the following macros to: // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); // Enable the Peripheral Interrupts INTERRUPT_PeripheralInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); // Disable the Peripheral Interrupts //INTERRUPT_PeripheralInterruptDisable(); //---------------- // 起動確認LED点滅 //---------------- Monitor = 0; // LED on __delay_ms(100); Monitor = 1; // LED off __delay_ms(100); Monitor = 0; // LED on __delay_ms(100); Monitor = 1; // LED off __delay_ms(100); //------------------- // OLED 初期設定、消去 //------------------- SSD1331_OLED_Reset(); // Hard Reset SSD1331_OLED_Init(); // 初期化 SSD1331_OLED_ColorCont(0xFF); // カラーコントラスト最大に SSD1331_OLED_ClearAll(); //全画面クリア __delay_ms(1000); //--------------------- // 全ドットON //--------------------- SPI_Send_8(0x00, 0xA5); // 全ドットON テスト(白色) __delay_ms(1000); SPI_Send_8(0x00, 0xA4); // Normal Mode(全ドットON解除) //------------------------------- // テスト表示 //------------------------------- printf("\n"); printf("C Code Test \n"); for (i = 0; i <= 8; i++) { SSD1331_OLED_DataSetAll(i); printf("C Code %d\n", i); __delay_ms(2000); } __delay_ms(1000); //----------------- 文字表示 test ------------------------ for (i = 0; i <= 6; i++) { SSD1331_OLED_CDisp("VividHobby ", 0, i ,10, 0 , i + 1); } //******************************************************************** // 動作停止 //******************************************************************** while (1) { Monitor ^= 1; __delay_ms(50); } } //************************************************************************* // サブルーチン関数 //************************************************************************* //----------------------------------------------------------------------------- // 指定位置からカラーChalactor文字列表示 // 文字データ配列、Cursor X, Y, R, G, B //----------------------------------------------------------------------------- void SSD1331_OLED_CDisp(unsigned char *p, int x1, int y1, int x2, int y2, int CC) { //---- ローカル変数定義 ----------- unsigned char Font_Code, Template, Bit_Check, Color_Code, Dummy; int i, j, Char_cnt, Line_cnt, Dot_cnt, Max_Lcnt = 8, Max_Rcnt, x, y, Max_Ccnt; //----- Color Depth & Scan direction change ------ SPI_Send_8(0x00, 0xA0); // Set Color depth SPI_Send_8(0x00, 0b00100001); // as 256 , pin下にして、左上から左下へ表示 //--- 最大文字数/行を求める ----- Max_Rcnt = y2; // 位置でチェック Max_Lcnt = 8; Max_Ccnt = x2 - x1 + 1; y2 = y1 + 1; Set_Window: //--- X, Y から出力ウィンドウを設定 ---- SSD1331_OLED_Cursor(x1, y1, x2, y2); //--- カウンターリセット ----- Char_cnt = 0; Line_cnt = 0; Dot_cnt = 0; Template = 0b00000001; // fontの左上ドット指定 //--- カラーコードセット ------- Color_Code = (Color_Set[CC][0] << 5) | (Color_Set[CC][1] << 2) | (Color_Set[CC][2]); //--- 次の文字コードを読み込む ----- while (*p != '\0') { Font_Code = *p; Next_Font_Line: Bit_Check = ASCII_font[Font_Code - 0x20][Line_cnt] & Template; if (Bit_Check == 0) {// 指定ビットがゼロ(黒いドット) SPI_Send_8(1, 0x00); //下のデータが消される } else {// 指定ビットがカラードット SPI_Send_8(1, Color_Code); } Template = Template << 1; Dot_cnt++; if (Dot_cnt <= 7) goto Next_Font_Line; Dot_cnt = 0; Template = 0b00000001; Line_cnt++; if (Line_cnt < 5) goto Next_Font_Line; //--- 1文字出力完了 ---- Char_cnt++; p++; // 次の文字をセット if (Char_cnt < Max_Ccnt) { for (i = 0; i <= 7; i++) { SPI_Send_8(1, 0x00); // 文字間のドット } //--- カウンターリセット ------ Line_cnt = 0; Dot_cnt = 0; Template = 0b00000001; // fontの左上ドット指定 continue; // 次の文字 } //--- 新ウィンドウ設定 ----- y1 = y1 + 1; y2 = y2 + 1; if (y2 > Max_Rcnt + 1) { return; } //---- 最終行を除く行の最後の文字間ブランクドット --- for (i = 0; i <= 7; i++) { SPI_Send_8(1, 0x00); // 文字間のドット } goto Set_Window; } return; } //------------------------------------------------------------------------- // カーソルセット(X=0-15、Y=0-7) // カーソル先頭位置を指定すると、その行の末端を自動指定 //------------------------------------------------------------------------- void SSD1331_OLED_Cursor(int x1, int y1, int x2, int y2) { unsigned char CS, RS, CE, RE; x1 = x1 * 6; x2 = x2 * 6 + 6; y1 = y1 * 8; y2 = y1 + 7; if (y1 > 63) y1 = 63; CS = (unsigned char) (x1); CE = (unsigned char) (x2); RS = (unsigned char) (y1); RE = (unsigned char) (y2); SPI_Send_8(0x00, 0x15); //カラムカーソルセットと範囲指定 SPI_Send_8(0x00, CS); SPI_Send_8(0x00, CE); SPI_Send_8(0x00, 0x75); //ロウカーソルセットと範囲指定 SPI_Send_8(0x00, RS); SPI_Send_8(0x00, RE); } //----------------------------------------------------------------------- // 直線描画 //----------------------------------------------------------------------- void SSD1331_OLED_DrawLine(unsigned char CS, unsigned char RS, unsigned char CE, unsigned char RE, unsigned char Blu, unsigned char Grn, unsigned char Red) { SPI_Send_8(0x00, 0x21); SPI_Send_8(0x00, CS); SPI_Send_8(0x00, RS); SPI_Send_8(0x00, CE); SPI_Send_8(0x00, RE); SPI_Send_8(0x00, Blu); SPI_Send_8(0x00, Grn); SPI_Send_8(0x00, Red); } //------------------------------------------------------------------------- // ウィンドフレームウセット //------------------------------------------------------------------------- void SSD1331_OLED_SetWindow(unsigned char CS, unsigned char RS, unsigned char CE, unsigned char RE) { SPI_Send_8(0x00, 0x15); // Column SPI_Send_8(0x00, CS); SPI_Send_8(0x00, CE); SPI_Send_8(0x00, 0x75); // Row SPI_Send_8(0x00, RS); SPI_Send_8(0x00, RE); } //-------------------------------------------------------------------------- // 3色共通カラーコントラストセット //-------------------------------------------------------------------------- void SSD1331_OLED_ColorCont(unsigned char) { SPI_Send_8(0x00, 0x81); //Color A SPI_Send_8(0x00, 0xFF); SPI_Send_8(0x00, 0x82); //Color B SPI_Send_8(0x00, 0xFF); SPI_Send_8(0x00, 0x83); //Color C SPI_Send_8(0x00, 0xFF); }; //------------------------------------------------------------------------- // 全画面データセット //------------------------------------------------------------------------- void SSD1331_OLED_DataSetAll(int CC) { int k; unsigned char Color_Code; Color_Code = (Color_Set[CC][0] << 5) | (Color_Set[CC][1] << 2) | (Color_Set[CC][2]); for (k = 0; k <= 6143; k++) { SPI_Send_8(1, Color_Code); } } //------------------------------------------------------------------------- // 画面(内蔵バッファ)クリア //------------------------------------------------------------------------- void SSD1331_OLED_ClearAll(void) {//全画面クリア SPI_Send_8(0x00, 0x25); // Clearコマンド SPI_Send_8(0x00, 0x00); // Start Column SPI_Send_8(0x00, 0x00); // Start Row SPI_Send_8(0x00, 95); // End Column SPI_Send_8(0x00, 63); // End Row } //------------------------------------------------------------------------- // 指定画面(内蔵バッファ)クリア //------------------------------------------------------------------------- void SSD1331_OLED_ClearWindow(unsigned char SC, unsigned char SR, unsigned char EC, unsigned char ER) {//指定画面クリア SPI_Send_8(0x00, 0x25); // Clearコマンド SPI_Send_8(0x00, SC); // Start Column SPI_Send_8(0x00, SR); // Start Row SPI_Send_8(0x00, EC); // End Column SPI_Send_8(0x00, ER); // End Row } //------------------------------------------------------------------------------ // SPIにOLEDコマンド、データを送信 //------------------------------------------------------------------------------ void SPI_Send_8(unsigned char DC, unsigned char data) { LATC2 = DC; // 0 = command, 1 = data SPI1_Exchange8bit(data); } //------------------------------------------------------------------------------ // SPIにOLEDコマンド、データを送信2バイトデータ //------------------------------------------------------------------------------ void SPI_Send_88(unsigned char DC, unsigned char data1, unsigned char data2) { LATC2 = DC; // 0 = command, 1 = data SPI1_Exchange8bit(data1); SPI1_Exchange8bit(data2); } //------------------------------------------------------------------------------ // OLED初期化 //------------------------------------------------------------------------------ void SSD1331_OLED_Init(void) { SPI_Send_8(0x00, 0xA4); // Normal Display Mode SPI_Send_8(0x00, 0xAF); // Set Display On SPI_Send_8(0x00, 0xA0); // Set Color depth SPI_Send_8(0x00, 0b00100000); // as 256 , pin下にして、左上から右へ表示 SPI_Send_8(0x00, 0xB0); // Powersave mode SPI_Send_8(0x00, 0x0B); // No:Disable SPI_Send_8(0x00, 0x15); // Column Window Set SPI_Send_8(0x00, 0); // Start SPI_Send_8(0x00, 95); // End SPI_Send_8(0x00, 0x75); // Row Window Set SPI_Send_8(0x00, 0); // Start SPI_Send_8(0x00, 63); // End } //------------------------------------------------------------------------------ // 文字表示位置をカーソルに従って設定 //------------------------------------------------------------------------------ //----------------------------------------------------------------------------- // OLED ハードリセット //------------------------------------------------------------------------------ void SSD1331_OLED_Reset(void) { Reset_SLED = off; __delay_ms(10); Reset_SLED = on; __delay_ms(10); Reset_SLED = off; __delay_ms(1000); } /** End of File */