/******************************************
* LCD library (i2cLCD_ST7032i.c) *
* use for AQM0802A,AQM1602Y,.... *
******************************************/
#include "i2cLCD_ST7032i.h"
#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
//-------- send command -------------------------
void LCD_cmd(char cmd){
/* ----- I2C_Write1ByteRegister()関数をを使わない場合
uint8_t bf[2];
bf[0] = 0x00;
bf[1] = cmd;
while(!I2C_Open(I2CLCD_Adr));
I2C_SetBuffer(bf,2);
I2C_MasterWrite();
while(I2C_BUSY == I2C_Close());
*/
I2C_Write1ByteRegister(I2CLCD_Adr, 0x00, cmd);
//-- Clear かHomeか?
if(cmd & 0xFC) // bit6 = 1
__delay_us(30); // 30us
else
__delay_ms(2); // 2ms Clear or Home
}
//-------- send data ----------------------
void LCD_dat(char chr){
/* ---- I2C_Write1ByteRegister()関数を使わない場合
uint8_t bf[2];
bf[0] = 0x40;
bf[1] = chr;
while(!I2C_Open(I2CLCD_Adr));
I2C_SetBuffer(bf,2);
I2C_MasterWrite();
while(I2C_BUSY == I2C_Close());
*/
I2C_Write1ByteRegister(I2CLCD_Adr, 0x40, chr);
__delay_us(30); // 30us
}
//-------- clear LCD--------------------------
void LCD_clr(void){
LCD_cmd(0x01);
}
//--------- Home -----------------------------
void LCD_home(void){
LCD_cmd(0x02);
}
//--------- Cursor X,Y -----------------------
void LCD_cursor(int x, int y){
if (y == 0)
LCD_cmd((char)(0x80 + x));
else if (y == 1)
LCD_cmd((char)(0xc0 + x));
}
//-------- display strings -------------------------
void LCD_str(char *str){
while(*str)
LCD_dat(*str++); //pointer increment
}
//------- Create CG Char ---------
uint8_t LCD_CGchar(uint8_t c, char* dt){
uint8_t i;
if(c > 7) return 1;
LCD_cmd((char)(0x40 | (c << 3)));
__delay_us(30);
for(i = 0; i < 7; i++){
LCD_dat(*dt++);
__delay_us(30);
}
return 0;
}
//-------- LCD sift position -----------------
void LCD_sift(uint8_t d){
if(d) LCD_cmd(0x18);
else LCD_cmd(0x1C);
}
//-------- LCD initialize ---------------------------
void LCD_init(void){
__delay_ms(40); // 40ms wait
LCD_cmd(0x38); // 8bit,2line
LCD_cmd(0x39); // IS=1 : extention mode set
LCD_cmd(0x14); // Internal OSC Frequency
LCD_cmd(0x70 + (CONTRAST & 0x0F)); //Contrast set
LCD_cmd(0x58 + BOOST + (CONTRAST >> 4));
//Power/ICON/Contrast Control
LCD_cmd(0x6C); // Follower control
__delay_ms(200); // 200ms wait
LCD_cmd(0x38); // IS=0 : extention mode cancel
LCD_cmd(0x0C); // Display ON
LCD_cmd(0x01); // Clear Display
__delay_ms(2); // wait more than 1.08ms
}
//-------- Redirect STDIO to LCD ----------------
/*
void putch(char ch){
LCD_dat(ch);
}
*/
/******** End of File ******/
|