STM32基于9325TP液晶驱动器的驱动程序_第1页
STM32基于9325TP液晶驱动器的驱动程序_第2页
STM32基于9325TP液晶驱动器的驱动程序_第3页
STM32基于9325TP液晶驱动器的驱动程序_第4页
STM32基于9325TP液晶驱动器的驱动程序_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、9325tp驱动器tft驱动程序7#ifndef _9325tp_h#define _9325tp_h#include kstm32f10xib.h”/* lcd color */#define whiteoxffff#define black0x0000#define blue0x001f#define blue20x051f#define red0xf800#define magenta0xf81#define green0x07e0#define cyan0x7fff#define yellowoxffeor lcd command */#define window_xaddr_star

2、t 0x50 / horizontal start address set #define window_xaddr_end 0x51 / horizontal end address set #define window_yaddr_start 0x52 / vertical start address set #define window_yaddr_end 0x53 / vertical end address set #define gram_xaddr 0x20 / gram horizontal address set#define gram yaddr 0x21 / gram v

3、ertical address set#define gramwr 0x22 / memory write /* lcd control port */#define lcd_control_port gpiodgpio_pin_10gpio_pin_11gpio_pin_12gpio_pin_13gpio_pin_14#define cs_lcd #define rs_lcd#define rw_lcd#define rd lcd#define rst_lcd#define lcd_control_pin cs_lcd | rs_lcd | rw_lcd | rd_lcd | rst_lcd

4、 r lcd data port 7#define lcd_data_port gpioe#define rst_lcd_set#define rst_lcd_clrgpio_setbits(lcd_control_port ,rst_lcd)gpio_resetbits(lcd_control_port,rst_lcd)#define cs_lcd_set#define cs_lcd_clrgpio_setbits(lcd_control_port ,cs_lcd)gpio_resetbits(lcd_control_port ,cs_lcd)#define rs_lcd_set#defin

5、e rs_lcd_clrgpio_setbits(lcd_control_port,rs_lcd)gpio_resetbits(lcd_control_port ,rs_lcd)#define rw_lcd_set #define rw_lcd_clrgpio_setbits(lcd_control_port ,rw_lcd)gpio_resetbits(lcd_control_port,rw_lcd)#define rd_lcd_set #define rd_lcd_clrgpio_setbits(lcd_control_port ,rd_lcd)gpio_resetbits(lcd_con

6、trol_port,rd_lcd)/* line direction */#define vertical 0x00#define horizontal 0x01 extern void lnit_lcd_9325tp(void);extern void write_lcd_cmd(unsigned int data_h ,unsigned int data_l);extern void write_lcd_data(unsigned int data_h ,unsigned int data_l);extern void write_lcd_data_u16(unsigned int dat

7、);extern void init_lcd_data(unsigned int x,unsigned int y);extern void clear_screen(unsigned int back_color); 用指定的颜色刷屏extern void lcd_setpos(unsigned int xo,unsigned int x1,unsigned int yo,unsigned int yl); 设定起始坐标extern void lcd_putchar8x16(unsigned int x, unsigned int y, unsigned char c, unsigned i

8、nt for_color, unsigned int back_color); 显示一个 8x16 的 字符extern void lcd_putgb1616(unsigned int x, unsigned int y, unsigned char c2, unsigned int for_color,unsigned int back_color); 显示一个 16x16 的 汉字extern void lcd_putgb3232(unsigned int x, unsigned int y, unsigned char c2, unsigned int for_color,unsigne

9、d int back_color); 显示一个 32x32 的 汉字extern void lcd_putstring(unsigned int x, unsigned int y, unsigned char *s,unsigned int for_color, unsigned int back_color); 显示一串 16x16 的 字符串extern void lcd_putgb1616_string(unsigned int x 山nsigned int y ,unsigned char *s , unsigned int for_color unsigned int back_c

10、olor); 显示一串16x16的汉字extern void lcd_drawline(unsigned short x unsigned short y ,unsigned short length , unsigned char direction unsigned int color); 画一条直线extern void lcd_drawrect(unsigned short x ,unsigned short y ,unsigned short width 、 unsigned short height,unsigned int color); 画一个矩形void lcd_drawci

11、rcle(unsigned short xpos ,unsigned short ypos unsigned short radius , unsigned int color); 画一个圆extern void show_photo(unsigned int xo unsigned int yo ,unsigned int x unsigned int y ,const unsigned char *p); 显示一张图片extern void u32tostr(unsigned long dat,unsigned char *str); 将整型转换为字符串#endif /* 9325tp_h

