TFT2.4彩屏3 [自制动画效果-滑块+吊钩]
扫描二维码
随时随地手机看文章
>_<:引脚和前面几个连接一样,这里做了一个实用的动画效果,模拟起重机的2维视图。
9325tp.h
1 #ifndef __ILI9325_H__
2 #define __ILI9325_H__
3
4 void ILI9325_Initial(void);
5 void Write_Cmd_Data(unsigned char x, unsigned int y);
6 void Write_Cmd(unsigned char DH,unsigned char DL);
7 void Write_Data(unsigned char DH,unsigned char DL);
8 void delayms(unsigned int tt);
9 void Write_Data_U16(unsigned int y);
10 static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);
11 void CLR_Screen(unsigned int bColor);
12 void Put_pixel(unsigned char x,unsigned char y,unsigned int color);
13 void Line(unsigned int X0,
14 unsigned int Y0,
15 unsigned int X1,
16 unsigned int Y1,
17 unsigned int color);
18 void Rectangle(unsigned int left,
19 unsigned int top,
20 unsigned int right,
21 unsigned int bottom,
22 unsigned int color);
23 #endif
9325tp.c
1 /*----------------------------------------------------------------
2 320x240彩屏液晶驱动程序
3 ----------------------------------------------------------------*/
4 #include"9325tp.h"
5 #include"reg52.h"
6 /*----------------------------------------------------------------
7 全局变量
8 ----------------------------------------------------------------*/
9 #define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
10 #define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
11 #define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set
12 #define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
13 #define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
14 #define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
15 #define GRAMWR 0x0022 // memory write
16
17 #define DataPort P0 //数据口使用DataPort
18
19 /*----------------------------------------------------------------
20 定义硬件端口
21 ----------------------------------------------------------------*/
22 sbit CS=P2^2; //片选
23 sbit RES=P2^1; //复位
24 sbit RS=P2^4; //数据/命令选择
25 sbit RW=P2^5;
26 /*----------------------------------------------------------------
27 清屏函数
28 输入参数:bColor 清屏所使用的背景色
29 ----------------------------------------------------------------*/
30 void CLR_Screen(unsigned int bColor)
31 {
32 unsigned int i,j;
33 LCD_SetPos(0,240,0,320);//320x240
34 for (i=0;i<320;i++)
35 {
36
37 for (j=0;j<240;j++)
38 Write_Data_U16(bColor);
39
40 }
41 }
42 /*----------------------------------------------------------------
43 写命令、写数据
44 输入参数:x 需要输入的命令 16位
45 y 需要输入的数据 16位
46 ----------------------------------------------------------------*/
47 void Write_Cmd_Data (unsigned char x,unsigned int y)
48 {
49 unsigned char m,n;
50 m=y>>8;
51 n=y;
52 Write_Cmd(0x00,x);
53 Write_Data(m,n);
54
55 }
56
57 /*----------------------------------------------------------------
58 写16位数据
59 ----------------------------------------------------------------*/
60 void Write_Data_U16(unsigned int y)
61 {
62 unsigned char m,n;
63 m=y>>8;
64 n=y;
65 Write_Data(m,n);
66
67 }
68 /*----------------------------------------------------------------
69 写命令
70 ----------------------------------------------------------------*/
71
72 void Write_Cmd(unsigned char DH,unsigned char DL)
73 {
74 CS=0;
75 RS=0;
76
77 DataPort=DH;
78 RW=0;
79 RW=1;
80
81 DataPort=DL;
82
83 RW=0;
84 RW=1;
85 CS=1;
86 }
87
88 /*----------------------------------------------------------------
89 写数据 双8位
90 ----------------------------------------------------------------*/
91 void Write_Data(unsigned char DH,unsigned char DL)
92 {
93
94 CS=0;
95
96 RS=1;
97 DataPort=DH;
98 RW=0;
99 RW=1;
100
101 DataPort=DL;
102 RW=0;
103 RW=1;
104 CS=1;
105 }
106 /*----------------------------------------------------------------
107 延时函数
108 ----------------------------------------------------------------*/
109 void delayms(unsigned int count)
110 {
111 int i,j;
112 for(i=0;i 113 { 114 for(j=0;j<260;j++); 115 } 116 } 117 /*---------------------------------------------------------------- 118 液晶初始化 119 ----------------------------------------------------------------*/ 120 void ILI9325_Initial(void) 121 { 122 CS=1; 123 delayms(5); 124 RES=0; 125 delayms(5); 126 RES=1; 127 delayms(50); 128 Write_Cmd_Data(0x0001,0x0100); 129 Write_Cmd_Data(0x0002,0x0700); 130 Write_Cmd_Data(0x0003,0x1030); 131 Write_Cmd_Data(0x0004,0x0000); 132 Write_Cmd_Data(0x0008,0x0207); 133 Write_Cmd_Data(0x0009,0x0000); 134 Write_Cmd_Data(0x000A,0x0000); 135 Write_Cmd_Data(0x000C,0x0000); 136 Write_Cmd_Data(0x000D,0x0000); 137 Write_Cmd_Data(0x000F,0x0000); 138 //power on sequence VGHVGL 139 Write_Cmd_Data(0x0010,0x0000); 140 Write_Cmd_Data(0x0011,0x0007); 141 Write_Cmd_Data(0x0012,0x0000); 142 Write_Cmd_Data(0x0013,0x0000); 143 //vgh 144 Write_Cmd_Data(0x0010,0x1290); 145 Write_Cmd_Data(0x0011,0x0227); 146 //delayms(100); 147 //vregiout 148 Write_Cmd_Data(0x0012,0x001d); //0x001b 149 //delayms(100); 150 //vom amplitude 151 Write_Cmd_Data(0x0013,0x1500); 152 //delayms(100); 153 //vom H 154 Write_Cmd_Data(0x0029,0x0018); 155 Write_Cmd_Data(0x002B,0x000D); 156 157 //gamma 158 Write_Cmd_Data(0x0030,0x0004); 159 Write_Cmd_Data(0x0031,0x0307); 160 Write_Cmd_Data(0x0032,0x0002);// 0006 161 Write_Cmd_Data(0x0035,0x0206); 162 Write_Cmd_Data(0x0036,0x0408); 163 Write_Cmd_Data(0x0037,0x0507); 164 Write_Cmd_Data(0x0038,0x0204);//0200 165 Write_Cmd_Data(0x0039,0x0707); 166 Write_Cmd_Data(0x003C,0x0405);// 0504 167 Write_Cmd_Data(0x003D,0x0F02); 168 //ram 169 Write_Cmd_Data(0x0050,0x0000); 170 Write_Cmd_Data(0x0051,0x00EF); 171 Write_Cmd_Data(0x0052,0x0000); 172 Write_Cmd_Data(0x0053,0x013F); 173 Write_Cmd_Data(0x0060,0xA700); 174 Write_Cmd_Data(0x0061,0x0001); 175 Write_Cmd_Data(0x006A,0x0000); 176 // 177 Write_Cmd_Data(0x0080,0x0000); 178 Write_Cmd_Data(0x0081,0x0000); 179 Write_Cmd_Data(0x0082,0x0000); 180 Write_Cmd_Data(0x0083,0x0000); 181 Write_Cmd_Data(0x00