C语言没学好伤不起,终于用LZ的函数显示粗来啦~
- #include
- #include "HAL_Dogs102x6.h"
- // ------------------ 汉字字模的数据结构定义 ------------------------ //
- typedef struct typFNT_GB12 // 汉字字模数据结构
- {
- char Index[2]; // 汉字内码索引
- uint8_t Msk[24]; // 点阵码数据
- } GB12;
- // 汉字字模表
- // 汉字库: 宋体12.dot 纵向取模上高位,数据排列:从左到右从上到下
- const struct typFNT_GB12 GB_12[] = // 数据表
- {
- "我", 0x11,0x51,0x52,0xFF,0x92,0x10,0x10,0xFF,0x11,0x52,0x34,0x10,
- 0x00,0x20,0x10,0xF0,0x00,0x20,0x40,0x80,0x40,0x20,0x10,0x70,
- "爱", 0x02,0x4C,0x6A,0x5A,0x4B,0x6E,0x5A,0x8A,0x9B,0xAA,0x0E,0x0A,
- 0x10,0x20,0x50,0x90,0x20,0xA0,0x40,0xA0,0x20,0x10,0x10,0x10,
- "电", 0x00,0x3F,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x7F,0x20,0x00,
- 0x00,0x80,0x80,0x80,0x80,0xE0,0x90,0x90,0x90,0x90,0x10,0x70,
- "子", 0x00,0x04,0x84,0x84,0x84,0x84,0x9F,0xA4,0xC4,0x84,0x0C,0x04,
- 0x00,0x00,0x00,0x20,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,
- "工", 0x00,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0xC0,0x40,0x00,
- 0x20,0x20,0x20,0x20,0x20,0xE0,0x20,0x20,0x20,0x20,0x60,0x20,
- "程", 0x51,0x56,0x7F,0x92,0x91,0x04,0xF4,0x94,0x97,0x94,0xF4,0x04,
- 0x80,0x00,0xF0,0x00,0x10,0x10,0x90,0x90,0xF0,0x90,0xB0,0x10,
- "世", 0x08,0x08,0x7F,0x08,0x08,0xFF,0x08,0x08,0x08,0xFF,0x08,0x08,
- 0x00,0x00,0xF0,0x10,0x10,0xD0,0x90,0x90,0x90,0xD0,0x10,0x10,
- "界", 0x00,0x00,0xF9,0xA9,0xAB,0xFC,0xAA,0xAA,0xA9,0xF9,0x01,0x01,
- 0x80,0x90,0x10,0x20,0xC0,0x00,0x00,0xF0,0x00,0x00,0x80,0x00
- };
- // 汉字表:
- // 电子工程世界
- #define GB_12_num sizeof(GB_12) / 26 //汉字个数
- /*******************************************************************************
- *函数名称:Dogs102x6_Font8x12DrawXY(x, y, f, style)
- *功能描述:Dogs102x6液晶上显示12x12字体
- *参数说明:x-坐标(0 - 101),y-坐标(0 - 63) 注意:当y>52时,字体都显示在液晶的最下面一行
- *参数说明:p_f-字符指针,style-(0-正常显示,1-反白显示);无返回参数.
- ******************************************************************************/
- void Dogs102x6_Font12x12DrawXY(uint8_t x, uint8_t y, const uint8_t *p_f, uint8_t style)
- {
- uint8_t b, row;
- uint8_t desired_char[36];
- // make sure we won't be writing off the screen
- if (x >= 102)
- {
- x = 101;
- }
- if (y >= 53)//字体是12x12,(63-52)+1=12
- {
- y = 52;
- }
- // Check if there is a remainder
- row = y >> 3; // identical to: row = y / 8;
- if (style == DOGS102x6_DRAW_NORMAL)
- {
- for (b = 0; b < 12; b++)
- {
- desired_char[b] =
- (*(p_f + b) >> (y % 8)) | dogs102x6Memory[2 + (row * 102) + x + b];//
- desired_char[b + 12] =
- *(p_f + b) << (8 - y % 8) | (*(p_f + 12 + b) >> (y % 8)) | dogs102x6Memory[2 + ((row + 1) * 102) + x + b];
- if((y % 8) > 4)
- {
- desired_char[b + 24] = *(p_f + 12 + b) << (8 - y % 8) | dogs102x6Memory[2 + ((row + 2) * 102) + x + b];
- }
- }
- }
- else
- {
- for (b = 0; b < 12; b++)
- {
- desired_char[b] =
- (*(p_f + b) ^ 0xFF) >> (y % 8) | dogs102x6Memory[2 + (row * 102) + x + b];
- desired_char[b + 12] =
- (*(p_f + b) ^ 0xFF) << (8 - y % 8) | (*(p_f + 12 + b) ^ 0xF0) >> (y % 8) | dogs102x6Memory[2 + ((row + 1) * 102) + x + b];
- if((y & 0x07) > 4)
- {
- desired_char[b + 24] =
- ((*(p_f + 12 + b) ^ 0xF0) << (8 - y % 8)) | dogs102x6Memory[2 + ((row + 2) * 102) + x + b];
- }
- }
- }
- Dogs102x6_setAddress(row, x);
- Dogs102x6_writeData(desired_char, 12);
- Dogs102x6_setAddress(row + 1, x);
- Dogs102x6_writeData(desired_char + 12, 12);
- if((y % 8) > 4)
- {
- Dogs102x6_setAddress(row + 2, x);
- Dogs102x6_writeData(desired_char + 24, 12);
- }
- }
- /*******************************************************************************
- *函数名称:Dogs102x6_chinesecharDrawXY(x, y, cchar, style)
- *功能描述:Dogs102x6液晶上显示汉字体
- *参数说明:x-坐标(0 - 101),y-坐标(0 - 63)
- *参数说明:cchar-汉字符指针,style-(0-正常显示,1-反白显示);无返回参数.
- ******************************************************************************/
- void Dogs102x6_chinesecharDrawXY(uint8_t x, uint8_t y, char *cchar, uint8_t style)
- {
- uint8_t k;
- for (k = 0; k < GB_12_num; k ++) //GB_12_num - (sizeof(GB_12) / 26)
- {
- if ((GB_12[k].Index[0] == *cchar) && (GB_12[k].Index[1] == *(cchar + 1)))
- {
- Dogs102x6_Font12x12DrawXY(x, y, GB_12[k].Msk, style);
- }
- }
- }
- /*******************************************************************************
- *函数名称:Dogs102x6_chinesefontsDrawXY(x, y, word, style)
- *功能描述:Dogs102x6液晶上连续显示汉字体(每行少于9个)
- *参数说明:x-坐标(0 - 101),y-坐标(0 - 63)
- *参数说明:word-汉字符指针,style-(0-正常显示,1-反白显示);无返回参数.
- ******************************************************************************/
- void Dogs102x6_chinesefontsDrawXY(uint8_t x, uint8_t y, char *word, uint8_t style)
- {
- while (*word != '\0')
- {
- // Draw a character
- Dogs102x6_chinesecharDrawXY(x, y, word, style);
- // Update location
- x += 12;
- // Text wrapping
- if (x >= 96)
- {
- x = 0;
- if (y + 12 < 64)
- y += 12;
- else
- y = 0;
- }
- word += 2;
- }
- }
- int main(void)
- {
- WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
- Dogs102x6_init(); //初始化LCD
- Dogs102x6_clearScreen(); //清屏
- Dogs102x6_setContrast(11); //设置初始对比度值
- char str[] = {"我爱电子工程世界我爱电子工程世界我爱电子工程世界我爱电子工程世界我爱电子工程世界"};
- Dogs102x6_chinesefontsDrawXY(0, 0, &str[0], 1);
- }
复制代码 |