/******************************** * LCD表示ライブラリ(for AQM0802A) **********************************************/ #include "lcd_lib.h" #include "mcc_generated_files/i2c.h" #include "mcc_generated_files/mcc.h" #define LcdAdr 0x3E #define CONTRAST 0x18 // for 5.0V //#define CONTRAST 0x30 // for 3.3V #define BOOST 0x00 // for 5.0V Bon=off //#define BOOST 0x04 // for 3.3V Bon=on I2C_MESSAGE_STATUS status; /********************************* * 1文字表示データ出力 *********************************/ void Lcd_data(unsigned char data) { unsigned char tbuf[2]; tbuf[0] = 0x40; tbuf[1] = data; I2C_MasterWrite(tbuf, 2, LcdAdr, &status); while(status == I2C_MESSAGE_PENDING); __delay_us(30); // 30usec wait } /******************************* * 1コマンド出力 *******************************/ void Lcd_cmd(unsigned char cmd) { unsigned char tbuf[2]; tbuf[0] = 0x00; tbuf[1] = cmd; I2C_MasterWrite(tbuf, 2, LcdAdr, &status); while(status == I2C_MESSAGE_PENDING); /* ClearかHomeか */ if((cmd == 0x01)||(cmd == 0x02)) __delay_ms(2); // 2msec wait else __delay_us(30); // 30usec wait } /******************************* * 初期化関数 *******************************/ void Lcd_init(void) { __delay_ms(50); // 50msec wait Lcd_cmd(0x38); // 8bit 2line Normal mode Lcd_cmd(0x39); // 8bit 2line Extend mode Lcd_cmd(0x14); // OSC 183Hz BIAS 1/5 /* contrast */ Lcd_cmd(0x70 + (CONTRAST & 0x0F)); Lcd_cmd(0x58 + BOOST + (CONTRAST >> 4)); Lcd_cmd(0x6B); // Follwer 0x62? __delay_ms(300); Lcd_cmd(0x38); // Set Normal mode Lcd_cmd(0x01); // Clear Display Lcd_cmd(0x0C); // Display On } /****************************** * 全消去関数 ******************************/ void Lcd_clear(void) { Lcd_cmd(0x01); } /***************************** * 文字列表示関数 *****************************/ void Lcd_str(const unsigned char* ptr) { while(*ptr != 0) Lcd_data(*ptr++); }