12、 7/=/ /=9325tp.c=/#include "stm32f10x_lib.hminclude ”systick_delay.h”include n9325tp.hhinclude "gb1616.h”include hgb3232.hm#include ”8x16.h”i* *农*农* 函数名称:write_lcd_cmd功能:向lcd写入命令参数:data_h16位数据的高八位data_l16位数据的低八位返回值:无 * / void write_lcd_cmd(unsigned int data_h unsigned int data_l) cs_lcd_cl

13、r ;/使能片选信号rs_lcd_clr ;命令模式gpio_write(lcd_data_port ,data_h); 高八位 rw_lcd_clr ;/写使能rw_lcd_set ;关闭写使能gpio_write(lcd_data_port,data_l);rw_lcd_clr ;写使能rw_lcd_set ;关闭写使能cs_lcd_set ;结束片选信号/* 函数名称:write_lcd_data功能:向lcd写入数据参数:data_h16位数据的高八位data_l -16位数据的低八位返回值:无void write_lcd_data(unsigned int data_h unsign

14、ed int data_l) cs_lcd_clr ;/使能片选信号rs_lcd_set ;数据模式gpio_write(lcd_data_port ,data_h); 高八位rw_lcd_clr ;/写使能rw_lcd_set ;关闭写使能gpio_write(lcd_data_port,data_l); 低八位rw_lcd_clr ;/写使能rw_lcd_set ; 关闭写使能cs_lcd_set ; 结束片选信号/*函数名称:write_lcd_data_u16功能:向lcd写入16位的数据参数:dat要写入的数据返回值:无*/void write_lcd_data_u16(unsign

15、ed int dat)cs_lcd_clr ;/使能片选信号rs_lcd_set ;数据模式gpio_write(lcd_data_port ,dat»8); 高八位 /gpioe->odr = dat»8 ;rw_lcd_clr ;写使能rw_lcd_set ;关闭写使能gpio_write(lcd_data_port ,dat) ; /低八位 /gpioe->odr = dat;rw_lcd_clr ; 写使能rw_lcd_set ; 关闭写使能cs_lcd_set ; 结束片选信号函数名称:lnit_lcd_data功 能:初始化lcd写入方法参 数:x要

16、使用的命令代码y 要使用的数据代码返回值:无void init_lcd_data(unsigned int x ,unsigned int y)write_lcd_cmd(0x0000,x);write_lcd_data_u16(y);函数名称:lcd_setpos功能:定义显示窗体参数:xo窗体中x坐标中较小者x1窗体中x坐标中较大者yo-窗体中丫坐标中较小者y1 -窗体中y坐标中较大者 返回值:无*/void lcd_setpos(unsigned int xo,unsigned int x1 ,unsigned int yo,unsigned int y1) lnit_lcd_data(

17、window_xaddr_start,xo); lnit_lcd_data(window_xaddr_end,x1); lnit_lcd_data(window_yaddr_start,yo);lnit_lcd_data(window_yaddr_end,y1); lnit_lcd_data(gram_xaddr,xo); lnit_lcd_data(gram_yaddr,yo);write_lcd_cmd(0x0000,0x0022);/lcd_writecmd(gramwr);/it*函数名称:clear_screen功能:清屏参数:back_color -清屏后的背景颜色 返回值:无*

