📄 lcd.lst
字号:
C51 COMPILER V8.02 LCD 05/08/2008 13:16:16 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN lcd.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd\lcd.c LARGE BROWSE INCDIR(.\dataflash;.\lcd;.\task;.\uart;.\ucos;.\key)
- DEBUG OBJECTEXTEND PRINT(.\lcd.lst) OBJECT(lcd.obj)
line level source
1 /*
2 ********************************************************************************
3 * C8051F340 LCD modular
4 *
5 * Ambition Comm Tech Ltd.Cop
6 * Jason.D.Proakis
7 *
8 * File Name : LCD.c
9 * File Description : C file of LCD modular TBM12F64-36A.
10 *
11 * Create Date : 04-21-2008
12 * Version : V1.00
13 * Modified History :
14 * None
15 *
16 * All rights reserved.
17 ********************************************************************************
18 */
19
20 /*
21 * rd_inst(), LCD_get_stat(), set_disp(), set_sta_line()
22 * not even test
23 */
24
25 /*
26 ********************************************************************************
27 * HEADER FILE INCLUDE
28 ********************************************************************************
29 */
30 #include <C8051F340.h>
31 #include "LCD.h"
32 #include "dataflash.h"
33
34 /*
35 ********************************************************************************
36 * INTERNAL FUNCTION DECLARATION
37 ********************************************************************************
38 */
39
40 static void put_asc(unsigned char ch);
41 static void put_asc_rev(unsigned char ch);
42 static void put_hz(unsigned int indx);
43 static void put_hz_rev(unsigned int indx);
44
45 /* set display start line, virtually set Z counter value */
46 static void set_sta_line(unsigned char num_of_line,bit cs);
47
48 /* set page address, virtually set X counter value */
49 static void set_pg_addr(unsigned char pg_addr,bit cs);
50
51 /* set Y address, virtually set Y counter value, column number */
52 static void set_y_addr(unsigned char y_addr,bit cs);
53
54 /* srt cursor to next line */
C51 COMPILER V8.02 LCD 05/08/2008 13:16:16 PAGE 2
55 static void nxt_line(void);
56
57 /* clear end of line */
58 static void clr_eol(void);
59
60 /* display Ambition Logo */
61 static void disp_logo(void);
62
63 /* display cursor at last of character */
64 static void disp_cur(void);
65
66 /* set sepecified part of LCD display ON or OFF */
67 static void set_disp(bit stat,bit cs);
68
69 /* wait specified chip ready */
70 static void wt_rdy(bit cs);
71
72 /* write one byte data to specified chip of LCD */
73 static void wr_dat(unsigned char dat,bit cs);
74
75 /* write one byte instruction to specified chip of LCD */
76 static void wr_inst(unsigned char inst,bit cs);
77
78 /* read one byte instruction from specified chip of LCD */
79 static unsigned char rd_inst(bit cs);
80
81 /*
82 ********************************************************************************
83 * STATIC VARIABLES
84 ********************************************************************************
85 */
86 static unsigned char code logo[32] = {
87 0xC0,0x03,0xF0,0x05,0xF8,0x15,0x3C,0x2A,0xDE,0x6A,0x2E,0x74,0xAF,0xFB,0x5F,0xFC,
88 0x9F,0xFF,0xBF,0xFF,0x3E,0x7F,0x9E,0x7E,0x9C,0x3E,0x18,0x1F,0x10,0x0F,0xC0,0x03,
89 };
90
91 static unsigned char reverse = 0x00;
92 static unsigned char cur_x;
93 static unsigned char cur_y;
94 static bit cur_ic;
95
96 /*
97 ********************************************************************************
98 * EXTERNAL INTERFACE FUNCTION
99 ********************************************************************************
100 */
101 /*
102 ********************************************************************************
103 * Function Name : LCD_init
104 * Description : initial LCD port, wait until reset done, set display ON
105 * Parameter : none
106 * Return : none
107 ********************************************************************************
108 */
109 void LCD_init(void)
110 {
111 1 P1MDOUT |= 0x30; /* set CS1, CS2 push-pull output */
112 1 P3MDOUT |= 0xF0; /* set D/I, R/W, E, BEN, push-pull output */
113 1 P4MDOUT = 0xFF; /* set data port push-pull output */
114 1
115 1 LCD_E = 0;
116 1 LCD_CS1 = 0;
C51 COMPILER V8.02 LCD 05/08/2008 13:16:16 PAGE 3
117 1 LCD_CS2 = 0;
118 1 LCD_DI = 1;
119 1 LCD_RW = 0;
120 1 LCD_BEN = 1;
121 1
122 1 while(rd_inst(LCD_IC1) & 0x10); /* wait IC1 until reset done */
123 1 while(rd_inst(LCD_IC2) & 0x10); /* wait IC2 until reset done */
124 1
125 1 LCD_clr();
126 1
127 1 set_disp(LCD_DISP_ON,LCD_IC1); /* set IC1 display ON */
128 1 set_disp(LCD_DISP_ON,LCD_IC2); /* set IC2 display ON */
129 1
130 1 set_sta_line(0,LCD_IC1); /* set IC1 start line 0 */
131 1 set_sta_line(0,LCD_IC2); /* set IC2 start line 0 */
132 1
133 1 LCD_cur_home(); /* set position home */
134 1 //disp_logo();
135 1 }
136
137 /*
138 ********************************************************************************
139 * Function Name : LCD_get_stat
140 * Description : get LCD current status
141 * Parameter : cs, bit type, sepecify which chip status is to get.
142 * can be set LCD_IC1 or LCD_IC2, other value is not permitted.
143 * Return : value of status register, unsigned char type
144 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
145 * BUSY 0 ON/OFF RET 0 0 0 0
146 ********************************************************************************
147 */
148 unsigned char LCD_get_stat(bit cs)
149 {
150 1 return (rd_inst(cs));
151 1 }
152
153 /*
154 ********************************************************************************
155 * Function Name : LCD_clr
156 * Description : clear LCD screen and set cursor home
157 * Parameter : none
158 * Return : none
159 ********************************************************************************
160 */
161 void LCD_clr(void)
162 {
163 1 unsigned char i,j;
164 1
165 1 for(i = 0;i < 8;i++) /* set DDRAM all 0 */
166 1 {
167 2 set_pg_addr(i,LCD_IC1); /* X counter will not increase auto */
168 2 set_y_addr(0,LCD_IC1);
169 2 set_pg_addr(i,LCD_IC2);
170 2 set_y_addr(0,LCD_IC2);
171 2
172 2 for(j = 0;j < 64;j++) /* Y counter increase auto after operation */
173 2 {
174 3 wr_dat(0x00,LCD_IC1);
175 3 wr_dat(0x00,LCD_IC2);
176 3 }
177 2 }
178 1 LCD_cur_home();
C51 COMPILER V8.02 LCD 05/08/2008 13:16:16 PAGE 4
179 1 }
180
181 /*
182 ********************************************************************************
183 * Function Name : LCD_cur_home
184 * Description : set cursor position to home
185 * Parameter : none
186 * Return : none
187 ********************************************************************************
188 */
189 void LCD_cur_home(void)
190 {
191 1 cur_x = 0;
192 1 cur_y = LCD_Y_DISP_STA_PIX;
193 1 cur_ic = LCD_IC1;
194 1
195 1 set_pg_addr(0,cur_ic);
196 1 set_y_addr(cur_y,cur_ic);
197 1 }
198
199 /*
200 ********************************************************************************
201 * Function Name : LCD_set_cur_pos
202 * Description : set cursor position
203 * Parameter : line, unsigned char type, range from 0 to 3.
204 * ch_addr, unsigned char type, range from 0 to
205 * (LCD_Y_DISP_STP_PIX - LCD_Y_DISP_STA_PIX)/LCD_FONT_WIDTH - 1.
206 * Return : none
207 ********************************************************************************
208 */
209 void LCD_set_cur_pos(unsigned char line,unsigned char ch_addr)
210 {
211 1 cur_x = line << 1;
212 1 cur_y = ch_addr * LCD_FONT_WIDTH + LCD_Y_DISP_STA_PIX;
213 1 cur_ic = cur_y >> 6;
214 1
215 1 set_pg_addr(cur_x,cur_ic);
216 1 set_y_addr(cur_y & 0xBF,cur_ic);
217 1 }
218
219 void LCD_putc(unsigned int buf)
220 {
221 1 if(buf > 0x80) put_hz(buf);
222 1 else (put_asc((unsigned char)buf));
223 1 }
224
225 void LCD_putc_rev(unsigned int buf)
226 {
227 1 if(buf > 0x80) put_hz_rev(buf);
228 1 else (put_asc_rev((unsigned char)buf));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -