//init 8 custom char void LCDDefineProgressBarChar() { uint8_t ch=0, chn=0; while(ch<48) { LCDdefinechar((LcdCustomChar+ch),chn++); ch=ch+8; } }
void LCDinit(void)//Initializes LCD { #ifdef LCD_4bit //4 bit part _delay_ms(15); LDP=0x00; LCP=0x00; LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4; LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS; //---------one------ LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //-----------two----------- LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //-------three------------- LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|0<<LCD_D4; //4 bit mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //--------4 bit--dual line--------------- LCDsendCommand(0b00101000); //-----increment address, invisible cursor shift------ LCDsendCommand(0b00001100); //init 8 custom chars uint8_t ch=0, chn=0; while(ch<64) { LCDdefinechar((LcdCustomChar+ch),chn++); ch=ch+8; } #else //8 bit part _delay_ms(15); LDP=0x00; LCP=0x00; LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4|1<<LCD_D3 |1<<LCD_D2|1<<LCD_D1|1<<LCD_D0; LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS; //---------one------ LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3 |0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //-----------two----------- LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3 |0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //-------three------------- LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|0<<LCD_D3 |0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //--------8 bit dual line---------- LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4|1<<LCD_D3 |0<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(1); //-----increment address, invisible cursor shift------ LDP=0<<LCD_D7|0<<LCD_D6|0<<LCD_D5|0<<LCD_D4|1<<LCD_D3 |1<<LCD_D2|0<<LCD_D1|0<<LCD_D0; //8 it mode LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS; _delay_ms(1); LCP&=~(1<<LCD_E); _delay_ms(5); //init custom chars uint8_t ch=0, chn=0; while(ch<64) { LCDdefinechar((LcdCustomChar+ch),chn++); ch=ch+8; } #endif }
void LCDinit(void) //Initializes LCD { //power on delay _delay_ms(POWER_ON_DELAY); //setup data and control registers LCD_DDR |= 1 << LCD_D7 | 1 << LCD_D6 | 1 << LCD_D5 | 1 << LCD_D4; LCD_CDR |= 1 << LCD_ENABLE | 1 << LCD_RW | 1 << LCD_RS; //Issue MSB(0b0011xxxx) command 3 times. use proper timing LCD_DATAPORT = 0x00; LCD_CONTROLPORT = 0x00; LCD_DATAPORT = 0 << LCD_D7 | 0 << LCD_D6 | 1 << LCD_D5 | 1 << LCD_D4; //4 bit mode LCD_CONTROLPORT |= 0 << LCD_ENABLE | 0 << LCD_RW | 0 << LCD_RS; //1st pulse LCDexecute(); _delay_ms(4); //wait more then 4.1ms //2nd pulse LCDexecute(); //3rd pulse LCDexecute(); #ifdef LCD_4bit //4 bit mode //Function Set: change to 4bit mode //same call but without D4 bit LCD_DATAPORT &= ~(1 << LCD_D4); //4 bit mode LCDexecute(); //4bit mode operation starts here //Function Set: 4 bit,dual line,5x8 LCDsendCommand( (1 << LCD_FUNCTION) | (0 << LCD_FUNCTION_8BIT) | (1 << LCD_FUNCTION_2LINES) | (0 << LCD_FUNCTION_10DOTS)); #else //8-bit mode //Function Set: 8 bit,dual line,5x8 LCDsendCommand( (1 << LCD_FUNCTION) | (1 << LCD_FUNCTION_8BIT) | (1 << LCD_FUNCTION_2LINES) | (0 << LCD_FUNCTION_10DOTS)); #endif //Display Control: disp Off,cursor off,blinking off LCDsendCommand( (1 << LCD_DISPLAY) | (0 << LCD_DISPLAY_ON) | (0 << LCD_CURSOR_ON) | (0 << LCD_BLINK_ON)); //Clear Display LCDsendCommand(1 << LCD_CLR); _delay_ms(3); //special more then 3ms case //Entry Mode Set: I/D: On S:Off LCDsendCommand( (1 << LCD_ENTRY_MODE) | (1 << LCD_ENTRY_MODE_INC) | (0 << LCD_ENTRY_MODE_SHIFT)); //End of Initialization , clear display now and switch it ON. //Display Control: disp ON,cursor off,blinking off LCDsendCommand( (1 << LCD_DISPLAY) | (1 << LCD_DISPLAY_ON) | (0 << LCD_CURSOR_ON) | (0 << LCD_BLINK_ON)); //user defined chars definitions come here //defines backslash char symbol in CGRAM memory //LCDdefinechar(backslash,0); //init 8 custom chars uint8_t ch=0, chn=0; while(ch<64) { LCDdefinechar((LCDcustomChar+ch),chn++); ch=ch+8; } }