/* Copyright 2022, Savanni D'Gerinel This file is part of Savanni's AVR library. Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Lumeto. If not, see . */ #include #include #include #include void display_strobe_line(gpio_t *line) { set_line(line); _delay_us(50); clear_line(line); _delay_us(50); } void write_instruction(display_t *disp, uint8_t bitcode) { clear_line(&disp->register_select); sr_send_msb(&disp->reg, bitcode); display_strobe_line(&disp->enable); } void write_char(display_t *disp, uint8_t bitcode) { set_line(&disp->register_select); sr_send_msb(&disp->reg, bitcode); display_strobe_line(&disp->enable); } void display_init(display_t *disp) { sr_initialize(&disp->reg); set_line_direction(&disp->register_select, LINE_OUT); set_line_direction(&disp->enable, LINE_OUT); write_instruction(disp, 0b00111000); } void display_clear(display_t *disp) { write_instruction(disp, 0b00000001); _delay_ms(3); write_instruction(disp, 0b00000010); _delay_ms(3); } void display_enable(display_t *disp) { write_instruction(disp, 0b00001100); _delay_us(100); write_instruction(disp, 0b00000100); _delay_us(100); } void display_set_location(display_t *disp, size_t row, size_t column) { size_t addr = row * 40 + column; write_instruction(disp, 0b10000000 | addr); _delay_us(100); } void display_write_message(display_t *disp, const char *msg) { for (size_t i = 0; msg[i] != 0; i++) { write_char(disp, msg[i]); } }