你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【HAL库每天一例】第076例:LCD-显示中文(透明效果)

[复制链接]
haohao663 提问时间:2016-7-28 08:47 /
【HAL库每天一例】系列例程从今天开始持续更新。。。。。
我们将坚持每天至少发布一个基于YS-F1Pro开发板的HAL库例程,
该系列例程将带领大家从零开始使用HAL库,后面会持续添加模块应用例程。
同样的,我们还程序发布基于HAL库的指导文档和视频教程,欢迎持续关注,并提出改进意见。

例程下载:
资料包括程序、相关说明资料以及软件使用截图
百度云链接:https://pan.baidu.com/s/1i574oPv
密码:r3s3

(硬石YS-F1Pro开发板HAL库例程持续更新\2. 软件设计之高级裸机例程(HAL库版本)\YSF1_HAL-110. LCD-显示中文(透明效果)

/**
  ******************************************************************************
  *                           硬石YS-F1Pro开发板例程功能说明
  *
  *  例程名称: YSF1_HAL-110. LCD-显示中文(透明效果)
  *   
  ******************************************************************************
  * 说明:
  * 本例程配套硬石stm32开发板YS-F1Pro使用。
  *
  * 淘宝:
  * 论坛:硬石电子社区
  * 版权归硬石嵌入式开发团队所有,请勿商用。
  ******************************************************************************
  */

【1】例程简介
  FSMC:可变静态存储控制器,是STM32系列采用的一种新型的存储器扩展技术。一般可以用FSMC
接口与液晶驱动IC连接,实现数据交换。YS-F1Pro预留16bit的FSMC液晶接口,我们同时提供了
3.5寸TFT液晶模组供选购,该模组的液晶驱动IC型号为ILI9488。
  本例程实现液晶模组显示24bit的bmp格式图片。
  
【2】跳线帽情况
******* 为保证例程正常运行,必须插入以下跳线帽 **********
丝印编号     IO端口      目标功能引脚        出厂默认设置
  JP1        PA10        TXD(CH340G)          已接入
  JP2        PA9         RXD(CH340G)          已接入
  
【3】操作及现象
将例程目录下的图片文件拷贝到SD卡中,并把SD卡插入到开发板上,把3.5寸TFT液晶模组插入开发
板中间液晶接口上,使用开发板配套的MINI USB线连接到开发板标示“调试串口”字样的MIMI USB
接口(需要安装驱动),在电脑端打开串口调试助手工具,设置参数为115200 8-N-1。下载完程序
之后,在串口调试助手窗口可接收到液晶模组ID信息,同时液晶屏幕亮起来,显示图片和一些文字,
部分文字是通透效果的。

/******************* (C) COPYRIGHT 2015-2020 硬石嵌入式开发团队 *****END OF FILE****/


bsp_lcd.c部分函数

  1. /**
  2.   * 函数功能: 在 LCD 显示器上显示一个英文字符
  3.   * 输入参数: usX:在特定扫描方向下字符的起始X坐标
  4.   *           usY :在特定扫描方向下该点的起始Y坐标
  5.   *           cChar :要显示的英文字符
  6.   *           usColor_Background :选择英文字符的背景色
  7.   *           usColor_Foreground :选择英文字符的前景色
  8.   *           font:字体选择
  9.   *           可选值:FONT_16 :16号字体
  10.   *                   FONT_24 :24号字体
  11.   * 返 回 值: 无
  12.   * 说    明:该函数必须与ascii.h内容对应使用
  13.   */
  14. void LCD_DispChar_EN_Transparent(uint16_t usX,uint16_t usY,const char cChar,
  15.                                  uint16_t usColor_Background,uint16_t usColor_Foreground,
  16.                                  uint8_t transparent,USB_FONT_Typdef font)
  17. {
  18.         uint8_t ucTemp, ucRelativePositon, ucPage, ucColumn;
  19.   uint16_t i,j;
  20.   
  21.   /* 检查输入参数是否合法 */
  22.   assert_param(IS_FONT(font));
  23.   
  24.         ucRelativePositon = cChar - ' ';
  25.   
  26.         if(font==USB_FONT_16)
  27.   {
  28.     for(j=0;j<16;++j)
  29.     {
  30.       for(i=0;i<8;++i)
  31.       {
  32.         LCD_SetCursor(usX+i,usY+j);        
  33.         bk_color[8*j+i]=LCD_Read_PixelData();
  34.       }
  35.     }
  36.     LCD_OpenWindow(usX,usY,8,16);
  37.     LCD_WRITE_CMD(0x2C);
  38.    
  39.     for(i=0,ucPage=0;ucPage<16;ucPage++)
  40.     {
  41.       ucTemp=ucAscii_1608[ucRelativePositon][ucPage];               
  42.       for(ucColumn=0;ucColumn<8;ucColumn++)
  43.       {
  44.         if(ucTemp&0x01)
  45.           LCD_WRITE_DATA(usColor_Foreground);                        
  46.         else if(transparent)
  47.           LCD_WRITE_DATA(bk_color[i]);        
  48.         else            
  49.           LCD_WRITE_DATA(usColor_Background);                                       
  50.         ++i;        
  51.         ucTemp >>= 1;                                       
  52.       }
  53.     }   
  54.   }
  55.   else
  56.   {
  57.     for(j=0;j<24;++j)
  58.     {
  59.       for(i=0;i<12;++i)
  60.       {
  61.         LCD_SetCursor(usX+i,usY+j);        
  62.         bk_color[12*j+i]=LCD_Read_PixelData();
  63.       }
  64.     }
  65.     LCD_OpenWindow(usX,usY,12,24);
  66.     LCD_WRITE_CMD(0x2C);
  67.    
  68.     for(i=0,ucPage=0;ucPage<48;ucPage++)
  69.     {
  70.       ucTemp=ucAscii_2412[ucRelativePositon][ucPage];               
  71.       for(ucColumn=0;ucColumn<8;ucColumn++)
  72.       {
  73.         if(ucTemp&0x01)
  74.           LCD_WRITE_DATA(usColor_Foreground);        
  75.         else if(transparent)
  76.           LCD_WRITE_DATA(bk_color[i]);               
  77.         else
  78.           LCD_WRITE_DATA(usColor_Background);               
  79.         ++i;        
  80.         ucTemp >>= 1;                                       
  81.       }        
  82.       ucPage++;
  83.       ucTemp=ucAscii_2412[ucRelativePositon][ucPage];
  84.       /* 只显示前面4个位,与前面8位总共12位 */
  85.       for(ucColumn=0;ucColumn<4;ucColumn++)
  86.       {
  87.         if(ucTemp&0x01)
  88.           LCD_WRITE_DATA(usColor_Foreground);               
  89.         else if(transparent)
  90.           LCD_WRITE_DATA(bk_color[i]);               
  91.         else         
  92.           LCD_WRITE_DATA(usColor_Background);        
  93.         ++i;        
  94.         ucTemp >>= 1;                                       
  95.       }        
  96.     }
  97.   }        
  98. }

  99. /**
  100.   * 函数功能: 在 LCD 显示器上显示英文字符串
  101.   * 输入参数: usX:在特定扫描方向下字符的起始X坐标
  102.   *           usY :在特定扫描方向下该点的起始Y坐标
  103.   *           pStr :要显示的英文字符串的首地址
  104.   *           usColor_Background :选择英文字符的背景色
  105.   *           usColor_Foreground :选择英文字符的前景色
  106.   *           font:字体选择
  107.   *           可选值:FONT_16 :16号字体
  108.   *                   FONT_24 :24号字体
  109.   * 返 回 值: 无
  110.   * 说    明:该函数必须与ascii.h内容对应使用
  111.   */
  112. void LCD_DispString_EN_Transparent(uint16_t usX,uint16_t usY,const char * pstr,
  113.                                    uint16_t usColor_Background, uint16_t usColor_Foreground,
  114.                                    uint8_t transparent,USB_FONT_Typdef font)
  115. {
  116.   /* 检查输入参数是否合法 */
  117.   assert_param(IS_FONT(font));
  118.   
  119.         while(*pstr != '\0')
  120.         {
  121.     if(font==USB_FONT_16)
  122.     {
  123.       if((usX+8)>LCD_DEFAULT_WIDTH)
  124.       {
  125.         usX = 0;
  126.         usY += 16;
  127.       }      
  128.       if((usY+16)>LCD_DEFAULT_HEIGTH)
  129.       {
  130.         usX=0;
  131.         usY=0;
  132.       }      
  133.       LCD_DispChar_EN_Transparent(usX,usY,*pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_16);
  134.       pstr++;      
  135.       usX+=8;
  136.     }
  137.     else
  138.     {
  139.       if((usX+12)>LCD_DEFAULT_WIDTH)
  140.       {
  141.         usX=0;
  142.         usY+=24;
  143.       }      
  144.       if((usY+24)>LCD_DEFAULT_HEIGTH)
  145.       {
  146.         usX=0;
  147.         usY=0;
  148.       }      
  149.       LCD_DispChar_EN_Transparent(usX,usY,*pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_24);
  150.       pstr++;      
  151.       usX+=12;
  152.     }
  153.         }
  154. }

  155. /**
  156.   * 函数功能: 在 LCD 显示器上显示一个中文
  157.   * 输入参数: usX:在特定扫描方向下字符的起始X坐标
  158.   *           usY :在特定扫描方向下该点的起始Y坐标
  159.   *           pstr: 汉字字符低字节码
  160.   *           usColor_Background :选择英文字符的背景色
  161.   *           usColor_Foreground :选择英文字符的前景色
  162.   *           font:字体选择
  163.   *           可选值:FONT_16 :16号字体
  164.   *                   FONT_24 :24号字体
  165.   * 返 回 值: 无
  166.   * 说    明:无
  167.   */
  168. void LCD_Disp_CH_Transparent(uint16_t usX,uint16_t usY,const uint8_t *pstr,
  169.                              uint16_t usColor_Background, uint16_t usColor_Foreground,
  170.                              uint8_t transparent,USB_FONT_Typdef font)
  171. {
  172.         uint8_t ucTemp, ucPage, ucColumn;
  173.   uint8_t gbk_buffer[72];
  174.   uint16_t i,j;
  175.   
  176.   /* 检查输入参数是否合法 */
  177.   assert_param(IS_FONT(font));
  178.   
  179.         if(font==USB_FONT_16)
  180.   {
  181.     for(j=0;j<16;++j)
  182.     {
  183.       for(i=0;i<16;++i)
  184.       {
  185.         LCD_SetCursor(usX+i,usY+j);        
  186.         bk_color[16*j+i]=LCD_Read_PixelData();
  187.       }
  188.     }
  189.    
  190.     LCD_OpenWindow(usX,usY,16,16);
  191.     LCD_WRITE_CMD(0x2C);
  192. #if USB_SPIFLASH_CH==1
  193.     GetGBKCode_SPIFLASH(gbk_buffer,pstr,USB_FONT_16);
  194. #else
  195.     GetGBKCode_SD(gbk_buffer,pstr,FONT_16);
  196. #endif
  197.     for(i=0,ucPage=0;ucPage<32;ucPage++)
  198.     {
  199.       ucTemp=gbk_buffer[ucPage];               
  200.       for(ucColumn=0;ucColumn<8;ucColumn++)
  201.       {
  202.         if(ucTemp&0x01)
  203.           LCD_WRITE_DATA(usColor_Foreground);               
  204.         else if(transparent)
  205.           LCD_WRITE_DATA(bk_color[i]);        
  206.         else
  207.           LCD_WRITE_DATA(usColor_Background);        
  208.         ++i;        
  209.         ucTemp >>= 1;                                       
  210.       }
  211.     }   
  212.   }
  213.   else
  214.   {
  215.     for(j=0;j<24;++j)
  216.     {
  217.       for(i=0;i<24;++i)
  218.       {
  219.         LCD_SetCursor(usX+i,usY+j);        
  220.         bk_color[24*j+i]=LCD_Read_PixelData();
  221.       }
  222.     }
  223.    
  224.     LCD_OpenWindow(usX,usY,24,24);
  225.     LCD_WRITE_CMD(0x2C);
  226. #if USB_SPIFLASH_CH==1
  227.     GetGBKCode_SPIFLASH(gbk_buffer,pstr,USB_FONT_24);
  228. #else
  229.     GetGBKCode_SD(gbk_buffer,pstr,FONT_24);
  230. #endif   
  231.    
  232.     for(i=0,ucPage=0;ucPage<72;ucPage++)
  233.     {
  234.       ucTemp=gbk_buffer[ucPage];               
  235.       for(ucColumn=0;ucColumn<8;ucColumn++)
  236.       {
  237.         if(ucTemp&0x01)
  238.           LCD_WRITE_DATA(usColor_Foreground);        
  239.         else if(transparent)
  240.           LCD_WRITE_DATA(bk_color[i]);        
  241.         else
  242.           LCD_WRITE_DATA(usColor_Background);                                                               
  243.         ++i;
  244.         ucTemp >>= 1;                                       
  245.       }
  246.     }
  247.   }        
  248. }

  249. /**
  250.   * 函数功能: 在 LCD 显示器上显示一串中文
  251.   * 输入参数: usX:在特定扫描方向下字符的起始X坐标
  252.   *           usY :在特定扫描方向下该点的起始Y坐标
  253.   *           pstr: 汉字字符低字节码
  254.   *           usColor_Background :选择英文字符的背景色
  255.   *           usColor_Foreground :选择英文字符的前景色
  256.   *           font:字体选择
  257.   *           可选值:FONT_16 :16号字体
  258.   *                   FONT_24 :24号字体
  259.   * 返 回 值: 无
  260.   * 说    明:无
  261.   */
  262. void LCD_DispString_CH_Transparent(uint16_t usX,uint16_t usY,const uint8_t *pstr,
  263.                                    uint16_t usColor_Background, uint16_t usColor_Foreground,
  264.                                    uint8_t transparent,USB_FONT_Typdef font)
  265. {
  266.   /* 检查输入参数是否合法 */
  267.   assert_param(IS_FONT(font));
  268.   
  269.   while(*pstr != '\0')
  270.         {
  271.     if(font==USB_FONT_16)
  272.     {
  273.       if((usX+16)>LCD_DEFAULT_WIDTH)
  274.       {
  275.         usX = 0;
  276.         usY += 16;
  277.       }      
  278.       if((usY+16)>LCD_DEFAULT_HEIGTH)
  279.       {
  280.         usX=0;
  281.         usY=0;
  282.       }      
  283.       LCD_Disp_CH_Transparent(usX,usY,pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_16);
  284.       pstr+=2;      
  285.       usX+=16;
  286.     }
  287.     else
  288.     {
  289.       if((usX+24)>LCD_DEFAULT_WIDTH)
  290.       {
  291.         usX = 0;
  292.         usY += 24;
  293.       }      
  294.       if((usY+24)>LCD_DEFAULT_HEIGTH)
  295.       {
  296.         usX=0;
  297.         usY=0;
  298.       }      
  299.       LCD_Disp_CH_Transparent(usX,usY,pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_24);
  300.       pstr+=2;      
  301.       usX+=24;
  302.     }
  303.         }  
  304. }

  305. /**
  306.   * 函数功能: 在 LCD 显示器上显示一串中英文
  307.   * 输入参数: usX:在特定扫描方向下字符的起始X坐标
  308.   *           usY :在特定扫描方向下该点的起始Y坐标
  309.   *           pstr: 汉字字符低字节码
  310.   *           usColor_Background :选择英文字符的背景色
  311.   *           usColor_Foreground :选择英文字符的前景色
  312.   *           font:字体选择
  313.   *           可选值:FONT_16 :16号字体
  314.   *                   FONT_24 :24号字体
  315.   * 返 回 值: 无
  316.   * 说    明:无
  317.   */
  318. void LCD_DispString_EN_CH_Transparent(uint16_t usX,uint16_t usY,const uint8_t *pstr,
  319.                                       uint16_t usColor_Background, uint16_t usColor_Foreground,
  320.                                       uint8_t transparent,USB_FONT_Typdef font)
  321. {
  322.   /* 检查输入参数是否合法 */
  323.   assert_param(IS_FONT(font));
  324.   
  325.   while(*pstr != '\0')
  326.         {
  327.     if(*pstr<=0x7f)
  328.     {
  329.       if(font==USB_FONT_16)
  330.       {
  331.         if((usX+8)>LCD_DEFAULT_WIDTH)
  332.         {
  333.           usX = 0;
  334.           usY += 16;
  335.         }      
  336.         if((usY+16)>LCD_DEFAULT_HEIGTH)
  337.         {
  338.           usX=0;
  339.           usY=0;
  340.         }      
  341.         LCD_DispChar_EN_Transparent(usX,usY,*pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_16);
  342.         pstr++;      
  343.         usX+=8;
  344.       }
  345.       else
  346.       {
  347.         if((usX+12)>LCD_DEFAULT_WIDTH)
  348.         {
  349.           usX=0;
  350.           usY+=24;
  351.         }      
  352.         if((usY+24)>LCD_DEFAULT_HEIGTH)
  353.         {
  354.           usX=0;
  355.           usY=0;
  356.         }      
  357.         LCD_DispChar_EN_Transparent(usX,usY,*pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_24);
  358.         pstr++;      
  359.         usX+=12;
  360.       }
  361.     }
  362.     else
  363.     {
  364.       if(font==USB_FONT_16)
  365.       {
  366.         if((usX+16)>LCD_DEFAULT_WIDTH)
  367.         {
  368.           usX = 0;
  369.           usY += 16;
  370.         }      
  371.         if((usY+16)>LCD_DEFAULT_HEIGTH)
  372.         {
  373.           usX=0;
  374.           usY=0;
  375.         }      
  376.         LCD_Disp_CH_Transparent(usX,usY,pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_16);
  377.         pstr+=2;      
  378.         usX+=16;
  379.       }
  380.       else
  381.       {
  382.         if((usX+24)>LCD_DEFAULT_WIDTH)
  383.         {
  384.           usX = 0;
  385.           usY += 24;
  386.         }      
  387.         if((usY+24)>LCD_DEFAULT_HEIGTH)
  388.         {
  389.           usX=0;
  390.           usY=0;
  391.         }      
  392.         LCD_Disp_CH_Transparent(usX,usY,pstr,usColor_Background,usColor_Foreground,transparent,USB_FONT_24);
  393.         pstr+=2;      
  394.         usX+=24;
  395.       }
  396.     }
  397.         }  
  398. }
复制代码



收藏 评论4 发布时间:2016-7-28 08:47

举报

4个回答
stary666 回答时间:2016-7-31 11:00:32
立志311 回答时间:2016-8-2 17:16:16
谢谢楼主分享!
edmundlee 回答时间:2019-6-13 14:20:36
楼主, 连接失效了, 能不能重发一个?
唐英tcy 回答时间:2019-6-14 08:26:17
谢谢楼主分享!

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版