Esempio n. 1
0
void initLCD(void) {
    LCD_BACKLIGHT_TRIS = OUTPUT;

    __delay_ms(5);
    
    // IO Tris
    LCD_D0_TRIS = OUTPUT;
    LCD_D1_TRIS = OUTPUT;
    LCD_D2_TRIS = OUTPUT;
    LCD_D3_TRIS = OUTPUT;
    LCD_D4_TRIS = OUTPUT;
    LCD_D5_TRIS = OUTPUT;
    LCD_D6_TRIS = OUTPUT;
    LCD_D7_TRIS = OUTPUT;
    LCD_RW_TRIS = OUTPUT;
    LCD_RS_TRIS = OUTPUT;
    LCD_EN_TRIS = OUTPUT;
 
    // init
    LCD_RS = 0;     //RS=0: Command, RS=1: Data
    LCD_RW = 0;     //R/W=0: Write, R/W=1: Read
    LCD_EN = 0;     //clock enable

    __delay_ms(15);

    commandLCD(0b00110000); // 8 bit interface, 8 chars per line, 5x10 pixels per char
    commandLCD(0b00110000);
    commandLCD(0b00110000);
    commandLCD(0b00111000);
    commandLCD(0b00000110); // no display shift
    commandLCD(0b00011000); 
    commandLCD(0b00001100); // display on, cursor off, no blink
    lcd_info.line = lcd_info.pos = 0;
}
Esempio n. 2
0
void initLCD(void) {
	LCD_BACKLIGHT_DIR = OUTPUT;   // Set LCD backlight-pin as output
	ADCON1 = 0x0A;                // RE0-2 digital
	delay_ms(5);                  // wait 5ms

	LCD_DATA = 0;
	LCD_DATA_DIR = 0xff;

	LCD_RS_DIR = OUTPUT;
	LCD_RW_DIR = OUTPUT;
	LCD_EN_DIR = OUTPUT;

	LCD_RS = 0;
	LCD_RW = 0;
	LCD_EN = 0;

	delay_ms(15);

	LCD_DATA_DIR = 0;

	commandLCD(0b00110000);
	commandLCD(0b00110000);
	commandLCD(0b00110000);
	commandLCD(0b00111000);
	commandLCD(0b00000110);
	commandLCD(0b00011000);
	commandLCD(0b00001100);
	lcd_info.line = lcd_info.pos = 0;
	clearLCD();
}
// set cursor at position p of line l
void setCursorLCD(BYTE l, BYTE p) {
	BYTE c;

	// check if input is valid
	if (l>LCD_LASTLINE) l = LCD_LASTLINE;
	if (p>LCD_LASTPOS)  p = LCD_LASTPOS;

	lcd_info.line = l;
	lcd_info.pos = p;
	
	if (l == 1)
		c = 0b11000000;
	else
		c = 0b10000000;
	
	// position offset
	p &= 0b00001111;
	c |= p;
		
	commandLCD(c);
	
	delay_us(45);         // wait until display has processed the command
}
void clearLCD(void) {
	commandLCD(0b00000001);
	delay_ms(2);
	setCursorLCD(0,0);
}