Usage record of font chip GT20L16S1Y

1. Chip basic information

16x16 dot matrix Chinese character library chip
GB2312 GB simplified Chinese characters (including legally authorized by the state beacon Commission) and ASCII characters are supported
The arrangement format is vertical and horizontal
SPI serial bus interface
Calculate the address of the word library in the chip through the character inner code

2. Font content

3. Chip IO description

4. Chip operation


Two reading modes are supported, general Read and FAST_READ.

4.1 General Reading


1byte read command, 3byte address, followed by the font data output by the chip.

4.2 fast reading


1byte read command, 3byte address, 1 byte arbitrary data, followed by the font data output by the chip.

5. Lattice arrangement format (vertical and horizontal)

Each Chinese character is stored in the chip in the form of Chinese character dot matrix font. Each point is represented by a binary bit. The point of 1 can be displayed on the screen when displayed, and the point of 0 will not be displayed on the screen. The lattice arrangement format is vertical and horizontal: that is, the high bit of a byte represents the lower point, and the low bit represents the upper point (if the user reads the lattice data according to the 16bit bus width, please pay attention to the order of high and low bytes). After one line is filled, the next line will be arranged. In this way, the lattice information will be directly displayed on the display according to the above rules, and the corresponding Chinese characters will appear.

The information of a 15X16 point Chinese character needs 32 bytes (BYTE 0 – BYTE 31), so the order of the dot matrix is as follows (this is closely related to the order of writing data when displayed on the LCD)

6. Code implementation

In this paper, GD32F303VC is used to read the word library, and GPIO is used to simulate SPI mode.

6.1 definition and initialization of IO port

#define ZK_CS_OUT(level)  { if(level) \
				            { gpio_bit_set(GPIOB,GPIO_PIN_12);} \
					        else    \
					        { gpio_bit_reset(GPIOB,GPIO_PIN_12);} \
                          }	

#define ZK_SCK_OUT(level) { if(level) \
				            { gpio_bit_set(GPIOB,GPIO_PIN_13);} \
					        else    \
					        { gpio_bit_reset(GPIOB,GPIO_PIN_13);} \
                          }	
							
#define ZK_SO_OUT(level) { if(level) \
				           { gpio_bit_set(GPIOB,GPIO_PIN_14);} \
					       else    \
					       { gpio_bit_reset(GPIOB,GPIO_PIN_14);} \
                         }	

#define ZK_SI_IN() gpio_input_bit_get(GPIOB,GPIO_PIN_15)
static void GT20L16S1YIoInit(void)
{
	rcu_periph_clock_enable(RCU_GPIOB);
    gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14);	
	gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ,GPIO_PIN_15);	
}

6.2 SPI reading and writing

static void GT20L16S1YSendByte( uint32_t addr )
{
    uint8_t i;
	
    addr = addr | 0x03000000;
    for( i = 0; i < 32; i++ )
    {
        ZK_SCK_OUT(0);
        if( addr & 0x80000000 )
        {
            ZK_SO_OUT(1);
        }
        else
        {
           ZK_SO_OUT(0);
        }
        ZK_SCK_OUT(1);
        addr = addr << 1;
    }
}


static uint8_t GT20L16S1YReadByte( void )
{
    uint8_t i;
    uint8_t dat = 0;
	
    ZK_SCK_OUT(1);
    for( i = 0; i < 8; i++ )
    {
        ZK_SCK_OUT(0);
        dat = dat << 1;
        if( ZK_SI_IN() )
        {
            dat = dat | 0x01;
        }
        else
        {
            dat &= 0xfe;
        }
        ZK_SCK_OUT(1);
    }
    return dat;
}

6.3 GT20L16S1Y reading and writing

/****************************************************
Description: read data from font
Address  :  Represents the byte address of the character dot matrix in the chip.
byte_long:  Is the number of read lattice data bytes.
*p_arr   :  Is an array that holds the read lattice data.
*****************************************************/
static void GT20L16S1YRead( uint32_t  address, uint8_t  byte_long, uint8_t* p_arr )
{
    unsigned int j = 0;
	
    ZK_CS_OUT(0);
    GT20L16S1YSendByte( address );
    for( j = 0; j < byte_long; j++ )
    {
        p_arr[j] = GT20L16S1YReadByte();
    }
    ZK_CS_OUT(1);
}

6.4. GT20L16S1Y word reading Library

