#include #include "xlcd.h" /******************************************************************** * Function Name: BusyXLCD * * Return Value: char: busy status of LCD controller * * Parameters: void * * Description: This routine reads the busy status of the * * Hitachi HD44780 LCD controller. * ********************************************************************/ unsigned char BusyXLCD(void) { RW_PIN = 1; // Set the control bits for read RS_PIN = 0; DelayFor18TCY(); E_PIN = 1; // Clock in the command DelayFor18TCY(); #ifdef BIT8 // 8-bit interface if(DATA_PORT&0x80) // Read bit 7 (busy bit) { // If high E_PIN = 0; // Reset clock line RW_PIN = 0; // Reset control line return 1; // Return TRUE } else // Bit 7 low { E_PIN = 0; // Reset clock line RW_PIN = 0; // Reset control line return 0; // Return FALSE } #else // 4-bit interface #ifdef UPPER // Upper nibble interface if(DATA_PORT&0x80) #else // Lower nibble interface if(DATA_PORT&0x08) #endif { E_PIN = 0; // Reset clock line DelayFor18TCY(); E_PIN = 1; // Clock out other nibble DelayFor18TCY(); E_PIN = 0; RW_PIN = 0; // Reset control line return 1; // Return TRUE } else // Busy bit is low { E_PIN = 0; // Reset clock line DelayFor18TCY(); E_PIN = 1; // Clock out other nibble DelayFor18TCY(); E_PIN = 0; RW_PIN = 0; // Reset control line return 0; // Return FALSE } #endif }