驱动字库芯片GT23L24M0140
生活随笔
收集整理的這篇文章主要介紹了
驱动字库芯片GT23L24M0140
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
驅動字庫芯片GT23L24M0140
本文博客鏈接:http://blog.csdn.net/jdh99,作者:jdh,轉載請注明.
環境:
主機:WIN8
開發環境:MDK5.13
mcu: stm32f407VGIGH6
字庫芯片:GT23L24M0140
說明:
GT23L24M0140是一款支持GB18030標準的字庫芯片,有多種大小的字體可供選擇。
本文驅動了其中常用的字體。
源代碼:
drv_font.h
/********************************************************************* * 字庫芯片驅動層頭文件 * (c)copyright 2013,jdh * All Right Reserved *新建日期:2015/2/2 by jdh *修改日期:2015/2/3 by jdh **********************************************************************/ /********************************************************************* 硬件連接說明 電路標號 單片機引腳 特殊功能 SPI1_NSS PA4 SPI1_NSS SPI1_MISO PA6 SPI1_MISO SPI1_MOSI PA7 SPI1_MOSI SPI1_SCK PA5 SPI1_SCK **********************************************************************/#ifndef _DRV_FONT_H_ #define _DRV_FONT_H_/********************************************************************* * 頭文件 **********************************************************************/#include "stm32f4xx.h"/********************************************************************* * 函數 **********************************************************************//********************************************************************* * 初始化字庫芯片 **********************************************************************/void drv_font_init(void);/********************************************************************* * 打開SPI使能 **********************************************************************/void drv_font_enable(void);/********************************************************************* * 關閉SPI使能 **********************************************************************/void drv_font_disable(void);/********************************************************************* * spi發送一個字節 *參數:dat:數據 *返回:spi接收到的字節 **********************************************************************/uint8_t drv_font_send_byte(uint8_t dat);#endifdrv_font.c
/********************************************************************* * 字庫芯片驅動層文件 * (c)copyright 2015,jdh * All Right Reserved *新建日期:2015/2/2 by jdh *修改日期:2015/2/3 by jdh **********************************************************************//********************************************************************* * 頭文件 **********************************************************************/#include "drv_font.h"/********************************************************************* * 靜態函數 **********************************************************************//********************************************************************* * 初始化spi **********************************************************************/static void init_spi(void);/********************************************************************* * 函數 **********************************************************************//********************************************************************* * 初始化字庫芯片 **********************************************************************/void drv_font_init(void) {//初始化spiinit_spi(); }/********************************************************************* * 打開SPI使能 **********************************************************************/void drv_font_enable(void) {GPIO_ResetBits(GPIOA, GPIO_Pin_4); }/********************************************************************* * 關閉SPI使能 **********************************************************************/void drv_font_disable(void) {GPIO_SetBits(GPIOA, GPIO_Pin_4); }/********************************************************************* * spi發送一個字節 *參數:dat:數據 *返回:spi接收到的字節 **********************************************************************/uint8_t drv_font_send_byte(uint8_t dat) {while ((SPI1->SR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET);SPI1->DR = dat;while ((SPI1->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET);return (SPI1->DR); }/********************************************************************* * 初始化spi **********************************************************************/static void init_spi(void) {//定義IO初始化結構體GPIO_InitTypeDef GPIO_InitStructure ;//定義SPI初始化結構體SPI_InitTypeDef SPI_InitStructure ;//配置CS//初始化時鐘RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);GPIO_PinAFConfig(GPIOA,GPIO_PinSource4,GPIO_AF_SPI1);//管腳模式:輸出口GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //類型:推挽模式GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //上拉下拉設置GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //IO口速度GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//管腳指定GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;//初始化GPIO_Init(GPIOA, &GPIO_InitStructure);//關閉使能drv_font_disable();//初始化SPI//關閉SPISPI_Cmd(SPI1,DISABLE);//初始化SPI時鐘 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);//設置IO口時鐘 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_SPI1);GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_SPI1);//管腳模式:輸出口GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //類型:推挽模式GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //上拉下拉設置GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //IO口速度GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//管腳指定GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;//初始化GPIO_Init(GPIOA, &GPIO_InitStructure);// SPI配置SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex ;SPI_InitStructure.SPI_Mode = SPI_Mode_Master ;SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b ;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low ;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge ;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft ;//SPI波特率分頻設置SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16 ;//SPI設置成LSB模式SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB ;SPI_InitStructure.SPI_CRCPolynomial = 7 ;SPI_Init( SPI1, &SPI_InitStructure ) ;//啟動SPISPI_Cmd(SPI1,ENABLE); }inf_font.h
/********************************************************************* * 字庫芯片接口層頭文件 * (c)copyright 2015,jdh * All Right Reserved *新建日期:2015/2/3 by jdh *修改日期:2015/2/5 by jdh *修改日期:2015/2/6 by jdh **********************************************************************/#ifndef _INF_FONT_H_ #define _INF_FONT_H_/********************************************************************* * 頭文件 **********************************************************************/#include "drv_font.h"/********************************************************************* * 宏定義 **********************************************************************//********************************************************************* * 字體定義 **********************************************************************//********************************************************************* * 7*8點陣ASCII標準字符 **********************************************************************///字體 #define ASCII_7X8 1 //起始地址 #define ASCII_7X8_ADDR_BASE 0x080300 //寬,位數 #define ASCII_7X8_WIDTH 8 //高,位數 #define ASCII_7X8_HEIGHT 8 //字節數 #define ASCII_7X8_SIZE 8/********************************************************************* * 7*8點陣ASCII粗體字符 **********************************************************************///字體 #define ASCII_BOLD_7X8 2 //起始地址 #define ASCII_BOLD_7X8_ADDR_BASE 0x080600 //寬,位數 #define ASCII_BOLD_7X8_WIDTH 8 //高,位數 #define ASCII_BOLD_7X8_HEIGHT 8 //字節數 #define ASCII_BOLD_7X8_SIZE 8/********************************************************************* * 6*12點陣ASCII標準字符 **********************************************************************///字體 #define ASCII_6X12 3 //起始地址 #define ASCII_6X12_ADDR_BASE 0x080900 //寬,位數 #define ASCII_6X12_WIDTH 8 //高,位數 #define ASCII_6X12_HEIGHT 12 //字節數 #define ASCII_6X12_SIZE 12/********************************************************************* * 8*16點陣ASCII標準字符 **********************************************************************///字體 #define ASCII_8X16 4 //起始地址 #define ASCII_8X16_ADDR_BASE 0x080D80 //寬,位數 #define ASCII_8X16_WIDTH 8 //高,位數 #define ASCII_8X16_HEIGHT 16 //字節數 #define ASCII_8X16_SIZE 16/********************************************************************* * 8*16點陣ASCII粗體字符 **********************************************************************///字體 #define ASCII_BOLD_8X16 5 //起始地址 #define ASCII_BOLD_8X16_ADDR_BASE 0x081580 //寬,位數 #define ASCII_BOLD_8X16_WIDTH 8 //高,位數 #define ASCII_BOLD_8X16_HEIGHT 16 //字節數 #define ASCII_BOLD_8X16_SIZE 16/********************************************************************* * 12*24點陣ASCII標準字符 **********************************************************************///字體 #define ASCII_12X24 6 //起始地址 #define ASCII_12X24_ADDR_BASE 0x081B80 //寬,位數 #define ASCII_12X24_WIDTH 12 //高,位數 #define ASCII_12X24_HEIGHT 24 //字節數 #define ASCII_12X24_SIZE 48/********************************************************************* * 16*32點陣ASCII標準字符 **********************************************************************///字體 #define ASCII_16X32 7 //起始地址 #define ASCII_16X32_ADDR_BASE 0x082D80 //寬,位數 #define ASCII_16X32_WIDTH 16 //高,位數 #define ASCII_16X32_HEIGHT 32 //字節數 #define ASCII_16X32_SIZE 64/********************************************************************* * 16*32點陣ASCII粗體字符 **********************************************************************///字體 #define ASCII_BOLD_16X32 8 //起始地址 #define ASCII_BOLD_16X32_ADDR_BASE 0x084580 //寬,位數 #define ASCII_BOLD_16X32_WIDTH 16 //高,位數 #define ASCII_BOLD_16X32_HEIGHT 32 //字節數 #define ASCII_BOLD_16X32_SIZE 64/********************************************************************* * 12*12點陣GB18030漢字 **********************************************************************///字體 #define GB18030_12X12 9 //起始地址 #define GB18030_12X12_ADDR_BASE 0x093D0E //寬,位數 #define GB18030_12X12_WIDTH 12 //高,位數 #define GB18030_12X12_HEIGHT 12 //字節數 #define GB18030_12X12_SIZE 24/********************************************************************* * 16*16點陣GB18030漢字 **********************************************************************///字體 #define GB18030_16X16 10 //起始地址 #define GB18030_16X16_ADDR_BASE 0x114FDE //寬,位數 #define GB18030_16X16_WIDTH 16 //高,位數 #define GB18030_16X16_HEIGHT 16 //字節數 #define GB18030_16X16_SIZE 32/********************************************************************* * 24*24點陣GB18030漢字 **********************************************************************///字體 #define GB18030_24X24 11 //起始地址 #define GB18030_24X24_ADDR_BASE 0x1F43DE //寬,位數 #define GB18030_24X24_WIDTH 24 //高,位數 #define GB18030_24X24_HEIGHT 24 //字節數 #define GB18030_24X24_SIZE 72/********************************************************************* * 數據結構 **********************************************************************//********************************************************************* * 字體結構 **********************************************************************/struct _Font_Type {uint8_t type;uint32_t addr_base;uint8_t width;uint8_t height;uint8_t size; };/********************************************************************* * 函數 **********************************************************************//********************************************************************* * 初始化字庫芯片 **********************************************************************/void inf_font_init(void);/********************************************************************* * 讀取字庫 *參數:font:字體 * ch:待讀取的字符 * buf:讀取的數據 *返回:讀取數據的字節數 **********************************************************************/uint8_t inf_font_read(uint8_t font,uint16_t ch,uint8_t *buf);/********************************************************************* * 將ASCII碼轉換成GB18030編碼 *說明:在emwin中調用中文字庫,如果其中有ascii碼,則必須先調用此函數轉換 *參數:dst:輸入字符串 * src:輸出字符串 **********************************************************************/void inf_font_asc2gb18030(char *dst,char *src);#endifinf_font.c
/********************************************************************* * 字庫芯片接口層文件 * (c)copyright 2015,jdh * All Right Reserved *新建日期:2015/2/3 by jdh *修改日期:2015/2/5 by jdh *修改日期:2015/2/6 by jdh **********************************************************************//********************************************************************* * 頭文件 **********************************************************************/#include "inf_font.h" #include "string.h"/********************************************************************* * 宏定義 **********************************************************************//********************************************************************* * 字體數量 **********************************************************************/#define FONT_NUM 5/********************************************************************* * 靜態變量 **********************************************************************//********************************************************************* * 字體結構 **********************************************************************/static struct _Font_Type Font_Type[FONT_NUM];/********************************************************************* * 靜態函數 **********************************************************************//********************************************************************* * 初始化字體類型 **********************************************************************/static void init_font_type(void);/********************************************************************* * 得到地址 *參數:font:字體 * ch:待讀取的字符 *返回:地址 **********************************************************************/static uint32_t get_address(uint8_t font,uint16_t ch);/********************************************************************* * 得到字體地址 *參數:ch1:字符編碼第1個字節 * ch2:字符編碼第2個字節 * ch3:字符編碼第3個字節 * ch4:字符編碼第4個字節 *返回:地址 **********************************************************************/static uint32_t get_address_GB18030_12X12(uint8_t c1,uint8_t c2,uint8_t c3,uint8_t c4);/********************************************************************* * 得到字體地址 *參數:ch1:字符編碼第1個字節 * ch2:字符編碼第2個字節 * ch3:字符編碼第3個字節 * ch4:字符編碼第4個字節 *返回:地址 **********************************************************************/static uint32_t get_address_GB18030_16X16(uint8_t c1,uint8_t c2,uint8_t c3,uint8_t c4);/********************************************************************* * 函數 **********************************************************************//********************************************************************* * 初始化字庫芯片 **********************************************************************/void inf_font_init(void) {//初始化字庫芯片drv_font_init();//初始化字體類型init_font_type(); }/********************************************************************* * 讀取字庫 *參數:font:字體 * ch:待讀取的字符 * buf:讀取的數據 *返回:讀取數據的字節數 **********************************************************************/uint8_t inf_font_read(uint8_t font,uint16_t ch,uint8_t *buf) {uint32_t address = 0;uint8_t i = 0;uint8_t ch1 = ch >> 8;uint8_t ch2 = ch;//開始讀取drv_font_enable();drv_font_send_byte(0x03);//得到地址address = get_address(font,ch);//讀取數據drv_font_send_byte(address >> 16);drv_font_send_byte(address >> 8);drv_font_send_byte(address);for (i = 0;i < Font_Type[font].size;i++){buf[i] = drv_font_send_byte(0);}//關閉讀取drv_font_disable(); }/********************************************************************* * 將ASCII碼轉換成GB18030編碼 *說明:在emwin中調用中文字庫,如果其中有ascii碼,則必須先調用此函數轉換 *參數:dst:輸入字符串 * src:輸出字符串 **********************************************************************/void inf_font_asc2gb18030(char *dst,char *src) {uint8_t len = strlen(src);uint8_t i = 0;uint8_t j = 0;uint16_t temp = 0;for (i = 0;i < len;i++){if ((uint8_t)src[i] < 0x80 && (uint8_t)src[i] != 0){temp = (uint8_t)src[i] + 0xa380;dst[j++] = temp >> 8;dst[j++] = temp;}else{dst[j++] = src[i];}} }/********************************************************************* * 初始化字體類型 **********************************************************************/static void init_font_type(void) {Font_Type[ASCII_7X8].addr_base = ASCII_7X8_ADDR_BASE;Font_Type[ASCII_7X8].width = ASCII_7X8_WIDTH;Font_Type[ASCII_7X8].height = ASCII_7X8_HEIGHT;Font_Type[ASCII_7X8].size = ASCII_7X8_SIZE;Font_Type[ASCII_BOLD_7X8].addr_base = ASCII_BOLD_7X8_ADDR_BASE;Font_Type[ASCII_BOLD_7X8].width = ASCII_BOLD_7X8_WIDTH;Font_Type[ASCII_BOLD_7X8].height = ASCII_BOLD_7X8_HEIGHT;Font_Type[ASCII_BOLD_7X8].size = ASCII_BOLD_7X8_SIZE;Font_Type[ASCII_6X12].addr_base = ASCII_6X12_ADDR_BASE;Font_Type[ASCII_6X12].width = ASCII_6X12_WIDTH;Font_Type[ASCII_6X12].height = ASCII_6X12_HEIGHT;Font_Type[ASCII_6X12].size = ASCII_6X12_SIZE;Font_Type[ASCII_8X16].addr_base = ASCII_8X16_ADDR_BASE;Font_Type[ASCII_8X16].width = ASCII_8X16_WIDTH;Font_Type[ASCII_8X16].height = ASCII_8X16_HEIGHT;Font_Type[ASCII_8X16].size = ASCII_8X16_SIZE;Font_Type[ASCII_BOLD_8X16].addr_base = ASCII_BOLD_8X16_ADDR_BASE;Font_Type[ASCII_BOLD_8X16].width = ASCII_BOLD_8X16_WIDTH;Font_Type[ASCII_BOLD_8X16].height = ASCII_BOLD_8X16_HEIGHT;Font_Type[ASCII_BOLD_8X16].size = ASCII_BOLD_8X16_SIZE;Font_Type[ASCII_12X24].addr_base = ASCII_12X24_ADDR_BASE;Font_Type[ASCII_12X24].width = ASCII_12X24_WIDTH;Font_Type[ASCII_12X24].height = ASCII_12X24_HEIGHT;Font_Type[ASCII_12X24].size = ASCII_12X24_SIZE;Font_Type[ASCII_16X32].addr_base = ASCII_16X32_ADDR_BASE;Font_Type[ASCII_16X32].width = ASCII_16X32_WIDTH;Font_Type[ASCII_16X32].height = ASCII_16X32_HEIGHT;Font_Type[ASCII_16X32].size = ASCII_16X32_SIZE;Font_Type[ASCII_BOLD_16X32].addr_base = ASCII_BOLD_16X32_ADDR_BASE;Font_Type[ASCII_BOLD_16X32].width = ASCII_BOLD_16X32_WIDTH;Font_Type[ASCII_BOLD_16X32].height = ASCII_BOLD_16X32_HEIGHT;Font_Type[ASCII_BOLD_16X32].size = ASCII_BOLD_16X32_SIZE;Font_Type[GB18030_12X12].addr_base = GB18030_12X12_ADDR_BASE;Font_Type[GB18030_12X12].width = GB18030_12X12_WIDTH;Font_Type[GB18030_12X12].height = GB18030_12X12_HEIGHT;Font_Type[GB18030_12X12].size = GB18030_12X12_SIZE;Font_Type[GB18030_16X16].addr_base = GB18030_16X16_ADDR_BASE;Font_Type[GB18030_16X16].width = GB18030_16X16_WIDTH;Font_Type[GB18030_16X16].height = GB18030_16X16_HEIGHT;Font_Type[GB18030_16X16].size = GB18030_16X16_SIZE;Font_Type[GB18030_24X24].addr_base = GB18030_24X24_ADDR_BASE;Font_Type[GB18030_24X24].width = GB18030_24X24_WIDTH;Font_Type[GB18030_24X24].height = GB18030_24X24_HEIGHT;Font_Type[GB18030_24X24].size = GB18030_24X24_SIZE; }/********************************************************************* * 得到地址 *參數:font:字體 * ch:待讀取的字符 *返回:地址 **********************************************************************/static uint32_t get_address(uint8_t font,uint16_t ch) { uint32_t address = 0;uint8_t ch1 = ch >> 8;uint8_t ch2 = ch;switch (font){case ASCII_7X8:case ASCII_BOLD_7X8:case ASCII_6X12:case ASCII_8X16:case ASCII_BOLD_8X16:case ASCII_12X24:case ASCII_16X32:{address = Font_Type[font].addr_base + (ch - 0x20) * Font_Type[font].size;break;}case ASCII_BOLD_16X32:{//芯片bug,弄反了幾個符號的asciido{if (ch == ';'){ch = ':';break;}if (ch == ':'){ch = ';';break;}if (ch == '_'){ch = '^';break;}if (ch == '^'){ch = '_';break;}} while (0);address = Font_Type[font].addr_base + (ch - 0x20) * Font_Type[font].size;break;}case GB18030_12X12:{address = Font_Type[font].addr_base + get_address_GB18030_12X12(ch1,ch2,0,0) * Font_Type[font].size;break;}case GB18030_16X16:case GB18030_24X24:{address = Font_Type[font].addr_base + get_address_GB18030_16X16(ch1,ch2,0,0) * Font_Type[font].size;break;}} }/********************************************************************* * 得到字體地址 *參數:ch1:字符編碼第1個字節 * ch2:字符編碼第2個字節 * ch3:字符編碼第3個字節 * ch4:字符編碼第4個字節 *返回:地址 **********************************************************************/static uint32_t get_address_GB18030_12X12(uint8_t c1,uint8_t c2,uint8_t c3,uint8_t c4) { uint32_t h = 0; if (c2 == 0x7f) {return h; }if (c1 >= 0xA1 && c1 <= 0xa9 && c2 >= 0xa1){//Section 1 h = (c1 - 0xA1) * 94 + (c2 - 0xA1); }else {if (c1 >= 0xa8 && c1 <= 0xa9 && c2 < 0xa1) { //Section 5 if (c2 > 0x7f) { c2--; } h = (c1 - 0xa8) * 96 + (c2 - 0x40) + 846; }} if (c1 >= 0xb0 && c1 <= 0xf7 && c2 >= 0xa1) {//Section 2 h = (c1 - 0xB0) * 94 + (c2 - 0xA1) + 1038; }else {if (c1 < 0xa1 && c1 >= 0x81 && c2 >= 0x40 ) { //Section 3 if (c2 > 0x7f) {c2--; } h = (c1 - 0x81) * 190 + (c2 - 0x40) + 1038 + 6768; } else {if(c1 >= 0xaa && c2 < 0xa1) { //Section 4if (c2 > 0x7f) {c2--; } h = (c1 - 0xaa) * 96 + (c2 - 0x40) + 1038 + 12848; } }}return h; }/********************************************************************* * 得到字體地址 *參數:ch1:字符編碼第1個字節 * ch2:字符編碼第2個字節 * ch3:字符編碼第3個字節 * ch4:字符編碼第4個字節 *返回:地址 **********************************************************************/static uint32_t get_address_GB18030_16X16(uint8_t c1,uint8_t c2,uint8_t c3,uint8_t c4) { uint32_t h = 0; if (c2 == 0x7f) {return h; }if (c1 >= 0xA1 && c1 <= 0xa9 && c2 >= 0xa1){//Section 1 h = (c1 - 0xA1) * 94 + (c2 - 0xA1); }else {if (c1 >= 0xa8 && c1 <= 0xa9 && c2 < 0xa1) { //Section 5 if (c2 > 0x7f) { c2--; } h = (c1 - 0xa8) * 96 + (c2 - 0x40) + 846; }} if (c1 >= 0xb0 && c1 <= 0xf7 && c2 >= 0xa1) {//Section 2 h = (c1 - 0xB0) * 94 + (c2 - 0xA1) + 1038; }else {if (c1 < 0xa1 && c1 >= 0x81 && c2 >= 0x40 ) { //Section 3 if (c2 > 0x7f) {c2--; } h = (c1 - 0x81) * 190 + (c2 - 0x40) + 1038 + 6768; } else {if(c1 >= 0xaa && c2 < 0xa1) { //Section 4if (c2 > 0x7f) {c2--; } h = (c1 - 0xaa) * 96 + (c2 - 0x40) + 1038 + 12848; } else{if(c1 == 0x81 && c2 >= 0x39) { //四字節區1h = 1038 + 21008 + (c3 - 0xEE) * 10 + c4 - 0x39; } else{if(c1 == 0x82){ //四字節區2h = 1038 + 21008 + 161 + (c2 - 0x30) * 1260 + (c3 - 0x81) * 10 + c4 - 0x30; } }}}}return h; }測試代碼:
uint8_t buf[30] = {0};inf_font_read(ASCII_6X12,'b',buf);總結
以上是生活随笔為你收集整理的驱动字库芯片GT23L24M0140的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端工程性能优化
- 下一篇: 火狐firefox扩展插件开发exten