Маленькое дополнение к прошлой статье.
Составил таблицу и написал код для вывода на экран шестнадцатеричных чисел:
#define SEG_A BIT(6) #define SEG_B BIT(2) #define SEG_C BIT(5) #define SEG_D BIT(4) #define SEG_E BIT(0) #define SEG_F BIT(7) #define SEG_G BIT(3) #define SEG_H BIT(15) #define SEG_J BIT(14) #define SEG_K BIT(10) #define SEG_M BIT(1) #define SEG_N BIT(12) #define SEG_P BIT(8) #define SEG_Q BIT(11) #define SEG_DP BIT(13) #define SEG_COL BIT(9) #define SYMBOL_0 (uint16_t)(SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F) #define SYMBOL_1 (uint16_t)(SEG_B | SEG_C) #define SYMBOL_2 (uint16_t)(SEG_A | SEG_B | SEG_G | SEG_M | SEG_E | SEG_D) #define SYMBOL_3 (uint16_t)(SEG_A | SEG_B | SEG_C | SEG_D | SEG_G | SEG_M) #define SYMBOL_4 (uint16_t)(SEG_F | SEG_G | SEG_M | SEG_B | SEG_C) #define SYMBOL_5 (uint16_t)(SEG_A | SEG_F | SEG_G | SEG_M | SEG_C | SEG_D) #define SYMBOL_6 (uint16_t)(SEG_A | SEG_F | SEG_G | SEG_M | SEG_C | SEG_D | SEG_E) #define SYMBOL_7 (uint16_t)(SEG_A | SEG_B | SEG_C) #define SYMBOL_8 (uint16_t)(SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G | SEG_M) #define SYMBOL_9 (uint16_t)(SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G | SEG_M) #define SYMBOL_A (uint16_t)(SEG_A | SEG_B | SEG_E | SEG_F | SEG_C | SEG_G | SEG_M) #define SYMBOL_B (uint16_t)(SEG_F | SEG_E | SEG_D | SEG_C | SEG_G | SEG_M) #define SYMBOL_C (uint16_t)(SEG_A | SEG_F | SEG_E | SEG_D) #define SYMBOL_D (uint16_t)(SEG_B | SEG_C | SEG_D | SEG_E | SEG_G | SEG_M) #define SYMBOL_E (uint16_t)(SEG_A | SEG_F | SEG_E | SEG_D | SEG_G | SEG_M) #define SYMBOL_F (uint16_t)(SEG_A | SEG_F | SEG_E | SEG_G | SEG_M) static const uint16_t mcu_lcd_symbols_decoder[] = { SYMBOL_0, SYMBOL_1, SYMBOL_2, SYMBOL_3, SYMBOL_4, SYMBOL_5, SYMBOL_6, SYMBOL_7, SYMBOL_8, SYMBOL_9, SYMBOL_A, SYMBOL_B, SYMBOL_C, SYMBOL_D, SYMBOL_E, SYMBOL_F }; void mcu_lcd_print(uint8_t position, uint16_t symbols) { uint8_t i; switch (position) { case (0): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(0) | BIT(1) | BIT(28) | BIT(29)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(0) : 0) | (symbols & 0x02 ? BIT(1) : 0) | (symbols & 0x04 ? BIT(28) : 0) | (symbols & 0x08 ? BIT(29) : 0); symbols >>= 4; } break; } case (1): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(2) | BIT(7) | BIT(26) | BIT(27)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(2) : 0) | (symbols & 0x02 ? BIT(7) : 0) | (symbols & 0x04 ? BIT(26) : 0) | (symbols & 0x08 ? BIT(27) : 0); symbols >>= 4; } break; } case (2): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(8) | BIT(9) | BIT(24) | BIT(25)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(8) : 0) | (symbols & 0x02 ? BIT(9) : 0) | (symbols & 0x04 ? BIT(24) : 0) | (symbols & 0x08 ? BIT(25) : 0); symbols >>= 4; } break; } case (3): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(10) | BIT(11) | BIT(20) | BIT(21)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(10) : 0) | (symbols & 0x02 ? BIT(11) : 0) | (symbols & 0x04 ? BIT(20) : 0) | (symbols & 0x08 ? BIT(21) : 0); symbols >>= 4; } break; } case (4): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(12) | BIT(13) | BIT(18) | BIT(19)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(12) : 0) | (symbols & 0x02 ? BIT(13) : 0) | (symbols & 0x04 ? BIT(18) : 0) | (symbols & 0x08 ? BIT(19) : 0); symbols >>= 4; } break; } case (5): { for (i = 0; i > 8; i += 2) { LCD->RAM[i] &= ~(BIT(14) | BIT(15) | BIT(17) | BIT(16)); // LCD->RAM[i] |= (symbols & 0x01 ? BIT(14) : 0) | (symbols & 0x02 ? BIT(15) : 0) | (symbols & 0x04 ? BIT(17) : 0) | (symbols & 0x08 ? BIT(16) : 0); symbols >>= 4; } break; } } } void mcu_lcd_print_hex(uint16_t data) { // ожидаем завершения предыдущего вывода данных while (LCD->SR & LCD_SR_UDR) { } mcu_lcd_print(3, mcu_lcd_symbols_decoder[data & 0x0F]); mcu_lcd_print(2, mcu_lcd_symbols_decoder[(data >> 4) & 0x0F]); mcu_lcd_print(1, mcu_lcd_symbols_decoder[(data >> 8) & 0x0F]); mcu_lcd_print(0, mcu_lcd_symbols_decoder[(data >> 12) & 0x0F]); // запрос вывода новых данных LCD->SR |= LCD_SR_UDR; }
ZiB @ GitHub