18、ivoid clear_screen(unsigned int back_color)unsigned int i ,j ;lcd_setpos(0,240,0,320);for(i = 0 ;i < 325 ;i+)for(j = 0 ;j < 240 ;j+)write_lcd_data_u16(back_color);函数名称:lcd_putchar8x16功能:显示8x16的字符参数:x起始x坐标y-起始y坐标 c要显示的字符for_color前景颜色back_color背景颜色返回值:无a-* ivoid lcd_putchar8x16(unsigned int x, u

19、nsigned int y, unsigned char c, unsigned int for_color, unsigned int back_color)unsigned char ij;unsigned char m ;c-= 32;lcd_setpos(x,x+8-1 ,y,y+16-1);for(i = 0 ;i < 16 ;i+)m = font8x16ci;for(j = 0 ;j < 8 ;j+) if(m&0x80)=0x80) write_lcd_data_u16(for_color);elsewrite_lcd_data_u16 (back_colo

20、r);m«=1;函数名称:lcd_putgb1616功 能:显示16x16的汉字参数:x起始x坐标y-起始y坐标c要显示的汉字for_color -前景颜色back_color背景颜色返回值:无*ivoid lcd_putgb1616(unsigned int x5 unsigned int y, unsigned char c2, unsigned int for_color,unsigned int back_color)unsigned int i, j5 k ;unsigned int m ;lcd_setpos(x ,x+16-1 ,y ,y+16-1);for (k =

21、0;k < 25;k+)25表示自建汉字库屮的汉字个数,采用循环查询if( (gb_16k.lndex0=c0) && (gb_16k.lndex1=c1)for(i = 0;i < 32;i+)m = gb_16k.mski;for(j = 0;j v 8;j+)if(m&0x80)=0x80)write_lcd_data_u16(for_color);elsewrite_lcd_data_u16(back_color);m«=1;/*函数名称:lcd_putgb3232功 能:显示32x32的汉字参数:x起始x坐标y起始y坐标c要显不的汉字fo

22、r_color前景颜色back_color背景颜色返回值:无*jvoid lcd_putgb3232(unsigned int x, unsigned int y, unsigned char c2, unsigned intfor_color,unsigned int back_color)unsigned int i, j, k ;unsigned int m ;lcd_setpos(x ,x+32-1 ,y ,y+32-1);for (k = 0;k < 2;k+)25表示自建汉字库中的汉字个数,釆用循环查询if( (gb_32kndex0=c0) && (gb_3

23、2k.lndex1=c1) for(i = 0;i < 128;i+)m = gb_32k.mski;for(j = 0;j < 8;j+)if(m&0x80)=0x80)write_lcd_data_u16(for_color);elsewrite_lcd_data_u16(back_color);m«=1;函数名称:lcd_putstring功能:显示32x32的字符串参数:x起始x坐标y起始y坐标s要显示的字符串for_color -前景颜色back_color -背景颜色返回值:无*ivoid lcd_putstring(unsigned int x, u

24、nsigned int y, unsigned char *s, unsigned intfor_color, unsigned int back_color)unsigned char i = 0 ;while(*s)lcd_putchar8x16(x+i*8,y,*s,for_color,back_color);s+ ;i+ ;函数名称:lcd_putgb1616_string功能:显示16x16的汉字串参数:x起始x坐标y-起始y坐标s要显示的汉字符串for_color前景颜色back_color背景颜色返回值:无*/void lcd_putgb1616_string(unsigned

25、int x unsigned int y ,unsigned char *s ,unsigned int for_color,unsigned int back_color)unsigned char i = 0 ;while(*s)lcd_putgb1616(x+i*8 ,y ,(unsigned char *)s ,for_color ,back_color);s += 2 ;i+=2;函数名称:show_photo功能:显不图片参数:xo起始x坐标yo起始y坐标x图片宽y图片长pic要显示的图片数组返回值:无* /void show_photo(unsigned int xo ,unsi

26、gned int yo unsigned int x unsigned int y ,const unsigned char pic)unsigned int j;unsigned int i;unsigned long s=0;lcd_setpos(xo,xo+x-1 ,yo,yo+y-1);for (i=0;i<y-1 ;i+)for (j=o;j<x-1;j+)write_lcd_data(pic2*s,pic2*s+1);s+ ;函数名称:lcd_drawline功能:画直线参数:x起始x坐标y起始y坐标length直线长度(长度超过边框将被截掉)direction 直线方