/***************************************
ASCII character set
ASCIICode: Represents ASCII code (8bits)
BaseAdd: Describe the starting address of the font set in the chip.
r_dat_bat:  Is a function of reading lattice data.
DZ_Data: Is an array that holds the read lattice data.
***************************************/
uint8_t  GT20L16S1YGetAsciiData( uint8_t ASCIICode, uint32_t BaseAdd, uint8_t* S1YDZ_Data )
{
    if( ( ASCIICode >= 0x20 ) && ( ASCIICode <= 0x7e ) )
    {
        switch( BaseAdd )
        {
            case 0x3bfc0:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 8 + BaseAdd, 8, S1YDZ_Data ); //Standard 5X7, 96
                break ;
            case 0x66c0:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 8 + BaseAdd, 8, S1YDZ_Data ); //Standard 7X8, 96
                break ;
            case 0x3b7c0:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 16 + BaseAdd, 16, S1YDZ_Data ); //Standard 8X16, 96
                break ;
            case 0x3cf80:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 26 + BaseAdd, 16, S1YDZ_Data ); //Bold 8X16, 96
                break ;
            case 0x3c2c0:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 34 + BaseAdd + 2, 32, S1YDZ_Data ); //16 dot matrix unequal width, Arial (square head), 96
                break ;
            case 0x3d580:
                GT20L16S1YRead( ( ASCIICode - 0x20 ) * 34 + BaseAdd + 2, 32, S1YDZ_Data ); //16 dot matrix unequal width, Times New Roman, 96
                break ;
            default:
                break;
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

/***************************************************
16*16 Dot GB2312 standard dot matrix font library
GBCode Indicates the internal code of Chinese characters.
MSB Represents the high 8bits of Chinese character internal code GBCode.
LSB Indicates the low 8bits of Chinese character internal code GBCode.
Address Represents the byte address of Chinese character or ASCII character dot matrix in the chip.
BaseAdd: Describe the starting address of dot matrix data in the font chip.
r_dat_bat Is a function of reading lattice data.
DZ_Data Is an array that holds the read lattice data.
*****************************************************/
void GT20L16S1YGetGb2312Data( uint8_t MSB, uint8_t LSB, uint8_t* S1YDZ_Data )
{
    uint32_t temp = ( MSB - 0xB0 ) * 94 + LSB - 0xA1;
    uint32_t BaseAdd = 0, Address;
	
    if( MSB == 0xA9 && LSB >= 0xA1 )                       //GB2312 characters, area A9
    {
        Address = ( 282 + ( LSB - 0xA1 ) ) * 32 + BaseAdd;
    }
    else if( MSB >= 0xA1 && MSB <= 0xA3 && LSB >= 0xA1 )   //GB2312 characters, A1-A3 area, A1-A3, A9, 376 characters in total
    {
        Address = ( ( MSB - 0xA1 ) * 94 + ( LSB - 0xA1 ) ) * 32 + BaseAdd;
    }
    else if( MSB >= 0xB0 && MSB <= 0xF7 && LSB >= 0xA1 )   //GB2312 Chinese characters, 6763 
    {
        Address = ( 846 + temp ) * 32 + BaseAdd;
    }
    GT20L16S1YRead( Address, 32, S1YDZ_Data );
}
/****************************************************
8*16 Dot international extended characters, 126, AAA1-ABC0

BaseAdd: Describe the starting byte address of this set of font in the font chip.
FontCode: Represents the inner character code (16bits)
Address: Represents the byte address of the character dot matrix in the chip.
r_dat_bat Is a function of reading lattice data.
DZ_Data Is an array that holds the read lattice data.
*****************************************************/
void GT20L16S1YGetExt8x16Data( uint16_t FontCode, uint8_t* S1YDZ_Data )
{
    uint32_t BaseAdd = 0x3b7d0, Address;
    uint32_t temp1 = ( FontCode - 0xAAA1 );
    uint32_t temp2 = ( FontCode - 0xABA1 + 95 );
	
    if( FontCode >= 0xAAA1 && FontCode <= 0xAAFE ) 
    {
        Address = temp1 * 16 + BaseAdd;
    }
    else if( FontCode >= 0xABA1 && FontCode <= 0xABC0 )
    {
        Address = temp2 * 16 + BaseAdd;
    }
    GT20L16S1YRead( Address, 16, S1YDZ_Data );
}

6.5 GT20L16S1Y read / write test

The manual gives the font of the letter "A" to compare the font that can read "A" to verify whether the driver is correct.

Arrangement: Y (vertical and horizontal)
Lattice size 8X16 letter "A"
Lattice data: 00 E0 9C 82 9C E0 00 0f 00 00 00 00 0f 00

void GT20L16S1YTest(void)
{
	uint8_t zk[16];
	uint8_t zk_str[32];
	GT20L16S1YGetAsciiData( 'A', 0x3b7c0, zk);
	
	for(uint8_t i=0;i<16;i++)
	{
		sprintf((char *)(&zk_str[3*i])," %02x",zk[i]);
	}
	log_debug("[%s]\r\n",zk_str);
}

7. Expand

GB2312 simplified Chinese coding table: http://tools.jb51.net/table/gb2312

8. Read font LCD display

Keywords: Single-Chip Microcomputer MCU

Added by maxsslade on Tue, 28 Dec 2021 22:08:02 +0200