示例#1
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
char ReadDataXLCD(void)
{
        char data;

	// 4-bit interface
	RW_PIN = 1;
	RS_PIN = 1;
	DelayFor18TCY();
	E_PIN = 1;                      // Clock the data out of the LCD
	DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
	data = DATA_PORT&0xf0;          // Read the upper nibble of data
#else                                   // Lower nibble interface
	data = (DATA_PORT<<4)&0xf0;     // read the upper nibble of data
#endif
	E_PIN = 0;                      // Reset the clock line
	DelayFor18TCY();
	E_PIN = 1;                      // Clock the next nibble out of the LCD
	DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
	data |= (DATA_PORT>>4)&0x0f;    // Read the lower nibble of data
#else                                   // Lower nibble interface
	data |= DATA_PORT&0x0f;         // Read the lower nibble of data
#endif
	E_PIN = 0;                                      
	RS_PIN = 0;                     // Reset the control bits
	RW_PIN = 0;

	return(data);                   // Return the data byte
}
示例#2
0
unsigned char BusyXLCD(void) {
    OLATB_curr |= 0xC0; // RW and RS are on
    clockLCDLow();
    I2C_Write(EXPANDER_IODIRB, 0x1E); // data bus is now an input
    I2C_Write(EXPANDER_OLATB, OLATB_curr);
    DelayFor18TCY();
    clockLCDHigh(); // Clock in the command with E
    DelayFor18TCY();
    
    busy = I2C_Read(EXPANDER_GPIOB);

    clockLCDLow(); // Reset clock line
    DelayFor18TCY();
    clockLCDHigh(); // Clock out other nibble
    DelayFor18TCY();
    clockLCDLow();
    OLATB_curr &= 0xBF; // Reset control line
    I2C_Write(EXPANDER_OLATB, OLATB_curr);
    I2C_Write(EXPANDER_IODIRB, 0x00); // set data bus back to output

    // busy bit is high?
    if (busy & 0x02)
    {
        return 1;
    }

    // Busy bit is low
    return 0;
}
示例#3
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
unsigned char ReadAddrXLCD(void)
{
	char data;                      // Holds the data retrieved from the LCD

	RW_PIN = 1;                     // Set control bits for the read
	RS_PIN = 0;
	DelayFor18TCY();
	E_PIN = 1;  

#ifdef UPPER                            // Upper nibble interface
	data = DATA_PORT&0xf0;          // Read the nibble into the upper nibble of data
#else                                   // Lower nibble interface
	data = (DATA_PORT<<4)&0xf0;     // Read the nibble into the upper nibble of data
#endif
	E_PIN = 0;                      // Reset the clock
	DelayFor18TCY();
	E_PIN = 1;                      // Clock out the lower nibble
	DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
	data |= (DATA_PORT>>4)&0x0f;    // Read the nibble into the lower nibble of data
#else                                   // Lower nibble interface
	data |= DATA_PORT&0x0f;         // Read the nibble into the lower nibble of data
#endif
	E_PIN = 0;
	RW_PIN = 0;                     // Reset the control lines

	return (data&0x7f);             // Return the address, Mask off the busy bit
}
示例#4
0
void LCD_data(unsigned char c)
        {
        RS = 1;                                         /* Data mode selected                                       */
        DATA_PORT_ = c;
        RW = 0;                                         /* Write mode selected                                      */
        EN = 1;                                         /* Logic HIGH on Enable pin                                 */
        DelayFor18TCY();                                /* Delay for 18 cycles                                      */
        EN = 0;                                         /* Logic LOW on Enable pin                                  */
        DelayFor18TCY();                                /* Delay for 18 cycles                                      */
        }
