12232 LCM Driver
自己写的12232LCM模块的驱动代码,实现了基本的功能。
1//==============================================================
2//12232.h
3//==============================================================
4#ifndef __12232Driver_H
5#define __12232Driver_H
6void LCD_Init(void);
7void LCD_Reset(void);
8void LCD_FillAll(void);
9void LCD_ClearAll(void);
10void LCD_WriteCmd(unsigned char cmd);
11void LCD_WriteCmd1(unsigned char cmd);
12void LCD_WriteCmd2(unsigned char cmd);
13void LCD_SetColumn(unsigned char column);
14void LCD_SetColumn1(unsigned char column);
15void LCD_SetColumn2(unsigned char column);
16void LCD_SetPage(unsigned char page);
17void LCD_SetPage1(unsigned char page);
18void LCD_SetPage2(unsigned char page);
19void LCD_WriteData(unsigned char d);
20void LCD_WriteData1(unsigned char d);
21void LCD_WriteData2(unsigned char d);
22unsigned char LCD_ReadData1(void);
23unsigned char LCD_ReadData2(void);
24#endif
25
26//==============================================================
27//12232Driver.c
28//==============================================================
29#include <reg51.h>
30#include "12232Driver.h"
31//#include <intrins.h>
32
33sbit E1=P3^4;
34sbit E2=P3^5;
35sbit A0=P3^7;
36sbit RST=P3^2;
37sbit RW=P3^6;
38
39#define LCD_DISPLAY_ON 0xAF
40#define LCD_DISPLAY_OFF 0xAE
41#define LCD_START_LINE_0 0xC0 //Set Start Line 0
42#define LCD_DRIVER_NORMAL 0xA4 //Normal display operation
43#define LCD_DRIVER_STATIC 0xA5 //Power Save
44#define LCD_DUTY_32 0xA9
45#define LCD_DUTY_16 0xA8
46#define LCD_RIGHTWARD_OUTPUT 0xA0
47#define LCD_LEFTWARD_OUTPUT 0xA1
48#define LCD_RESET 0xE3
49#define LCD_PAGE_0 0xB8
50#define LCD_RMW 0xE0
51#define LCD_END 0xEE
52#define uchar unsigned char
53//LCD Controller Display and Control Functions
54
55void LCD_Init(void)
56{
57 //E1=0;
58 //E2=0;
59 //Reset
60 RST=0;
61 RST=1;
62 LCD_WriteCmd(LCD_DISPLAY_ON); //Display On
63 LCD_WriteCmd(LCD_START_LINE_0); //Start = 0
64 LCD_WriteCmd(LCD_DRIVER_NORMAL); //Driver
65 LCD_WriteCmd(LCD_DUTY_32); //Duty 32
66 LCD_WriteCmd(LCD_RIGHTWARD_OUTPUT); //ADC
67 LCD_WriteCmd(LCD_RESET); //Reset
68 LCD_Reset();
69}
70
71void LCD_Reset(void)
72{
73 LCD_WriteCmd(LCD_RESET);
74}
75
76void LCD_FillAll(void)
77{
78 uchar page,y;
79 LCD_WriteCmd(LCD_RMW);
80 for(page=0;page<4;page++)
81 {
82 LCD_SetPage(page);
83 LCD_SetColumn(0);
84 for(y=0;y<61;y++)
85 {
86 LCD_WriteData(0xFF);
87 }
88 LCD_WriteCmd(LCD_END);
89 }
90}
91
92void LCD_ClearAll(void)
93{
94 uchar page,y;
95 LCD_WriteCmd(LCD_RMW);
96 for(page=0;page<4;page++)
97 {
98 LCD_SetPage(page);
99 LCD_SetColumn(0);
100 for(y=0;y<61;y++)
101 {
102 LCD_WriteData(0);
103 }
104 LCD_WriteCmd(LCD_END);
105 }
106}
107
108
109void LCD_WriteCmd(unsigned char cmd)
110{
111 LCD_WriteCmd1(cmd);
112 LCD_WriteCmd2(cmd);
113 return;
114}
115
116void LCD_WriteCmd1(unsigned char cmd)
117{
118 RW=0;
119 E1=0;
120 A0=0;
121 P1=cmd;
122 E1=1;
123 E1=0;
124 return;
125}
126
127void LCD_WriteCmd2(unsigned char cmd)
128{
129 RW=0;
130 E2=0;
131 A0=0;
132 P1=cmd;
133 E2=1;
134 E2=0;
135 return;
136}
137
138void LCD_WriteData(unsigned char d)
139{
140 LCD_WriteData1(d);
141 LCD_WriteData2(d);
142 return ;
143}
144
145void LCD_WriteData1(unsigned char d)
146{
147 RW=0;
148 E1=0;
149 A0=1;
150 P1=d;
151 E1=1;
152 E1=0;
153 return;
154}
155
156void LCD_WriteData2(unsigned char d)
157{
158 RW=0;
159 E2=0;
160 A0=1;
161 P1=d;
162 E2=1;
163 E2=0;
164 return;
165}
166
167void LCD_SetColumn(unsigned char d)
168{
169 LCD_SetColumn1(d);
170 LCD_SetColumn2(d);
171 return;
172}
173void LCD_SetColumn1(unsigned char d)
174{
175 LCD_WriteCmd1(d);
176 return;
177}
178
179void LCD_SetColumn2(unsigned char d)
180{
181 LCD_WriteCmd2(d);
182 return;
183}
184
185void LCD_SetPage(unsigned char page)
186{
187 LCD_SetPage1(page);
188 LCD_SetPage2(page);
189 return;
190}
191void LCD_SetPage1(unsigned char page)
192{
193 page=page%4;
194 LCD_WriteCmd1(LCD_PAGE_0+page); //0x5C
195 return;
196}
197
198void LCD_SetPage2(unsigned char page)
199{
200 page=page%4;
201 LCD_WriteCmd2(LCD_PAGE_0+page); //0x5C
202 return;
203}
204
205unsigned char LCD_ReadData1(void)
206{
207 unsigned char d=0;
208 RW=1;
209 E1=0;
210 A0=1;
211 P1=0xFF;
212 E1=1;
213 d=P1;
214 E1=0;
215 return d;
216}
217
218unsigned char LCD_ReadData2(void)
219{
220 unsigned char d=0;
221 RW=1;
222 E2=0;
223 A0=1;
224 P1=0xFF;
225 E2=1;
226 d=P1;
227 E2=0;
228 return d;
229}
2//12232.h
3//==============================================================
4#ifndef __12232Driver_H
5#define __12232Driver_H
6void LCD_Init(void);
7void LCD_Reset(void);
8void LCD_FillAll(void);
9void LCD_ClearAll(void);
10void LCD_WriteCmd(unsigned char cmd);
11void LCD_WriteCmd1(unsigned char cmd);
12void LCD_WriteCmd2(unsigned char cmd);
13void LCD_SetColumn(unsigned char column);
14void LCD_SetColumn1(unsigned char column);
15void LCD_SetColumn2(unsigned char column);
16void LCD_SetPage(unsigned char page);
17void LCD_SetPage1(unsigned char page);
18void LCD_SetPage2(unsigned char page);
19void LCD_WriteData(unsigned char d);
20void LCD_WriteData1(unsigned char d);
21void LCD_WriteData2(unsigned char d);
22unsigned char LCD_ReadData1(void);
23unsigned char LCD_ReadData2(void);
24#endif
25
26//==============================================================
27//12232Driver.c
28//==============================================================
29#include <reg51.h>
30#include "12232Driver.h"
31//#include <intrins.h>
32
33sbit E1=P3^4;
34sbit E2=P3^5;
35sbit A0=P3^7;
36sbit RST=P3^2;
37sbit RW=P3^6;
38
39#define LCD_DISPLAY_ON 0xAF
40#define LCD_DISPLAY_OFF 0xAE
41#define LCD_START_LINE_0 0xC0 //Set Start Line 0
42#define LCD_DRIVER_NORMAL 0xA4 //Normal display operation
43#define LCD_DRIVER_STATIC 0xA5 //Power Save
44#define LCD_DUTY_32 0xA9
45#define LCD_DUTY_16 0xA8
46#define LCD_RIGHTWARD_OUTPUT 0xA0
47#define LCD_LEFTWARD_OUTPUT 0xA1
48#define LCD_RESET 0xE3
49#define LCD_PAGE_0 0xB8
50#define LCD_RMW 0xE0
51#define LCD_END 0xEE
52#define uchar unsigned char
53//LCD Controller Display and Control Functions
54
55void LCD_Init(void)
56{
57 //E1=0;
58 //E2=0;
59 //Reset
60 RST=0;
61 RST=1;
62 LCD_WriteCmd(LCD_DISPLAY_ON); //Display On
63 LCD_WriteCmd(LCD_START_LINE_0); //Start = 0
64 LCD_WriteCmd(LCD_DRIVER_NORMAL); //Driver
65 LCD_WriteCmd(LCD_DUTY_32); //Duty 32
66 LCD_WriteCmd(LCD_RIGHTWARD_OUTPUT); //ADC
67 LCD_WriteCmd(LCD_RESET); //Reset
68 LCD_Reset();
69}
70
71void LCD_Reset(void)
72{
73 LCD_WriteCmd(LCD_RESET);
74}
75
76void LCD_FillAll(void)
77{
78 uchar page,y;
79 LCD_WriteCmd(LCD_RMW);
80 for(page=0;page<4;page++)
81 {
82 LCD_SetPage(page);
83 LCD_SetColumn(0);
84 for(y=0;y<61;y++)
85 {
86 LCD_WriteData(0xFF);
87 }
88 LCD_WriteCmd(LCD_END);
89 }
90}
91
92void LCD_ClearAll(void)
93{
94 uchar page,y;
95 LCD_WriteCmd(LCD_RMW);
96 for(page=0;page<4;page++)
97 {
98 LCD_SetPage(page);
99 LCD_SetColumn(0);
100 for(y=0;y<61;y++)
101 {
102 LCD_WriteData(0);
103 }
104 LCD_WriteCmd(LCD_END);
105 }
106}
107
108
109void LCD_WriteCmd(unsigned char cmd)
110{
111 LCD_WriteCmd1(cmd);
112 LCD_WriteCmd2(cmd);
113 return;
114}
115
116void LCD_WriteCmd1(unsigned char cmd)
117{
118 RW=0;
119 E1=0;
120 A0=0;
121 P1=cmd;
122 E1=1;
123 E1=0;
124 return;
125}
126
127void LCD_WriteCmd2(unsigned char cmd)
128{
129 RW=0;
130 E2=0;
131 A0=0;
132 P1=cmd;
133 E2=1;
134 E2=0;
135 return;
136}
137
138void LCD_WriteData(unsigned char d)
139{
140 LCD_WriteData1(d);
141 LCD_WriteData2(d);
142 return ;
143}
144
145void LCD_WriteData1(unsigned char d)
146{
147 RW=0;
148 E1=0;
149 A0=1;
150 P1=d;
151 E1=1;
152 E1=0;
153 return;
154}
155
156void LCD_WriteData2(unsigned char d)
157{
158 RW=0;
159 E2=0;
160 A0=1;
161 P1=d;
162 E2=1;
163 E2=0;
164 return;
165}
166
167void LCD_SetColumn(unsigned char d)
168{
169 LCD_SetColumn1(d);
170 LCD_SetColumn2(d);
171 return;
172}
173void LCD_SetColumn1(unsigned char d)
174{
175 LCD_WriteCmd1(d);
176 return;
177}
178
179void LCD_SetColumn2(unsigned char d)
180{
181 LCD_WriteCmd2(d);
182 return;
183}
184
185void LCD_SetPage(unsigned char page)
186{
187 LCD_SetPage1(page);
188 LCD_SetPage2(page);
189 return;
190}
191void LCD_SetPage1(unsigned char page)
192{
193 page=page%4;
194 LCD_WriteCmd1(LCD_PAGE_0+page); //0x5C
195 return;
196}
197
198void LCD_SetPage2(unsigned char page)
199{
200 page=page%4;
201 LCD_WriteCmd2(LCD_PAGE_0+page); //0x5C
202 return;
203}
204
205unsigned char LCD_ReadData1(void)
206{
207 unsigned char d=0;
208 RW=1;
209 E1=0;
210 A0=1;
211 P1=0xFF;
212 E1=1;
213 d=P1;
214 E1=0;
215 return d;
216}
217
218unsigned char LCD_ReadData2(void)
219{
220 unsigned char d=0;
221 RW=1;
222 E2=0;
223 A0=1;
224 P1=0xFF;
225 E2=1;
226 d=P1;
227 E2=0;
228 return d;
229}