Wrapper for HD44780 automatically taking care of custom CGRAM patterns and partial redraws to optimize response times
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
hd44780-buf/src/main.c

91 rader
2.4 KiB

#include <stdio.h>
#include <stdint.h>
#include "lcdbuf.h"
int main()
{
struct LcdBuffer buf;
LcdBuffer_Init(&buf, CGROM_A00, CGRAM_CZ);
LcdBuffer_Write(&buf, 2, 10, "Ahoj");
LcdBuffer_Write(&buf, 2, 9, "x");
LcdBuffer_Write(&buf, 2, 6, "mm");
LcdBuffer_Write(&buf, 0, 0, "ěščžýíéů");
LcdBuffer_Write(&buf, 0, 0, "MEOWžýíéůěščřžýíéů");
LcdBuffer_Flush(&buf);
LcdBuffer_Write(&buf, 0, 5, "ĚŠČŘŽÝ");
LcdBuffer_Flush(&buf);
LcdBuffer_Clear(&buf);
LcdBuffer_Flush(&buf);
return 0;
}
/** Write character data at position */
void LcdBuffer_IO_Clear()
{
printf("ClearScreen\n");
}
/** Write character data at position */
void LcdBuffer_IO_WriteAt(lcdbuf_pos_t row, lcdbuf_pos_t col, const uint8_t *buf, lcdbuf_count_t len)
{
printf("W@%d,%d: (len %d) \"", row, col, len); // "\n
for(int i=0; i<len; i++) {
char c = buf[i];
if (c >= 32 && c < 127) {
printf("%c", c);
} else {
printf("\\%d", c);
}
}
printf("\"\n");
}
void LcdBuffer_IO_SetCursorPos(lcdbuf_pos_t cursor_row, lcdbuf_pos_t cursor_col)
{
printf("CURS : %d,%d\n", cursor_row, cursor_col);
}
void LcdBuffer_IO_SetCursorStyle(uint8_t cursor_style)
{
printf("CURS: style 0x%02x\n", cursor_style);
}
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
#define BYTE_TO_BINARY(byte) \
((byte) & 0x80 ? '#' : '.'), \
((byte) & 0x40 ? '#' : '.'), \
((byte) & 0x20 ? '#' : '.'), \
((byte) & 0x10 ? '#' : '.'), \
((byte) & 0x08 ? '#' : '.'), \
((byte) & 0x04 ? '#' : '.'), \
((byte) & 0x02 ? '#' : '.'), \
((byte) & 0x01 ? '#' : '.')
/** Write CGRAM data. Data is always 8 bytes long. */
void LcdBuffer_IO_WriteCGRAM(lcdbuf_pos_t position, const uint8_t *data)
{
printf("G@%d:\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n "
BYTE_TO_BINARY_PATTERN"\n\n",
position,
BYTE_TO_BINARY(data[0]),
BYTE_TO_BINARY(data[1]),
BYTE_TO_BINARY(data[2]),
BYTE_TO_BINARY(data[3]),
BYTE_TO_BINARY(data[4]),
BYTE_TO_BINARY(data[5]),
BYTE_TO_BINARY(data[6]),
BYTE_TO_BINARY(data[7]));
}