STM32学习笔记(五)LCD函数

//x,y :起点坐标  
//len :小数点后的位数
//size:字体大小,此处省略,默认1608字体
//color:颜色,此处仅保留前景色,可自行修改
//num:数值(0~4294967295); 
 

void LCD_ShowNum(u16 x,u16 y,float num,u8 len,u16 color)


[html]  view plain  copy
  1. #include "led.h"  
  2. #include "delay.h"  
  3. #include "sys.h"  
  4. #include "usart.h"  
  5. #include "lcd.h"  
  6. void init()  
  7. {  
  8.     delay_init();            //延时函数初始化      
  9.     uart_init(9600);     //串口初始化为9600  
  10.     LED_Init();      //初始化与LED连接的硬件接口  
  11.     LCD_Init();  
  12.     POINT_COLOR=BLACK;       //定义画笔颜色  
  13.     LCD_Clear(RED);  
  14. }  
  15.  int main(void)  
  16.  {   
  17.     u8 x=0,i;  
  18.     u16 ty;   
  19.     init();  
  20.     LCD_ShowString(30,40,200,24,24,"My first TFT ^_^");   
  21.     ty=70;  
  22.     for(i=1;i<=10;i++,ty+=20)  
  23.     {  
  24.         LCD_ShowString(20,ty,200,12,12,"the deep you love,the more you get");  
  25.     }  
  26.   while(1)   
  27.     {;}   
  28. }  

注意到初始化那,因为LCD初始化的时候有用到printf,所以一定要初始化串口,不然会死机TAT

对于POINT_COLOR,顾名思义,而且也可以在库中找到定义,就是定义画笔颜色(相当于字体的颜色)

[html]  view plain  copy
  1. u16 POINT_COLOR=0x0000; //画笔颜色  
  2. u16 BACK_COLOR=0xFFFF;  //背景色  
我们定义为BLACK(黑色),也可以修改为别的颜色(对应相应的大写英文)
LCD_Clear(color);  这个函数是清屏+填充颜色 (颜色同上)

LCD_ShowString()函数:

[html]  view plain  copy
  1. //显示字符串  
  2. //x,y:起点坐标  
  3. //width,height:区域大小    
  4. //size:字体大小  
  5. //*p:字符串起始地址            
  6. void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)  

字体大小有3种选择,12 ,16,24 前两个参数好填,x,y就是起始坐标,而区域大小填 (200,字体大小(3种选择))最后一个参数应该很好理解就不多说了

最后我们令 while(1);卡住程序以显示静止的画面


颜色库

[html]  view plain  copy
  1. //画笔颜色  
  2. #define WHITE            0xFFFF  
  3. #define BLACK            0x0000     
  4. #define BLUE             0x001F    
  5. #define BRED             0XF81F  
  6. #define GRED             0XFFE0  
  7. #define GBLUE            0X07FF  
  8. #define RED              0xF800  
  9. #define MAGENTA          0xF81F  
  10. #define GREEN            0x07E0  
  11. #define CYAN             0x7FFF  
  12. #define YELLOW           0xFFE0  
  13. #define BROWN            0XBC40 //棕色  
  14. #define BRRED            0XFC07 //棕红色  
  15. #define GRAY             0X8430 //灰色  


下面是一些画图函数


快速画点

[html]  view plain  copy
  1. //快速画点  
  2. //x,y:坐标  
  3. //color:颜色  
  4. void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color)  

画线

[html]  view plain  copy
  1. //画线  
  2. //x1,y1:起点坐标  
  3. //x2,y2:终点坐标    
  4. void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)  
画矩形,给出矩形对角线上的两个端点坐标即可。

[html]  view plain  copy
  1. //画矩形  
  2. void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)  

画圆

[html]  view plain  copy
  1. //在指定位置画一个指定大小的圆  
  2. //(x,y):中心点  
  3. //r    :半径  
  4. void LCD_Draw_Circle(u16 x0,u16 y0,u8 r)  

在指定区域填充单一颜色(只能是指定矩形区域)而且给的的坐标只能是 sx<=ex && sy<=ey

[html]  view plain  copy
  1. //在指定区域内填充指定颜色  
  2. //区域大小:(xend-xsta+1)*(yend-ysta+1)  
  3. //xsta  
  4. //color:要填充的颜色  
  5. void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color)  

在指定区域填充颜色块,同上,只不过颜色要放到数组里面传过去

[html]  view plain  copy
  1. //在指定区域内填充指定颜色块            
  2. //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)     
  3. //color:要填充的颜色  
  4. void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color)  



还有一些好玩的函数


横屏显示

[html]  view plain  copy
  1. //设置LCD显示方向  
  2. //dir:0,竖屏;1,横屏  
  3. void LCD_Display_Dir(u8 dir)  

开启/关闭显示

[html]  view plain  copy
  1. //LCD开启显示  
  2. void LCD_DisplayOn(void)  
  3. //LCD关闭显示  
  4. void LCD_DisplayOff(void)  


  • 32
    点赞
  • 129
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值