Create a function to move the cursor
Create a function (`lcs_move_cursor()`) to move the cursor in order to reduce code repetition.
This commit is contained in:
parent
cc105aa9c9
commit
47bd5e45f7
1 changed files with 22 additions and 63 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -201,13 +202,19 @@ static void lcd_update_backlight(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void lcd_move_cursor(const uint8_t column, const uint8_t row) {
|
||||||
|
assert(row < 16);
|
||||||
|
|
||||||
|
SPI_PORT &= ~(1 << LCD_CD);
|
||||||
|
lcd_write(0x00 + (0x0F & column));
|
||||||
|
lcd_write(0x10 + (column >> 4));
|
||||||
|
lcd_write(0xB0 + row);
|
||||||
|
SPI_PORT |= (1 << LCD_CD);
|
||||||
|
}
|
||||||
|
|
||||||
static void lcd_fill(const uint8_t data) {
|
static void lcd_fill(const uint8_t data) {
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB0 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
for (uint8_t j = 0; j < 102; j++)
|
for (uint8_t j = 0; j < 102; j++)
|
||||||
lcd_write(data);
|
lcd_write(data);
|
||||||
|
@ -280,11 +287,7 @@ static void lcd_splash(void) {
|
||||||
lcd_fill(0x00);
|
lcd_fill(0x00);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 5; i++) {
|
for (uint8_t i = 0; i < 5; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(31, 1 + i);
|
||||||
lcd_write(0x0F);
|
|
||||||
lcd_write(0x11);
|
|
||||||
lcd_write(0xB1 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
for (uint8_t j = 0; j < 40; j++)
|
for (uint8_t j = 0; j < 40; j++)
|
||||||
lcd_write(sacred_chao[i * 40 + j]);
|
lcd_write(sacred_chao[i * 40 + j]);
|
||||||
|
@ -292,11 +295,7 @@ static void lcd_splash(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(26, 6 + i);
|
||||||
lcd_write(0x0A);
|
|
||||||
lcd_write(0x11);
|
|
||||||
lcd_write(0xB6 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
for (uint8_t j = 0; j < 48; j++)
|
for (uint8_t j = 0; j < 48; j++)
|
||||||
lcd_write(onders_org[i * 48 + j]);
|
lcd_write(onders_org[i * 48 + j]);
|
||||||
|
@ -327,39 +326,19 @@ static void lcd_home(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB0 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("CH1\0", i, ch1_selected);
|
lcd_write_string_page("CH1\0", i, ch1_selected);
|
||||||
lcd_write_kerning(2, ch1_selected);
|
lcd_write_kerning(2, ch1_selected);
|
||||||
|
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, 2 + i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB2 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("CH2\0", i, ch2_selected);
|
lcd_write_string_page("CH2\0", i, ch2_selected);
|
||||||
lcd_write_kerning(2, ch2_selected);
|
lcd_write_kerning(2, ch2_selected);
|
||||||
|
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, 4 + i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB4 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("CH3\0", i, ch3_selected);
|
lcd_write_string_page("CH3\0", i, ch3_selected);
|
||||||
lcd_write_kerning(2, ch3_selected);
|
lcd_write_kerning(2, ch3_selected);
|
||||||
|
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(33, 6 + i);
|
||||||
lcd_write(0x01);
|
|
||||||
lcd_write(0x12);
|
|
||||||
lcd_write(0xB6 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("SETUP\0", i, setup_selected);
|
lcd_write_string_page("SETUP\0", i, setup_selected);
|
||||||
lcd_write_kerning(2, setup_selected);
|
lcd_write_kerning(2, setup_selected);
|
||||||
}
|
}
|
||||||
|
@ -393,24 +372,14 @@ static void lcd_setup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB0 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_kerning(30, true);
|
lcd_write_kerning(30, true);
|
||||||
lcd_write_string_page("SETUP\0", i, true);
|
lcd_write_string_page("SETUP\0", i, true);
|
||||||
lcd_write_kerning(33, true);
|
lcd_write_kerning(33, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, 2 + i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB2 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("CONTRAST:\0", i, contrast_selected);
|
lcd_write_string_page("CONTRAST:\0", i, contrast_selected);
|
||||||
lcd_write_kerning(2, contrast_selected);
|
lcd_write_kerning(2, contrast_selected);
|
||||||
lcd_write_kerning(16, false);
|
lcd_write_kerning(16, false);
|
||||||
|
@ -419,12 +388,7 @@ static void lcd_setup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(0, 4 + i);
|
||||||
lcd_write(0x00);
|
|
||||||
lcd_write(0x10);
|
|
||||||
lcd_write(0xB4 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected);
|
lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected);
|
||||||
lcd_write_kerning(2, backlight_selected);
|
lcd_write_kerning(2, backlight_selected);
|
||||||
lcd_write_kerning(5, false);
|
lcd_write_kerning(5, false);
|
||||||
|
@ -433,12 +397,7 @@ static void lcd_setup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
SPI_PORT &= ~(1 << LCD_CD);
|
lcd_move_cursor(33, 6 + i);
|
||||||
lcd_write(0x01);
|
|
||||||
lcd_write(0x12);
|
|
||||||
lcd_write(0xB6 + i);
|
|
||||||
SPI_PORT |= (1 << LCD_CD);
|
|
||||||
|
|
||||||
lcd_write_string_page("BACK:\0", i, back_selected);
|
lcd_write_string_page("BACK:\0", i, back_selected);
|
||||||
lcd_write_kerning(2, back_selected);
|
lcd_write_kerning(2, back_selected);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue