//***************************************************************************** // //! \brief Write data or command to the HD44780. //! //! \param ucRS determines if the IR or DR to select. //! //! The parameter of ucRS can be: //! - HD44780_RS_COMMAND - select the IR. //! - HD44780_RS_DATA - select the DR. //! //! \return None. // //***************************************************************************** void HD44780Write(unsigned char ucRS, unsigned char ucInstruction) { int i; // // Check Arguments. // xASSERT((ucRS == HD44780_RS_COMMAND) || (ucRS == HD44780_RS_DATA)); // // RS:Command, RW:Write, E:Enable // _digitalWrite(ucRsPin, ucRS); _digitalWrite(ucEnablePin, HD44780_E_ENABLE); // // Output Data // for ( i = 0; i < 4; i++) { _digitalWrite(ucDataPin[i], (ucInstruction >> (i+4)) & 0x01); } PulseEnable(); xSysCtlDelay(10); _digitalWrite(ucEnablePin, HD44780_E_ENABLE); for ( i = 0; i < 4; i++) { _digitalWrite(ucDataPin[i], (ucInstruction >> (i)) & 0x01); } xSysCtlDelay(10); PulseEnable(); }
/************************************************************************************* * * Function: WriteLcdDataByte * * Description: Function used to split 8 bit commands into two 4 bit commands. * Note: This can only be used after setting LCD module in 4 bit mode * * Parameters: byte: Byte value to trigger, Bank: Setting of RS bit * * Return: void * *************************************************************************************/ void WriteLcdDataByte(char byte, unsigned char Bank) { unsigned char highnib; unsigned char lownib; if(Bank == INSTRUCTION_REG) { lownib = (byte & 0x0F) << 4 | BL; highnib = (byte & 0xF0) | BL; } if(Bank == DATA_REG) { lownib = (byte & 0x0F) << 4 | BL | RS; highnib = (byte & 0xF0) | BL | RS; } /* First write the 4 MSB bits */ WriteByteI2C(highnib); /* Trigger the data */ PulseEnable(highnib); /* Now write the 4 LSB bits */ WriteByteI2C(lownib); /* Trigger the data */ PulseEnable(lownib); }
/************************************************************************************* * * Function: WriteLcdDataNibble * * Description: Function that writes only 4 bits to the LCD * * Parameters: Nibble value to trigger * * Return: void * *************************************************************************************/ void WriteLcdDataNibble(unsigned char nibble) { /* High nibble */ unsigned char nibble_val = (nibble & 0x0F) << 4 | BL; /* Write the byte to I2C (nibble value in above 4 bits) */ WriteByteI2C(nibble_val); /* Trigger the data */ PulseEnable(nibble_val); }