示例#5
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
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();
                                   // 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
	}
}
示例#6
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
void WriteCmdXLCD(unsigned char cmd)
{
	// 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= cmd&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= (cmd>>4)&0x0f;
#endif
        RW_PIN = 0;                     // Set control signals for command
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= (cmd<<4)&0xf0;
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= cmd&0x0f;
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Make data nibble input
        TRIS_DATA_PORT |= 0xf0;
#else
        TRIS_DATA_PORT |= 0x0f;
#endif

	return;
}
示例#7
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
void SetDDRamAddr(unsigned char DDaddr)
{
                                          // 4-bit interface
#ifdef UPPER                                    // Upper nibble  interface
	TRIS_DATA_PORT &= 0x0f;                 // Make port output
	DATA_PORT &= 0x0f;                      // and write upper nibble
	DATA_PORT |= ((DDaddr | 0b10000000) & 0xf0);
#else                                           // Lower nibble interface
	TRIS_DATA_PORT &= 0xf0;                 // Make port output
	DATA_PORT &= 0xf0;                      // and write upper nibble
	DATA_PORT |= (((DDaddr | 0b10000000)>>4) & 0x0f);
#endif
	RW_PIN = 0;                             // Set control bits
	RS_PIN = 0;
	DelayFor18TCY();
	E_PIN = 1;                              // Clock the cmd and address in
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
	DATA_PORT &= 0x0f;                      // Write lower nibble
	DATA_PORT |= ((DDaddr<<4)&0xf0);
#else                                           // Lower nibble interface
	DATA_PORT &= 0xf0;                      // Write lower nibble
	DATA_PORT |= (DDaddr&0x0f);
#endif
	DelayFor18TCY();
	E_PIN = 1;                              // Clock the cmd and address in
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
	TRIS_DATA_PORT |= 0xf0;                 // Make port input
#else                                           // Lower nibble interface
	TRIS_DATA_PORT |= 0x0f;                 // Make port input
#endif

	return;
}
示例#8
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
void SetCGRamAddr(unsigned char CGaddr)
{
	// 4-bit interface
#ifdef UPPER                                    // Upper nibble interface
	TRIS_DATA_PORT &= 0x0f;                 // Make nibble input
	DATA_PORT &= 0x0f;                      // and write upper nibble
	DATA_PORT |= ((CGaddr | 0b01000000) & 0xf0);
#else                                           // Lower nibble interface
	TRIS_DATA_PORT &= 0xf0;                 // Make nibble input
	DATA_PORT &= 0xf0;                      // and write upper nibble
	DATA_PORT |= (((CGaddr |0b01000000)>>4) & 0x0f);
#endif
	RW_PIN = 0;                             // Set control signals
	RS_PIN = 0;
	DelayFor18TCY();
	E_PIN = 1;                              // Clock cmd and address in
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
	DATA_PORT &= 0x0f;                      // Write lower nibble
	DATA_PORT |= ((CGaddr<<4)&0xf0);
#else                                           // Lower nibble interface
	DATA_PORT &= 0xf0;                      // Write lower nibble
	DATA_PORT |= (CGaddr&0x0f);
#endif
	DelayFor18TCY();
	E_PIN = 1;                              // Clock cmd and address in
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
	TRIS_DATA_PORT |= 0xf0;                 // Make inputs
#else                                           // Lower nibble interface
	TRIS_DATA_PORT |= 0x0f;                 // Make inputs
#endif

	return;
}
示例#9
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
void WriteDataXLCD(unsigned char data)
{
#ifdef UPPER                            // Upper nibble interface
	TRIS_DATA_PORT &= 0x0f;
	DATA_PORT &= 0x0f;
	DATA_PORT |= data&0xf0;
#else                                   // Lower nibble interface
	TRIS_DATA_PORT &= 0xf0;
	DATA_PORT &= 0xf0;
	DATA_PORT |= ((data>>4)&0x0f);
#endif
	RS_PIN = 1;                     // Set control bits
	RW_PIN = 0;
	DelayFor18TCY();
	E_PIN = 1;                      // Clock nibble into LCD
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
	DATA_PORT &= 0x0f;
	DATA_PORT |= ((data<<4)&0xf0);
#else                                   // Lower nibble interface
	DATA_PORT &= 0xf0;
	DATA_PORT |= (data&0x0f);
#endif
	DelayFor18TCY();
	E_PIN = 1;                      // Clock nibble into LCD
	DelayFor18TCY();
	E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
	TRIS_DATA_PORT |= 0xf0;
#else                                   // Lower nibble interface
	TRIS_DATA_PORT |= 0x0f;
#endif

	return;
}
示例#10
0
/********************************************************************
*       Function Name:  WriteCmdXLCD                                *
*       Return Value:   void                                        *
*       Parameters:     cmd: command to send to LCD                 *
*       Description:    This routine writes a command to the Hitachi*
*                       HD44780 LCD controller. The user must check *
*                       to see if the LCD controller is busy before *
*                       calling this routine.                       *
********************************************************************/
void WriteCmdXLCD(unsigned char cmd)
{
#ifdef BIT8                             // 8-bit interface
    TRIS_DATA_PORT = 0;             // Data port output
    DATA_PORT = cmd;                // Write command to data port
    RW_PIN = 0;                     // Set the control signals
    RS_PIN = 0;                     // for sending a command
    DelayFor18TCY();
    E_PIN = 1;                      // Clock the command in
    DelayFor18TCY();
    E_PIN = 0;
    DelayFor18TCY();
    TRIS_DATA_PORT = 0xff;          // Data port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
    TRIS_DATA_PORT &= 0x0f;
    DATA_PORT &= 0x0f;
    DATA_PORT |= cmd&0xf0;
#else                                   // Lower nibble interface
    TRIS_DATA_PORT &= 0xf0;
    DATA_PORT &= 0xf0;
    DATA_PORT |= (cmd>>4)&0x0f;
#endif
    RW_PIN = 0;                     // Set control signals for command
    RS_PIN = 0;
    DelayFor18TCY();
    E_PIN = 1;                      // Clock command in
    DelayFor18TCY();
    E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
    DATA_PORT &= 0x0f;
    DATA_PORT |= (cmd<<4)&0xf0;
#else                                   // Lower nibble interface
    DATA_PORT &= 0xf0;
    DATA_PORT |= cmd&0x0f;
#endif
    DelayFor18TCY();
    E_PIN = 1;                      // Clock command in
    DelayFor18TCY();
    E_PIN = 0;
#ifdef UPPER                            // Make data nibble input
    TRIS_DATA_PORT |= 0xf0;
#else
    TRIS_DATA_PORT |= 0x0f;
#endif
#endif
    return;
}
示例#11
0
文件: writdata.c 项目: Shmuma/radio
/********************************************************************
*       Function Name:  WriteDataXLCD                               *
*       Return Value:   void                                        *
*       Parameters:     data: data byte to be written to LCD        *
*       Description:    This routine writes a data byte to the      *
*                       Hitachi HD44780 LCD controller. The user    *
*                       must check to see if the LCD controller is  *
*                       busy before calling this routine. The data  *
*                       is written to the character generator RAM or*
*                       the display data RAM depending on what the  *
*                       previous SetxxRamAddr routine was called.   *
********************************************************************/
void WriteDataXLCD(char data)
{
#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0;             // Make port output
        DATA_PORT = data;               // Write data to port
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock data into LCD
        DelayFor18TCY();
        E_PIN = 0;
        RS_PIN = 0;                     // Reset control bits
        TRIS_DATA_PORT = 0xff;          // Make port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= data&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= ((data>>4)&0x0f);
#endif
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= ((data<<4)&0xf0);
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= (data&0x0f);
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        return;
}
示例#12
0
/*********************************************************************
*       Function Name:  ReadAddrXLCD                                 *
*       Return Value:   char: address from LCD controller            *
*       Parameters:     void                                         *
*       Description:    This routine reads an address byte from the  *
*                       Hitachi HD44780 LCD controller. The user     *
*                       must check to see if the LCD controller is   *
*                       busy before calling this routine. The address*
*                       is read from the character generator RAM or  *
*                       the display data RAM depending on what the   *
*                       previous SetxxRamAddr routine was called.    *
*********************************************************************/
unsigned char ReadAddrSLCD(void)
{
        char data;                      // Holds the data retrieved from the LCD

#ifdef BIT8                             // 8-bit interface
        SLCD_RW_PIN = 1;                     // Set control bits for the read
        SLCD_RS_PIN = 0;
        DelayFor18TCY();
        SLCD_E_PIN = 1;                      // Clock data out of the LCD controller
        DelayFor18TCY();
        data = SLCD_DATA_PORT_RD;               // Save the data in the register
        SLCD_E_PIN = 0;
        SLCD_RW_PIN = 0;                     // Reset the control bits
#else                                   // 4-bit interface
        SLCD_RW_PIN = 1;                     // Set control bits for the read
        SLCD_RS_PIN = 0;
        DelayFor18TCY();
        SLCD_E_PIN = 1;                      // Clock data out of the LCD controller
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data = SLCD_DATA_PORT_RD&0xf0;          // Read the nibble into the upper nibble of data
#else                                   // Lower nibble interface
        data = (SLCD_DATA_PORT_RD<<4)&0xf0;     // Read the nibble into the upper nibble of data
#endif
        SLCD_E_PIN = 0;                      // Reset the clock
        DelayFor18TCY();
        SLCD_E_PIN = 1;                      // Clock out the lower nibble
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data |= (SLCD_DATA_PORT_RD>>4)&0x0f;    // Read the nibble into the lower nibble of data
#else                                   // Lower nibble interface
        data |= SLCD_DATA_PORT_RD&0x0f;         // Read the nibble into the lower nibble of data
#endif
        SLCD_E_PIN = 0;
        SLCD_RW_PIN = 0;                     // Reset the control lines
#endif
        return (data&0x7f);             // Return the address, Mask off the busy bit
}