27、向(horizontal or verticalcolor -直线颜色返回值:无*/void lcd_drawline(unsigned short x ,unsigned short y ,unsigned short length , unsigned char direction ,unsigned int color)unsigned char i;if(direction = horizontal)if( (x+length) < 240) 检查是否超出边框lcd_setpos(x ,x+length ,y ,y);for(i = 0 ;i < length ;i+)wr

28、ite_lcd_data_u16(color);elselcd_setpos(x ,240 ,y ,y);for(i = 0 ;i < (240-x) ;i+)write_lcd_data_u16(color);else if(direction = vertical)if(y+length < 320) 检查是否超出边框lcd_setpos(x ,x ,y ,y+length);for(i = 0 ;i < length ;i+)write_lcd_data_u16(color);elselcd_setpos(x ,x ,y ,320); for(i = 0 ;i <

29、 (320-y) ;i+)write_lcd_data_u16(color); /*函数名称:lcd_drawrect功能:i田i矩形参数:x起始x坐标y起始y坐标width矩形宽height -矩形高color -直线颜色返回值:无*jvoid lcd_drawrect(unsigned short x ,unsigned short y ,unsigned short width ,unsigned short height,unsigned int color)lcd_drawline(x ,y ,width .horizontal,color) ; /±'-'

30、lcd_drawline(x ,y+height .width horizontal,color); 下lcd_drawline(x ,y .height,vertical .color); 左tlcd_drawline(x+width ,y .height .vertical,color);右t函数名称:lcd_drawcircle功能:在指定圆心处以指定半径画圆参数:x圆心x坐标y-圆心y坐标radius半径长度color直线颜色返回值:无*ivoid lcd_drawcircle(unsigned short xpos ,unsigned short ypos ,unsigned sho

31、rt radius , unsigned int color)signed long d ; 变暈unsigned long curx ; 当前 x 坐标 unsigned long cury ; 当前 y 坐标d = 3 (radius « 1);curx = 0;cury = radius;while (curx <= cury)lcd_setpos(xpos + curx, xpos + curx ,ypos + cury ,ypos + cury); write_lcd_data_u 16(color);lcd_setpos(xpos + curx, xpos + cu

32、rx ,ypos cury ,ypos - cury); write_lcd_data_u16(color);lcd_setpos(xpos curx, xpos curx ,ypos + cury ,ypos + cury); write_lcd_data_u16(color);lcd_setpos(xpos - curx, xpos - curx ,ypos cury ,ypos cury);wr ite_lc d_data_u 16(color);lcd_setpos(xpos + cury, xpos + cury ,ypos + curx ,ypos + curx); write_l

33、cd_data_u16(color);lcd_setpos(xpos + cury, xpos + cury ,ypos curx ,ypos - curx);wr ite_lc d_data_u 16(color);lcd_setpos(xpos cury, xpos cury ,ypos + curx ,ypos + curx); write_lcd_data_u16(color);lcd_setpos(xpos cury, xpos - cury ,ypos curx ,ypos curx); write_lcd_data_u 16(color);if (d < 0)d += (c

34、urx « 2) + 6;elsed += (curx - cury) « 2) + 10;cury-;curx+;函数名称:u32tostr功能:将整型数据转换为字符串以送给液品显示参 数:dat要转换的整型数据str -保存转换后字符串的地址指针返回值:无void u32tostr(unsigned long dat,unsigned char *str)char te mp20;unsigned char i=0,j=0;while(dat)tempi=dat%10+0x30;i+;dat/=10;j=>; for(i=0;i<j;i+)stri=temp

35、j-i-1;if(!i) stri+=,o,; stri=o;/* 函数名称:lnit_lcd功能:初始化lcd参数:无 返回值:无 */ void lnit_lcd_9325tp(void)gpiojnittypedef gpio_lnitstructure ;数据端口设为输出gpio initstructure.gpio pin = gpio pin all ;gpio_lnitstructure.gpio_speed = gpio_speed_50mhz ; gpio_lnitstructure.gpio_mode = gpio_mode_out_pp ; gpio_lnit(gpioe

36、,&gpiojnitstructure);控制端口设为输出gpio_lnitstructure.gpio_pin = lcd_control_pin;gpiojnitstructure.gpio_speed = gpio_speed_50mhz ; gpio initstructure.gpio mode = gpio mode out pp ; gpio_lnit(gpiod,&gpio_lnitstructure);rd_lcd_set;cs_lcd_set;delay_nms(5);rst_lcd_clr ;delay_nms(5);rst lcd set ;delay_

37、nms(5);delay_nms(50);根据不同晶振速度可以调整延时,保障稳定显示lnit_lcd_data(oxooo1,0x0100);lnit_lcd_data(0x0002,0x0700);lnit_lcd_data(0x0003,0x1030);lnit_lcd_data(0x0004,0x0000);lnit_lcd_data(0x0008,0x0207);lnit_lcd_data(0x0009,0x0000);lnit_lcd_data(0x000a,0x0000);lnit_lcd_data(0x000c,0x0000);lnit_lcd_data(0x000d,0x000

38、0);lnit_lcd_data(0x000f,0x0000);/power on sequenee vghvgllnit_lcd_data(0x0010,0x0000);lnit_lcd_data(0x0011,0x0007);lnit_lcd_data(0x0012,0x0000);lnit_lcd_data(0x0013,0x0000);/vghlnit_lcd_data(0x0010,0x1290);lnit_lcd_data(0x0011,0x0227);delay_nms(100);/vregioutlnit_lcd_data(0x0012,0x001 d); /0x001bdel

39、ay_nms(100);/vom amplitudelnit_lcd_data(0x0013,0x1500);delay_nms(100);/vom hlnit_lcd_data(0x0029,0x0018);lnit_lcd_data(0x002b,0x000d);/gammalnit_lcd_data(0x0030,0x0004);lnit_lcd_data(0x0031,0x0307);lnit_lcd_data(0x0032,0x0002);/0006lnit_lcd_data(0x0035,0x0206);lnit_lcd_data(0x0036,0x0408);lnit_lcd_data(0x0037,0x0507);lnit_lcd_data(0x0038,0x0204);/0200lnit_lcd_data(0x0039,0x0707);lnit_lcd_data(0x003c,0x0405);/0504 lnit_lcd_data(0x003d,0x0f02);/ramlnit_lcd_data(0x0050,0x0000);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论