1.1K
// PIC16F877A Configuration Bit Settings #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled) #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) unsigned char i2c_add, BackLight_State = LCD_BACKLIGHT; unsigned char RS; void main(void) { // Initialize I2C and LCD I2C_Master_Init(); LCD_Init(0x4E); // Initialize LCD module with I2C address = 0x4E // Write strings to LCD LCD_Set_Cursor(1, 1); LCD_Print_String(" THE EMBEDDED "); LCD_Set_Cursor(2, 1); LCD_Print_String(" THINGS "); __delay_ms(2500); // Animation loop while(1) { LCD_SR(); __delay_ms(350); LCD_SR(); __delay_ms(350); LCD_SL(); __delay_ms(350); LCD_SL(); __delay_ms(350); } return; } void I2C_Master_Init(void) { SSPCON = 0x28; SSPCON2 = 0x00; SSPSTAT = 0x00; SSPADD = ((_XTAL_FREQ/4)/I2C_BaudRate) - 1; SCL_D = 1; SDA_D = 1; } void I2C_Master_Wait(void) { while ((SSPSTAT & 0x04) || (SSPCON2 & 0x1F)); } void I2C_Master_Start(void) { I2C_Master_Wait(); SEN = 1; } void I2C_Master_Stop(void) { I2C_Master_Wait(); PEN = 1; }