MechanicVV
New Member
Good afternoon. Tell me please. When trying to output custom characters from const char font[256][8], garbage appears on the screen. How to solve this problem?
C++:
const char font[256][8] =
{ { 0b11111, 0b10000, 0b10000, 0b11110, 0b10001, 0b10001, 0b11110, 0b00000 },
{ 0b11111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b00000 },
{ 0b00110, 0b01010, 0b01010, 0b01010, 0b01010, 0b01010, 0b11111, 0b10001 },
{ 0b10101, 0b10101, 0b10101, 0b01110, 0b10101, 0b10101, 0b10101, 0b00000 },
{ 0b01110, 0b10001, 0b00001, 0b00110, 0b00001, 0b10001, 0b01110, 0b00000 },
{ 0b00111, 0b01001, 0b01001, 0b01001, 0b01001, 0b01001, 0b10001, 0b00000 },
{ 0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b00000 },
{ 0b10001, 0b10001, 0b10001, 0b01111, 0b00001, 0b10001, 0b01110, 0b00000 }
};
void read_stat_lcd() {
while ((Lcd_com & 0x03) != 0x03)
;
}
void write_com(uint8_t com) {
read_stat_lcd();
WriteCommand(com);
}
void write_dat(uint8_t dat) {
read_stat_lcd();
WriteData(dat);
}
void T6963_WriteDisplayData(unsigned char x) // Writes display data and increment address pointer
{
write_dat(x);
write_com(T6963_DATA_WRITE_AND_INCREMENT);
}
void Set_Address_pointer(uint16_t addr) {
write_dat(addr & 0xff);
write_dat(addr >> 8);
write_com(0x24);
}
void Set_Offset_Register(uint16_t addr) {
write_dat(addr & 0xff);
write_dat(addr >> 8);
write_com(0x22);
}
void glcd_clear_graph() {
Set_Address_pointer(T6963_GRAPHIC_HOME);
for (uint16_t i = 0; i < T6963_GRAPHIC_SIZE; i++) {
write_dat(0);
write_com(T6963_DATA_WRITE_AND_INCREMENT);
}
}
void glcd_clear_text() {
Set_Address_pointer(T6963_TEXT_HOME);
for (uint16_t i = 0; i < T6963_TEXT_SIZE; i++) {
write_dat(0);
write_com(T6963_DATA_WRITE_AND_INCREMENT);
}
}
uint16_t add = 0;
void T6963_DefineCharacter(uint8_t charCode, const char (*defChar)[8]) // Write single char pattern to character generator area of display RAM memory
{
add = charCode;
add = add << 3; //Character code 00h to 80h assign External character generator, when
//External generator mode.
Set_Address_pointer(add);
for (uint8_t i = 0; i < 8; i++) //The process of writing user characters to CG RAM
T6963_WriteDisplayData(defChar[charCode][i]);
Set_Address_pointer(charCode); //Setting the initial position of the first sign on the LCD screen
write_dat(charCode); //Writing data
write_com(T6963_DATA_WRITE_AND_NONVARIALBE); //Writes display data and Non-variable address pointer
}
void lcd_init(void) {
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, RESET);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, SET); //Hardware reset of the LCD
HAL_Delay(10);
write_com(T6963_MODE_SET | T6963_MODE_CG_RAM); //Setting the operating mode external CG RAM
Set_Address_pointer(T6963_GRAPHIC_HOME);
write_com(T6963_SET_GRAPHIC_HOME_ADDRESS);
Set_Address_pointer(0x001E);
write_com(T6963_SET_GRAPHIC_AREA);
Set_Address_pointer(0);
write_com(T6963_SET_TEXT_HOME_ADDRESS);
Set_Address_pointer(0x0028);
write_com(T6963_SET_TEXT_AREA);
Set_Offset_Register(0);
Set_cursor(0, 0);
write_com(
T6963_DISPLAY_MODE | T6963_TEXT_DISPLAY_ON
| T6963_GRAPHIC_DISPLAY_ON | T6963_CURSOR_DISPLAY_ON
| T6963_CURSOR_BLINK_ON);
}
int main(void) {
lcd_init();
glcd_clear_text();
glcd_clear_graph();
for (uint8_t k = 0; k < 8; k++)
{
T6963_DefineCharacter(k, font); //Writing custom characters from the "font" array
//and displaying these characters on the screen
}
}