Subversion Repositories group.electronics

Rev

Rev 43 | Rev 45 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <avr/io.h>
#include "wire.h"
#include "lcd.h"
#include "macros.h"
#include <util/delay.h>


void lcd_init() {
        lcd_sendNib(0x30);      
        _delay_ms(150);

        lcd_sendNib(0x30);      
        _delay_ms(150);

        lcd_sendNib(0x30);      
        _delay_ms(50);

        lcd_sendNib(0x20);      
        _delay_ms(50);

        lcd_command(LCD_FUNCTIONSET | LCD_2LINE);
        _delay_ms(50);

        lcd_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);
        _delay_ms(50);

        lcd_command(LCD_CLEARDISPLAY);
        _delay_ms(50);

        lcd_command(LCD_RETURNHOME);
        _delay_ms(50);
}

void lcd_command(uint8_t data) {
        lcd_send(data, LCD_MODE_CM);
}

void lcd_char(uint8_t data) {
        lcd_send(data, LCD_MODE_RS);
}


void lcd_send(uint8_t value, uint8_t mode) {
        uint8_t high = value & 0xf0;
        uint8_t low = (value << 4) & 0xf0;
        lcd_pulse((high)|mode);
        lcd_pulse((low)|mode);
}

void lcd_sendNib(uint8_t nib) {
        //lcd_write(nib);
        lcd_pulse(nib);
}

void lcd_write(uint8_t data) {
        i2c_beginTransmission(LCD_ADDR);
        i2c_writeByte((int) data | 0x08);
        i2c_endTransmission(1);
}

void lcd_pulse(uint8_t data) {
        lcd_write(data | LCD_MODE_EN);
        _delay_us(40);

        //lcd_write(data & ~LCD_MODE_EN);
        lcd_write(data );
        _delay_us(40);
}