From ad2623d8c4bc51638343ae9a628f8647ff558155 Mon Sep 17 00:00:00 2001 From: Thomas Albers Date: Mon, 14 Aug 2023 10:47:54 +0200 Subject: Initial commit --- stn/stn.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 stn/stn.c (limited to 'stn/stn.c') diff --git a/stn/stn.c b/stn/stn.c new file mode 100644 index 0000000..7ad307a --- /dev/null +++ b/stn/stn.c @@ -0,0 +1,236 @@ +#include + +#include + +#define NOP \ + do { \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + __asm__("nop"); \ + } while (0) + +// extern const uint8_t font[97][8]; + +static inline void +stn_display_on(void) +{ + stn_1_inst = 0x3F; + NOP; + stn_2_inst = 0x3F; + NOP; +} + +static inline +void stn_start_line(uint8_t x) +{ + stn_1_inst = 0xC0 | (x & 0x3F); + NOP; + NOP; + NOP; + stn_2_inst = 0xC0 | (x & 0x3F); + NOP; + NOP; + NOP; +} + +static inline void +stn_set_row(uint8_t x) +{ + stn_1_inst = 0xB8 | x; + NOP; + NOP; + NOP; + stn_2_inst = 0xB8 | x; + NOP; + NOP; + NOP; +} + + +static inline void +stn_set_column(uint8_t x) +{ + if (x & 0xC0) + stn_2_inst = 0x40 | (x >> 6); + else + stn_1_inst = 0x40 | x; + + NOP; + NOP; + NOP; +} + +static inline void +stn_set_columns(uint8_t x) +{ + stn_1_inst = 0x40 | x; + NOP; + NOP; + NOP; + stn_2_inst = 0x40 | x; + NOP; + NOP; + NOP; +} + +void +stn_clear_screen(void) +{ + for (uint8_t i = 0; i < 8; ++i) { + // set x address + stn_set_row(i); + + // set y address + stn_set_columns(0); + + for (uint8_t j = 0; j < 64; ++j) { + stn_1_data = 0; + NOP; + NOP; + NOP; + stn_2_data = 0; + NOP; + NOP; + NOP; + } + } +} + +/* void */ +/* stn_print(int x, int y, const char *str) */ +/* { */ +/* stn_set_row(y); */ +/* stn_set_column(x << 3); */ + +/* while (*str) { */ +/* const uint8_t *p = font[(*str++) - ' ']; */ + +/* if (x < 8) { */ +/* for (uint8_t i = 0; i < 8; ++i) */ +/* stn_1_data = p[i]; */ +/* } else { */ +/* for (uint8_t i = 0; i < 8; ++i) */ +/* stn_2_data = p[i]; */ +/* } */ + +/* if (++x & 0xF0) { */ +/* x = 0; */ +/* stn_set_row(++y & 0x07); */ +/* stn_set_columns(0); */ +/* } */ +/* } */ +/* } */ + +int +main(void) +{ + stn_display_on(); + stn_start_line(0); + stn_clear_screen(); + // stn_print(1, 1, "Hello World! how are you"); + stn_set_columns(0); + + while (1) { + stn_set_columns(0); + + for (uint8_t i = 0; i < 64; ++i) { + stn_1_data = i; + NOP; + NOP; + NOP; + } + + volatile uint8_t c; + for (uint8_t i = 0; i < 9; ++i) { + c = stn_1_data; + NOP; + NOP; + NOP; + } + + + /* for (uint8_t i = 0; i < 64; ++i) { */ + /* stn_2_data = i; */ + /* NOP; */ + /* } */ + + stn_1_inst = 0x40 | 0; + NOP; + NOP; + NOP; + + /* // stn_set_columns(0); */ + for (uint8_t i = 0; i < 64; ++i) { + c = stn_1_data; + NOP; + NOP; + NOP; + stn_2_data = c; + NOP; + NOP; + NOP; + } + } + + // return 0; +} -- cgit v1.2.3