avr/display/display.c

62 lines
1.8 KiB
C

/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
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 <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <display.h>
#include <util/delay.h>
#include <base.h>
void display_strobe_line(gpio_t *line) {
set_line(line);
_delay_us(100);
clear_line(line);
_delay_us(100);
}
void write_instruction(display_t *disp, uint8_t bitcode) {
clear_line(&disp->register_select);
sr_send_msb(&disp->reg, bitcode);
_delay_ms(1);
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);
_delay_ms(1);
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, 0b00111100);
}
void display_clear(display_t *disp) {
write_instruction(disp, 0x01);
write_instruction(disp, 0x02);
}
void display_enable(display_t *disp) {
write_instruction(disp, 0x0e);
}
void display_write_message(display_t *disp, const char *msg) {
for (size_t i = 0; msg[i] != 0; i++) {
write_char(disp, msg[i]);
}
}