?? 1602動態.lst
字號:
C51 COMPILER V7.06 1602__蘝 01/18/2010 00:02:16 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 1602__蘝
OBJECT MODULE PLACED IN 1602動態.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE 1602動態.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1
2 /*1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK*/
3
4 /*-----------------------------------------------
5 名稱:LCD1602
6 公司:上海浩豚電子科技有限公司
7 編寫:師訪
8 日期:2009.5
9 修改:無
10 內容:通過標準程序動態顯示字符
11 ------------------------------------------------*/
12 #include<reg52.h> //包含頭文件,一般情況不需要改動,頭文件包含特殊功能寄存器的定義
13
14 sbit RS = P2^4; //定義端口
15 sbit RW = P2^5;
16 sbit EN = P2^6;
17
18 #define RS_CLR RS=0
19 #define RS_SET RS=1
20 #define RW_CLR RW=0
21 #define RW_SET RW=1
22 #define EN_CLR EN=0
23 #define EN_SET EN=1
24 /******************************************************************/
25 /* 微秒延時函數 */
26 /******************************************************************/
27 void delay_us(unsigned int n) //延時 如果需要高精度延時 請嵌入匯編
28 {
29 1 if (n == 0)
30 1 {
31 2 return ;
32 2 }
33 1 while (--n);
34 1 }
35 /******************************************************************/
36 /* 毫秒函數聲明 */
37 /******************************************************************/
38 void delay_ms(unsigned char i)
39 {
40 1 unsigned char a, b;
41 1 for (a = 1; a < i; a++)
42 1 {
43 2 for (b = 1; b; b++)
44 2 { ; }
45 2 }
46 1 }
47 /******************************************************************/
48 /* 寫入命令函數 */
49 /******************************************************************/
50 void LCD_write_com(unsigned char com)
51 {
52 1 RS_CLR;
53 1 RW_CLR;
54 1 EN_SET;
55 1 P0 = com;
C51 COMPILER V7.06 1602__蘝 01/18/2010 00:02:16 PAGE 2
56 1 delay_us(5);
57 1 EN_CLR;
58 1 }
59 /******************************************************************/
60 /* 寫入數據函數 */
61 /******************************************************************/
62 void LCD_write_Data(unsigned char Data)
63 {
64 1 RS_SET;
65 1 RW_CLR;
66 1 EN_SET;
67 1 P0 = Data;
68 1 delay_us(5);
69 1 EN_CLR;
70 1 }
71 /******************************************************************/
72 /* 清屏函數 */
73 /******************************************************************/
74 void LCD_clear(void)
75 {
76 1 LCD_write_com(0x01);
77 1 delay_ms(5);}
78 /******************************************************************/
79 /* 寫入字符串函數 */
80 /******************************************************************/
81 void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
82 {
83 1 if (y == 0)
84 1 {
85 2 LCD_write_com(0x80 + x);
86 2 }
87 1 else
88 1 {
89 2 LCD_write_com(0xC0 + x);
90 2 }
91 1 while (*s)
92 1 {
93 2 LCD_write_Data( *s);
94 2 s ++;
95 2 }
96 1 }
97 /******************************************************************/
98 /* 寫入字節函數 */
99 /******************************************************************/
100 void LCD_write_char(unsigned char x,unsigned char y,unsigned char Data)
101 {
102 1 if (y == 0)
103 1 {
104 2 LCD_write_com(0x80 + x);
105 2 }
106 1 else
107 1 {
108 2 LCD_write_com(0xC0 + x);
109 2 }
110 1 LCD_write_Data( Data);
111 1 }
112 /******************************************************************/
113 /* 初始化函數 */
114 /******************************************************************/
115 void LCD_init(void)
116 {
117 1 LCD_write_com(0x38); /*顯示模式設置*/
C51 COMPILER V7.06 1602__蘝 01/18/2010 00:02:16 PAGE 3
118 1 delay_ms(5);
119 1 LCD_write_com(0x38);
120 1 delay_ms(5);
121 1 LCD_write_com(0x38);
122 1 delay_ms(5);
123 1 LCD_write_com(0x38);
124 1 LCD_write_com(0x08); /*顯示關閉*/
125 1 LCD_write_com(0x01); /*顯示清屏*/
126 1 LCD_write_com(0x06); /*顯示光標移動設置*/
127 1 delay_ms(5);
128 1 LCD_write_com(0x0C); /*顯示開及光標設置*/
129 1 }
130
131 /******************************************************************/
132 /* 主函數 */
133 /******************************************************************/
134 void main(void)
135 {
136 1 unsigned char i;
137 1 unsigned char *p;
138 1 delay_ms(100);
139 1 LCD_init();
140 1 while (1)
141 1 {
142 2 i = 1;
143 2 p = "www.doflye.net";
144 2 LCD_clear();
145 2 LCD_write_str(2,0,"Welcome to");
146 2 delay_ms(250);
147 2 while (*p)
148 2 {
149 3 LCD_write_char(i,1,*p);
150 3 i ++;
151 3 p ++;
152 3 delay_ms(250);
153 3 }
154 2 delay_ms(250);
155 2 }
156 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 252 ----
CONSTANT SIZE = 26 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -