// LCD.h: Sends data to LCD via I2C BUS // // // Author: Ali Topping // Date: 01/3/06 // Version: 1.1 // Notes: SCL and SDA must be set to outputs in TRISC. // PIC: 18F4585 // Software: MikroC 5.0.0.3 // Hardware: LCD03 - www.robot-electronics.co.uk #define DATA_RATE 100000 // I2C Data Rate, 100K, 400k or 3.4MHz #define LCDW 0xC6 // LCD address + Write bit #define LCDR 0xC7 // LCD address + Read bit //=============== // HEADER FILE PROTOTYPES void LCD_Update(unsigned char DATA); void Init_LCD(void); /******************************************************************** * Function Name: LCD_Update * * Return Value: void * * Parameters: DATA: Data to be sent to LCD * * Description: This routine sends data out to the LCD on the * * I2C BUS. * ********************************************************************/ void LCD_Update(unsigned char DATA) { I2C_Start(); while(!I2C_Is_Idle()) asm nop; // Send Start condition I2C_Wr(LCDW); // Write to LCD03 while(!I2C_Is_Idle()) asm nop; I2C_Wr(0); // Write to register 0 while(!I2C_Is_Idle()) asm nop; I2C_Wr(DATA); // Write DATA to LCD (Command or ascii value) while(!I2C_Is_Idle()) asm nop; // Must wait for bus to be cleared before I2C_Stop(); I2C_Stop(); } /******************************************************************** * Function Name: Init_LCD * * Return Value: void * * Parameters: void * * Description: This routine initialises the LCD and then * * clears the initial Data from the LCD. * ********************************************************************/ void Init_LCD() { I2C_Init(100000); // Init Baud Rate I2C_Start(); // Send start condition. while(!I2C_Is_Idle()) asm nop; I2C_Wr(LCDW); // Write to LCD03 while(!I2C_Is_Idle()) asm nop; I2C_Wr(0); // Write to register 0 while(!I2C_Is_Idle()) asm nop; I2C_Wr(12); // Clears LCD03's Screen while(!I2C_Is_Idle()) asm nop; // Wait for bus to be cleared before I2C_Stop(); I2C_Stop(); // Send stop bit }