/* * LCDNHDC0220.c * * Created on: 11.02.2012 * Author: R Tyrakowski */ extern void WaitSoft(unsigned long ul_x); void I2C_Stop(void); void I2C_Start(void); unsigned char I2C_out(unsigned char j); #include unsigned char LCD_Buf[40]; //--------------------------------------------------- void LCD_I2CStart(void) { I2C_Start(); I2C_out(def_LCDSlaveaddress); // def_LCDSlaveaddress=0x78 } /**************************************************** * Initialization For ST7036i * *****************************************************/ void Init_LCDNHDC0220(void) { sda_p; sda_dout; sda_h; scl_p; scl_d; scl_l; LCD_I2CStart(); I2C_out(def_Comsend0); // def_Comsend = 0x00 (Control Byte CO = 0, RS=0 I2C_out(0x38); // Function set ( 8 bit data, lines 2 ) WaitSoft(1000); I2C_out(0x39); // Function set ( 8 bit, 2 lines, IS1 =1 WaitSoft(1000); I2C_out(0x14); // Bias Set I2C_out(0x71); // Contrast set I2C_out(0x5E); // PWR/ICON/Contrast Control I2C_out(0x6D); // Follower Control WaitSoft(1000); I2C_out(0x0C); // Display on I2C_out(0x01); // Clear display I2C_out(0x06); // Entry Mode WaitSoft(1000); I2C_Stop(); } /*****************************************************/ /**************************************************** * Output command or data via I2C * *****************************************************/ unsigned char I2C_out(unsigned char uc_j) //I2C Output { unsigned char uc_n; for(uc_n=0;uc_n<8;uc_n++){ if((uc_j&0x80)==0x80) { sda_h; sda_h; sda_h; sda_h; } else { sda_l; sda_l; sda_l; sda_l; } uc_j=(uc_j<<1); scl_l; scl_l; scl_l; scl_l; scl_h; scl_h; scl_h; scl_h; scl_l; scl_l; scl_l; scl_l; } sda_din; scl_h; scl_h; scl_h; scl_h; uc_j = sda_in; uc_j = sda_in; uc_j = sda_in; scl_l; scl_l; scl_l; scl_l; sda_dout; return uc_j; } /*****************************************************/ /**************************************************** * I2C Start * [11] *****************************************************/ void I2C_Start(void) { scl_h; scl_h; scl_h; scl_h; sda_h; sda_h; sda_h; sda_h; sda_l; sda_l; sda_l; sda_l; scl_l; scl_l; scl_l; scl_l; } /*****************************************************/ /**************************************************** * I2C Stop * *****************************************************/ void I2C_Stop(void) { sda_l; sda_l; sda_l; sda_l; scl_l; scl_l; scl_l; scl_l; scl_h; scl_h; scl_h; scl_h; sda_h; sda_h; sda_h; sda_h; } /**************************************************** * Send string of ASCII data (40 byte) to LCD * *****************************************************/ void LCDNHDC0220_TextOut(unsigned char *text) { unsigned int ui_n; LCD_I2CStart(); I2C_out(def_Comsend1); // Control byte -> another control byte will follow, RS = 0 I2C_out(0x02); // return home, first line I2C_out(def_ComsendData); // Control byte -> last control byte, RS=1 , just Data flow for(ui_n=0;ui_n<20;ui_n++){ I2C_out(*text); text++; } I2C_Stop(); I2C_Start(); I2C_out(def_LCDSlaveaddress); // def_LCDSlaveaddress=0x78 I2C_out(def_Comsend1); // Control byte -> another control byte will follow, RS = 0 I2C_out(0xC0); // Set DDRAM Address to 40 , second line I2C_out(def_ComsendData); // Control byte -> last control byte, RS=1 , just Data flow for(ui_n=0;ui_n<20;ui_n++){ I2C_out(*text); text++; } I2C_Stop(); } /****************************************************** * Send string of ASCII data (different length) to LCD * *******************************************************/ void LCDNHDC0220_TextPartOut(unsigned char uc_pos, unsigned char *text, unsigned int ui_textlength) { unsigned int ui_n; LCDNHDC0220_Pos(uc_pos); LCD_I2CStart(); I2C_out(def_ComsendData); // Control byte -> last control byte, RS=1 , just Data flow for(ui_n=0;ui_n normal size // uc_h = 1 -> Double size void LCDNHD0220_Size(unsigned char uc_h) { LCD_I2CStart(); I2C_out(def_Comsend0); // def_Comsend = 0x00 (Control Byte CO =0, RS=0 if (uc_h) I2C_out(0x34); // Function set ( 8 bit data, lines 2 ) // I2C_out(0x3C); // Function set ( 8 bit data, lines 2 ) else I2C_out(0x38); WaitSoft(1000); I2C_out(0x01); // Clear display I2C_out(0x06); // Entry Mode WaitSoft(500); I2C_Stop(); } //--------------------------------------------------------------------------------- void LCDNHDC0220_SingleChar(unsigned char uc_ccc) { LCD_I2CStart(); I2C_out(def_ComsendData); I2C_out(uc_ccc); I2C_Stop(); } //------------------------------------------------------------------------------------------ void LCDNHDC0220_Pos(unsigned char uc_pos) { if (!uc_pos) uc_pos = 1; uc_pos--; if (uc_pos > 19) { uc_pos -= 20; uc_pos += 64; } LCD_I2CStart(); I2C_out(def_Comsend1); // I2C_out(0x80 | uc_pos); I2C_Stop(); } //------------------------------------------------------------------------------------------ const unsigned char cgram_char[20 * 8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // bar horicontal 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C, 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00, // bar vertical from button 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00, 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x00, 0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x00, 0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x00, 0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00, // bar vertival from top 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00, 0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00, 0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00, 0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00, 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00, 0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; void LCDNHDC0220_Fill_CGRAM(unsigned char uc_adr,unsigned char uc_number, unsigned char * uc_buf) { unsigned int ui_n; LCD_I2CStart(); I2C_out(def_Comsend0); // Control byte , CO=1, RS=0 I2C_out(0x38); // Function set ( 8 bit data, lines 2, write CGRAM ) I2C_out(0x40 + uc_adr); // CGRAM Start address = 0 I2C_Stop(); WaitSoft(100); LCD_I2CStart(); I2C_out(def_ComsendData); for(ui_n=0;ui_n < (uc_number * 8);ui_n++){ I2C_out(*(uc_buf+ui_n)); } I2C_Stop(); } void LCDNHDC0220_Fill_BAR(void) { // 8 x 5 Char bar // 1 | 2 || 3 ||| 4 |||| 5 ||||| von links // 1 _ 2 __ 3 ___ 4 ____ 5 _____ 6 ______ 7 _______ 8 ________ von unten // 1 _ 2 __ 3 ___ 4 ____ 5 _____ 6 ______ 7 _______ 8 ________ von oben LCDNHDC0220_Fill_CGRAM(0x00,0x6, (unsigned char *) cgram_char); } //------------------------------------------------------------------------------------------ void Copy_to_LCD_Buf(const unsigned char * buffer,unsigned int ui_bufstart, unsigned char len) { unsigned int ui_x; for (ui_x=0;ui_x