Commit e378fa84 authored by Martin Vítek's avatar Martin Vítek
Browse files

Small fixes in HD44780 lib

parent bc49a32c
......@@ -36,7 +36,7 @@ void HD44780::init(void)
_delay_ms(5);
len();
_delay_us(150);
_delay_us(150);
len();
......@@ -47,15 +47,15 @@ void HD44780::init(void)
set_function_set(LINES_2 | DATA_4_BITS | FONT_5x8);
//send_instruction(0x06);
set_entry_mode(AUTO_INCREMENT);
set_entry_mode(AUTO_INCREMENT | DONT_SHIFT_ENTIRE_DISPLAY);
//send_instruction(0x0c);
set_display_control(DISPLAY_ON | CURSOR_BLINK);
set_display_control(DISPLAY_ON | CURSOR_ON);
set_shift_mode(SHIFT_CURSOR | SHIFT_LEFT);
//send_instruction(0x01);
clear();
_delay_ms(3);
}
//napi� neznam�nkov� int
......@@ -141,7 +141,7 @@ void HD44780::write_hex16(unsigned int cislo)
}
//napis string, umisteny v RAM
void HD44780::write_text(char* text)
void HD44780::write_text(const char* text)
{
unsigned char i=0,temp;
......@@ -167,9 +167,9 @@ void HD44780::write_ftext(const char* text)
void HD44780::len(void) //impuls Enable do LCD
{
enable.on();
_delay_us(2);
_delay_us(3);
enable.off();
_delay_us(2);
_delay_us(3);
}
void HD44780::write_data(char c)
......@@ -215,7 +215,7 @@ void HD44780::set_display_control(uint8_t control)
send_instruction(DISPLAY_ON_OFF_CONTROL | control);
}
void HD44780::shift(uint16_t shift)
void HD44780::set_shift_mode(uint8_t shift)
{
send_instruction(CURSOR_OR_DISPLAY_SHIFT | shift);
}
......
......@@ -8,8 +8,8 @@
struct HD44780_config
{
PORT_t port;
uint8_t reset;
PORT_t &port;
uint8_t register_select;
uint8_t enable;
uint8_t data4;
uint8_t data5;
......@@ -34,14 +34,14 @@ class HD44780
enum instructions
{
CLEAR_DISPLAY = 0x01,
RETURN_HOME = 0x02,
ENTRY_MODE_SET = 0x04,
DISPLAY_ON_OFF_CONTROL = 0x08,
CLEAR_DISPLAY = 0x01,
RETURN_HOME = 0x02,
ENTRY_MODE_SET = 0x04,
DISPLAY_ON_OFF_CONTROL = 0x08,
CURSOR_OR_DISPLAY_SHIFT = 0x10,
FUNCTION_SET = 0x20,
SET_CGRAM_ADDRESS = 0x40,
SET_DDRAM_ADDRESS = 0x80
FUNCTION_SET = 0x20,
SET_CGRAM_ADDRESS = 0x40,
SET_DDRAM_ADDRESS = 0x80
};
enum entry_modes
......@@ -83,14 +83,14 @@ class HD44780
void send_instruction(unsigned char ins);
void set_entry_mode(uint8_t mode);
void set_display_control(uint8_t control);
void shift(uint16_t shift);
void set_shift_mode(uint8_t shift);
void set_function_set(uint8_t set);
void set_CGRAM_address(uint8_t address);
void set_DDRAM_address(uint8_t address);
void write_data(char c);
public:
HD44780(HD44780_config config): register_select(config.port, config.reset),
HD44780(HD44780_config config): register_select(config.port, config.register_select),
enable(config.port, config.enable),
data{
{config.port, config.data4},
......@@ -111,7 +111,7 @@ class HD44780
void write_hex16(unsigned int cislo); //vyp�e int hexadecim�ln�
void write_char (unsigned char dat); //napis znak
void write_text (char* text); //napis string, umisteny v RAM
void write_text (const char* text); //napis string, umisteny v RAM
void write_ftext(const char* text); //napis string, umisteny ve FLASH
void write_num(unsigned int cislo) { write_int_d(cislo, ' ', 5); };
......@@ -120,7 +120,7 @@ class HD44780
void write_byt(char cislo) { write_int_d((cislo),' ',3); };
void write_byt_s(char cislo) { write_int_s((cislo),' ',3); };
void clear() { send_instruction(0x01); _delay_ms(3); }; //vymaz displej
void clear() { send_instruction(CLEAR_DISPLAY); _delay_ms(3); }; //vymaz displej
void cursor_off() { send_instruction(0x0c); }; //vypni kurzor
void cursor_on() { send_instruction(0x0e); }; //zapni kurzor
void cursor_blink() { send_instruction(0x0f); }; //kurzor blika
......@@ -128,5 +128,4 @@ class HD44780
void shift_right() { send_instruction(0x1c); }; //posun text doprava
void gotoxy(uint8_t lin, uint8_t col) { send_instruction(64*((lin)+1)+((col)-1)); }; //jdi na radek (lin)
void gotoxy_new(uint8_t line, uint8_t columm) { set_DDRAM_address( (line*0x40) + columm); };
};
......@@ -14,27 +14,30 @@ int main()
backlight.set_direction(OUTPUT);
backlight.on();
PORTC.DIRSET = PIN4_bm | PIN5_bm | PIN6_bm | PIN7_bm;
PORTC.OUTCLR = PIN4_bm | PIN5_bm | PIN6_bm | PIN7_bm;
const HD44780_config lcd_config = {PORTD, PIN2_bm, PIN3_bm, PIN4_bm, PIN5_bm, PIN6_bm, PIN7_bm};
HD44780 lcd(lcd_config);
lcd.init();
lcd.clear();
for (uint8_t i = 0; i < 2; i++)
{
lcd.gotoxy(i+1,1);
for (uint8_t j = 0; j < 40; j++)
{
lcd.gotoxy_new(i,j);
lcd.write_char('0');
//lcd.gotoxy_new(i,j);
lcd.write_char('a');
}
}
//lcd.gotoxy(1,1);
lcd.gotoxy_new(0,0);
lcd.write_char('x');
//lcd.gotoxy(2,1);
lcd.gotoxy_new(1,2);
//lcd.gotoxy_new(1,2);
lcd.write_text("Ahoj! :)");
for(;;)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment