///////////////////////////////////////////////////////////////////////////////////// // I2C LCD ライブラリ PIC18 Ver 2.0 20130512 // ストロベリーリナックス液晶表示ライブラリ // 以下の機能を提供 // LCD_int() ----- 初期化 // LCD_cmd(cmd) ----- コマンド出力 // LCD_dat(chr) ----- 1文字表示 // LCD_str(*str) ---- 文字列表示 // LCD_ROMstr(*str) -- ROM文字列表示 // LCD_hex(char); // LCD_posyx(y,x) ---- カーソル位置指定、行 y、横位置 x // LCD_clr() ----- 全消去 // LCD_icon_on(icn);--- 指定アイコンON // LCD_icon_off(icn);-- 指定アイコンOFF // LCD_icon_clrf();---- 全アイコンOFF // LCD_cg_ram_user_set() ----- ユーザーキャラクタ書込み(追加)N.Ishii 160611 // //液晶表示器とPICはI2Cにより接続される // 1)Define I/O PORT // PORTB(4)pin13 : SDA // PORTB(6)pin11 : SCL // 2)OSC // 内部クロック 4MHz // // Copyright (c) 2012-2013 iwamoto All Rights Reserved ////////////////////////////////////////////////////////////////////////////////////// #include #include "L_i2cLCD.h" /// lcd char_gane ram user data table:追加 160611 char lcd_cg_ram_data[] = { 0,0x0e,0x11,0x11,0x11,0x0e,0,0, // White circle 0,0x0e,0x1f,0x1f,0x1f,0x0e,0,0, // Black circle /* 0x0a,0x1f,0x1f,0x1f,0x1f,0x0e,0x04,0, // harat 0,0x04,0x0e,0x1f,0x0e,0x04,0,0, // Dia 0x04,0x0e,0x1f,0x1f,0x1f,0x04,0x0e,0, // Spades 0x0e,0x0e,0x15,0x1f,0x15,0x04,0x0e,0, // Clover */ //0x1f,0x15,0x0e,0x04,0x04,0x04,0x04,0, // Ant 0x1f,0x0e,0x04,0x04,0x04,0x04,0x04,0, // Ant 0,0,0,0,0,0x0f,0x0f,0, // Low Level 0,0,0,0x0f,0x0f,0x0f,0x0f,0, // Mid Level 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0, // Hi Level 0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0, // Checkered 0x02,0x13,0x1f,0x1f,0x1c,0x14,0x14,0 // Smole Dog }; void _EEByteWrite(char, char, char); void _i2cTx(char); void _EEByteWrite(char addr, char cont, char data){ SSPCON2bits.SEN = 1; // Start condition 開始 while(SSPCON2bits.SEN); // Start condition 完了 _i2cTx(addr); _i2cTx(cont); _i2cTx(data); PIR1bits.SSPIF = 0; SSPCON2bits.PEN = 1; while(SSPCON2bits.PEN); } void _i2cTx(char data){ PIR1bits.SSPIF = 0; SSPBUF = data; while(!PIR1bits.SSPIF); } //-------- 1文字表示 void LCD_dat(char chr){ _EEByteWrite(0x7C, 0x40, chr); Delay_50uS; // 50μsec } //-------- コマンド出力 void LCD_cmd(char cmd){ _EEByteWrite(0x7C, 0x00, cmd); if(cmd & 0xFC) // 上位6ビットに1がある命令 Delay_50uS; // 50usec else Delay_2mS; // 2msec ClearおよびHomeコマンド } //-------- 全消去 void LCD_clr(void){ LCD_cmd(0x01); //Clearコマンド出力 } //-------- カーソル位置指定 void LCD_posyx(char ypos, char xpos){ unsigned char pcode; switch(ypos & 0x03){ case 0: pcode=0x80;break; case 1: pcode=0xC0;break; case 2: pcode=0x94;break; case 3: pcode=0xD4;break; } LCD_cmd(pcode += xpos); } //-------- 文字列出力 void LCD_str(char *str){ while(*str) //文字列の終わり(00)まで継続 LCD_dat(*str++); //文字出力しポインタ+1 } //-------- Rom 文字列出力 void LCD_ROMstr(const char *str){ while(*str) //文字列の終わり(00)まで継続 LCD_dat(*str++); //文字出力しポインタ+1 } //-------- 16進文字変換表示 void LCD_hex(char c){ const char hexch[] ="0123456789ABCDEF"; LCD_dat(hexch[c >> 4]); LCD_dat(hexch[c & 0xF]); } //-------- 初期化 void LCD_int(void){ SSPCON1 = 0x28; //I2Cマスターモード指定 SSPSTAT = 0x00; SSPADD = BaudConst; //Board Rate Delay_100mS; LCD_cmd(0x38); // 8bit 2行 表示命令モード LCD_cmd(0x39); // 8bit 2行 拡張命令モード LCD_cmd(0x14); // OSC BIAS 設定1/5 // コントラスト設定 LCD_cmd(0x70 + (CONTRAST & 0x0F)); LCD_cmd(0x5C + (CONTRAST >> 4)); LCD_cmd(0x6B); // Ffollwer Delay_100mS; Delay_100mS; LCD_cmd(0x38); // 表示命令モード LCD_cmd(0x0C); // Display On LCD_cmd(0x01); // Clear Display } //-- 指定アイコン ON void LCD_icon_on(int icn){ LCD_cmd(0x39); // 拡張命令モード LCD_cmd(icn >> 8); // Icon アドレス LCD_dat(icn & 0xFF); // Icon ビット LCD_cmd(0x38); // 表示命令モード } //-- 指定アイコン OFF void LCD_icon_off(int icn){ LCD_cmd(0x39); // 拡張命令モード LCD_cmd(icn >> 8); // Icon アドレス LCD_dat(0x00); // Icon ビット LCD_cmd(0x38); // 表示命令モード } //-- 全アイコン OFF void LCD_icon_clr(void){ unsigned char icn = 0x40; LCD_cmd(0x39); // 拡張命令モード while(icn <= 0x4F){ LCD_cmd(icn++); // Icon アドレス LCD_dat(0x00); // Icon ビット } LCD_cmd(0x38); // 表示命令モード } //////// ユーザーキャラクタ書込み(表示)関数 void LCD_cg_ram_user_set(void) { unsigned char cg_ram_address; for (cg_ram_address = 0 ; cg_ram_address != 64 ; ++cg_ram_address) // 8*8 { LCD_cmd(cg_ram_address + 0x40); // CG RAM Address Set(cgramadd:8*3char) LCD_dat(lcd_cg_ram_data[cg_ram_address]); } }