?? 家電控制系統.lst
字號:
C51 COMPILER V7.06 家_緲刂芲_蚠 03/25/2009 22:37:00 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 家_緲刂芲_蚠
OBJECT MODULE PLACED IN 家電控制系統.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 家電控制系統.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg51.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <intrins.h>
5
6 #define uchar unsigned char
7 #define uint unsigned int
8 //typedef unsigned char uchar;
9 //typedef unsigned int uint;
10
11 sbit LCD_RS = P1^0;
12 sbit LCD_RW = P1^1;
13 sbit LCD_EN = P1^2;
14 sbit LED = P1^6;//數據傳輸指示
15 sbit LED1=P1^0;
16 sbit LED2=P1^1;
17 sbit LED3=P1^2;
18 sbit LED4=P1^3;
19 sbit LED5=P1^4;
20 sbit LED6=P1^5;
21 sbit LED7=P1^6;
22 sbit LED8=P1^7;
23
24
25
26
27
28 uchar RST=0;
29 static count;
30 static value=0;
31 uchar p;
32 uchar flag=0;
33
34
35 char data mode[20]={"INPUT: "};
36
37 uchar code dis1[] = {"andy is the best!!"}; //預留要顯示的內容
38 uchar code dis2[] = {"happy new year!!"}; //預留要顯示的內容
39 /******************************************************************
40 /*
41 /*復位代碼
42 /*
43 /******************************************************************/
44 void soft_reset(void)
45 {
46 1 ((void (code *) (void)) 0x0000) ();
47 1 }
48 /*******************************************************************/
49 /*
- */
50 /* 延時子程序
- */
51 /*
- */
52 /*******************************************************************/
C51 COMPILER V7.06 家_緲刂芲_蚠 03/25/2009 22:37:00 PAGE 2
53
54 void delay(int ms)
55 {
56 1 int i;
57 1 while(ms--)
58 1 {
59 2 for(i = 0; i< 250; i++)
60 2 {
61 3 _nop_();
62 3 _nop_();
63 3 _nop_();
64 3 _nop_();
65 3 }
66 2 }
67 1 }
68
69 /*******************************************************************/
70 /*
- */
71 /*檢查LCD忙狀態
- */
72 /*lcd_busy為1時,忙,等待。lcd-busy為0時,閑,可寫指令與數據。 */
73 /*
- */
74 /*******************************************************************/
75
76 bit lcd_busy()
77 {
78 1 bit result;
79 1 LCD_RS = 0;
80 1 LCD_RW = 1;
81 1 LCD_EN = 1;
82 1 _nop_();
83 1 _nop_();
84 1 _nop_();
85 1 _nop_();
86 1 result = (bit)(P0&0x80);
87 1 LCD_EN = 0;
88 1 return result;
89 1 }
90
91 /*******************************************************************/
92 /*
- */
93 /*寫指令數據到LCD
- */
94 /*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。 *
-/
95 /*
- */
96 /*******************************************************************/
97
98 void lcd_wcmd(uchar cmd)
99 {
100 1 while(lcd_busy());
101 1 LCD_RS = 0;
102 1 LCD_RW = 0;
103 1 LCD_EN = 0;
104 1 _nop_();
105 1 _nop_();
106 1 P0 = cmd;
107 1 _nop_();
C51 COMPILER V7.06 家_緲刂芲_蚠 03/25/2009 22:37:00 PAGE 3
108 1 _nop_();
109 1 _nop_();
110 1 _nop_();
111 1 LCD_EN = 1;
112 1 _nop_();
113 1 _nop_();
114 1 _nop_();
115 1 _nop_();
116 1 LCD_EN = 0;
117 1 }
118
119 /*******************************************************************/
120 /*
- */
121 /*寫顯示數據到LCD
- */
122 /*RS=H,RW=L,E=高脈沖,D0-D7=數據。 *
-/
123 /*
- */
124 /*******************************************************************/
125
126 void lcd_wdat(uchar dat)
127 {
128 1 while(lcd_busy());
129 1 LCD_RS = 1;
130 1 LCD_RW = 0;
131 1 LCD_EN = 0;
132 1 P0 = dat;
133 1 _nop_();
134 1 _nop_();
135 1 _nop_();
136 1 _nop_();
137 1 LCD_EN = 1;
138 1 _nop_();
139 1 _nop_();
140 1 _nop_();
141 1 _nop_();
142 1 LCD_EN = 0;
143 1 }
144
145 /*******************************************************************/
146 /*
- */
147 /* 設定顯示位置
- */
148 /*
- */
149 /*******************************************************************/
150
151 void lcd_pos(uchar pos)
152 {
153 1 lcd_wcmd(pos|0x80); //數據指針=80+地址變量
154 1 }
155
156 /*******************************************************************/
157 /*
- */
158 /* LCD初始化設定
- */
159 /*
- */
C51 COMPILER V7.06 家_緲刂芲_蚠 03/25/2009 22:37:00 PAGE 4
160 /*******************************************************************/
161
162 void lcd_init()
163 {
164 1 delay(15); //等待LCD電源穩定
165 1 lcd_wcmd(0x38); //16*2顯示,5*7點陣,8位數據
166 1 delay(5);
167 1 lcd_wcmd(0x38);
168 1 delay(5);
169 1 lcd_wcmd(0x38);
170 1 delay(5);
171 1
172 1 lcd_wcmd(0x0c); //顯示開,關光標
173 1 delay(5);
174 1 lcd_wcmd(0x06); //移動光標
175 1 delay(5);
176 1 lcd_wcmd(0x01); //清除LCD的顯示內容
177 1 delay(5);
178 1 }
179
180 /*******************************************************************/
181 /*
- */
182 /* 清屏子程序
- */
183 /*
- */
184 /*******************************************************************/
185
186 void lcd_clr()
187 {
188 1 lcd_wcmd(0x01); //清除LCD的顯示內容
189 1 delay(5);
190 1 }
191
192 /*******************************************************************/
193 /*
- */
194 /* 閃動子程序
- */
195 /*
- */
196 /*******************************************************************/
197
198 void flash()
199 {
200 1 delay(200); //控制停留時間
201 1 lcd_wcmd(0x08); //關閉顯示
202 1 delay(50); //延時
203 1 lcd_wcmd(0x0c); //開顯示
204 1 delay(200);
205 1 lcd_wcmd(0x08); //關閉顯示
206 1 delay(50); //延時
207 1 lcd_wcmd(0x0c); //開顯示
208 1 //delay(200);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -