//reset LCD to 4bit mode void HD44780_Reset(void){ //set initial pin states LCD_BL_TRIS&=(~LCD_BL_PIN);//backlight pin output LCD_BL_LAT|=LCD_BL_PIN; //backlight on //all I/O should be to ground, low to start TRISC&=(~0b11000000); LATC&=(~0b11000000); TRISD&=(~0b11111000); LATD&=(~0b11111000); //# Wait more than 15 msecs after power is applied. delayMS(15); LCD_RS=0;//0 for a command //# Write 0x03 to LCD and wait 5 msecs for the instruction to complete HD44780_WriteNibble(0x03); delayMS(5); //# Write 0x03 to LCD and wait 160 usecs for instruction to complete HD44780_WriteNibble(0x03); delayUS(160); //# Write 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag) HD44780_WriteNibble(0x03); delayUS(160); //Set the Operating Characteristics of the LCD //* Write 0x02 to the LCD to Enable Four Bit Mode HD44780_WriteNibble(0x02); delayUS(160); }
//reset LCD to 4bit mode void HD44780_Reset(void){ //set initial pin states //LCD_BL_TRIS=0;//backlight pin output //LCD_BL=0; //backlight off //we use open drain with pullup resistors to interface the LCD at 5volts //all I/O should be to ground, low to start PORTB &= (~0b10111111100000); LATB &= (~0b10111111100000); TRISB &= (~0b10111111100000); //# Wait more than 15 msecs after power is applied. delayMS(15); LCD_RS_TRIS=0;//0 for a command //# Write 0x03 to LCD and wait 5 msecs for the instruction to complete HD44780_WriteNibble(0x03); delayMS(5); //# Write 0x03 to LCD and wait 160 usecs for instruction to complete HD44780_WriteNibble(0x03); delayUS(160); //# Write 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag) HD44780_WriteNibble(0x03); delayUS(160); //Set the Operating Characteristics of the LCD //* Write 0x02 to the LCD to Enable Four Bit Mode HD44780_WriteNibble(0x02); delayUS(160); }
//write byte dat to register reg void HD44780_WriteByte(unsigned char reg, unsigned char dat){ LCD_RW=0; //write mode =0 if(reg==DATA){ //does RS need to be set? LCD_RS=1; //set register select flag for text }else{ LCD_RS=0;//0 for a command } HD44780_WriteNibble((dat>>4) ); HD44780_WriteNibble((dat & 0x0F)); }