📄 51
字号:
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE CLOCK
OBJECT MODULE PLACED IN clock.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE clock.c DEBUG OBJECTEXTEND
line level source
1 #include <AT89x51.h>
2 #include <string.h>
3 #include<intrins.h>
4
5 #define LCM_RS P2_0 //定义引脚
6 #define LCM_RW P2_1
7 #define LCM_E P2_2
8 #define LCM_Data P0
9 #define Busy 0x80 //用于检测LCM状态字中的Busy标识
10 #define uchar unsigned char
11
12 uchar id,timecount,dipsmodid;
13 bit lmcinit_or_not; //是否需要清屏标志位“1”为需要“0”为不需要
14 bit flag,sflag; //flag是时钟冒号闪烁标志,sflag是温度负号显示标志
15 void Disp_line1(void); //显示屏幕第一行
16 void Disp_line2(void); //显示屏幕第二行
17 void id_case1_key();
18 void Disp_mod0(void);//显示模式0
19 void Disp_mod1(void);//显示模式
20
21
22 //*********** DS1302 时间显示定义部分
23 sbit T_CLK=P1^0;
24 sbit T_IO =P1^1;
25 sbit T_RST=P1^2;
26 sbit ACC0=ACC^0;
27 sbit ACC7=ACC^7;
28 void Set(uchar,uchar); //根据选择调整相应项目
29 void RTInputByte(uchar); /* 输入 1Byte */
30 uchar RTOutputByte(void); /* 输出 1Byte */
31 void W1302(uchar, uchar); // 向DS1302写入一个字节
32 uchar R1302(uchar); // 从DS1302读出一个字节
33 void Set1302(unsigned char * ); // 设置时间
34 bit sec,min,hour,year,mon,day,weekk; //闪烁标志位
35 //初始化后设置为:04年12月2日星期4 0点0分0秒
36 unsigned char inittime[7]={0x00,0x00,0x00,0x02,0x12,0x04,0x04};
37 // 秒 分钟 小时 日 月 年 星期
38
39 //***** 18B20温度显示定义部
40 sbit DQ=P3^3; //18B20 接P07口
41 typedef unsigned char byte;
42 typedef unsigned int word;
43 Read_Temperature(char,char);
44 void mychar(void);
45 byte ow_reset(void);
46 byte read_byte(void);
47 void write_byte(char val);
48 void adjust_res(char res); //res 分别等于 0x1f, 0x3f, 0x5f 温度读数分辨率分别对应
49 // 0.5, 0.25, 0.125
50
51 //*******温度控制部分*********
52 bit tl_flash_flag; //下限闪烁标志
53 bit th_flash_flag; //上限闪烁标志
54 bit tl_flag; //下限越限标志
55 bit th_flag; //上限越限标志
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 2
56 bit tl_sign,th_sign; //温度零下标志 0:零上,1:零下
57 char tempid;
58 void Disp_Temp(void); //显示上下限温度
59 void Set_TH_Temp(void); //设置温度上限
60 void Set_TL_Temp(void); //设置温度下限
61 signed char tl=20,th=45;
62 void Compare_Temp(signed char l,signed char h); //比较温度
63 void Tl_Al(void); //下限越限报警
64 void Th_Al(void); //上限越限报警
65
66
67
68 //******* 1602LCD驱动 **********************************************************
69 void WriteDataLCM(unsigned char WDLCM);
70 void WriteCommandLCM(unsigned char WCLCM,BuysC);
71 unsigned char ReadStatusLCM(void);
72 void LCMInit(void);
73 void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
74 void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
75 void Delay5Ms(void);
76 void Delay400Ms(void);
77 unsigned char code week[]={"Week."};
78
79
80 void main(void)
81 {
82 1 Delay400Ms(); //启动等待,等LCM讲入工作状态
83 1 LCMInit(); //LCM初始化
84 1 Delay5Ms(); //延时片刻(可不要)
85 1 mychar();
86 1 TMOD=0x01;
87 1 TH0=(65535-50000)/256;
88 1 TL0=(65535-50000)%256;
89 1 EA=1;
90 1 TR0=1;
91 1 ET0=1;
92 1 W1302(0x90,0xa5);//打开充电二级管 一个二级管串联一个2K电阻
93 1 W1302(0x8e,0x80);//写保护,禁止写操作
94 1 adjust_res(0x1f); //调整18B20的分辨率 0x1f:0.5; 0x3f:0.25; 0x5f:0.125
95 1 while(1)
96 1 {
97 2 if (P1_7==0)
98 2 {dipsmodid++;
99 3 lmcinit_or_not=1;
100 3 if(dipsmodid>2) dipsmodid=0;
101 3 while(P1_7==0);
102 3 }
103 2 switch(dipsmodid)
104 2 {
105 3 case 0:
106 3 Disp_mod0();
107 3 break;
108 3 case 1:
109 3 Disp_mod1();
110 3 break;
111 3 }
112 2 }
113 1 }
114 /*//选择显示模?
115 void Dispmod_id_case_key()
116 {
117 if (P0_3==0)
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 3
118 {dipsmodid++;
119 if(dipsmodid>1) dipsmodid=0;
120 }
121 }*/
122 //显示模式0
123 void Disp_mod0(void)
124 {
125 1 if(lmcinit_or_not==1)
126 1 {LCMInit();
127 2 lmcinit_or_not=0;
128 2 }
129 1 if ((P1_4|P1_5)==0) //初始化
130 1 {
131 2 Delay5Ms();
132 2 if ((P1_4|P1_5)==0) Set1302(inittime);
133 2 }
134 1 //mychar(); //显示自定义字符
135 1 if (P1_6==0) // 设置和选择项目键
136 1 {
137 2 Delay5Ms();
138 2 if(P0_6==0){id++;if(id>7) id=0;}
139 2 while(P1_6==0);
140 2 }
141 1 switch(id)
142 1 {
143 2 case 0:
144 2 sec=0;
145 2 Disp_line1(); Disp_line2();
146 2 break;
147 2 case 1://年
148 2 year=1;
149 2 Disp_line1(); Disp_line2();
150 2 id_case1_key();
151 2 break;
152 2 case 2://月
153 2 year=0;mon=1;
154 2 Disp_line1(); Disp_line2();
155 2 id_case1_key();
156 2 break;
157 2 case 3://日
158 2 mon=0;day=1;
159 2 Disp_line1(); Disp_line2();
160 2 id_case1_key();
161 2 break;
162 2 case 4://星期
163 2 day=0;weekk=1;
164 2 Disp_line1(); Disp_line2();
165 2 id_case1_key();
166 2 break;
167 2 case 5://小时
168 2 weekk=0;hour=1;
169 2 Disp_line1(); Disp_line2();
170 2 id_case1_key();
171 2 break;
172 2 case 6://分钟
173 2 hour=0;min=1;
174 2 Disp_line1(); Disp_line2();
175 2 id_case1_key();
176 2 break;
177 2 case 7://秒
178 2 min=0;sec=1;
179 2 Disp_line1(); Disp_line2();
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 4
180 2 id_case1_key();
181 2 break;
182 2 }
183 1 }
184 //显示模式1
185 void Disp_mod1(void)
186 {
187 1 if(lmcinit_or_not==1)
188 1 {LCMInit();
189 2 lmcinit_or_not=0;
190 2 }
191 1 Read_Temperature(1,0);
192 1 DisplayOneChar(0,1,'T');
193 1 DisplayOneChar(1,1,'L');
194 1 DisplayOneChar(2,1,':');
195 1 DisplayOneChar(7,1,'T');
196 1 DisplayOneChar(8,1,'H');
197 1 DisplayOneChar(9,1,':');
198 1 if(P1_6==0)
199 1 {
200 2 if(P1_6==0)
201 2 {
202 3 tempid++;
203 3 if(tempid>2) tempid=0;
204 3 while(P1_6==0);
205 3 }
206 2 }
207 1 switch(tempid)
208 1 {
209 2 case 0:
210 2 tl_flash_flag=0;
211 2 th_flash_flag=0;
212 2 Disp_Temp();
213 2 break;
214 2 case 1:
215 2 tl_flash_flag=1;
216 2 th_flash_flag=0;
217 2 Disp_Temp();
218 2 Set_TL_Temp();
219 2 break;
220 2 case 2:
221 2 tl_flash_flag=0;
222 2 th_flash_flag=1;
223 2 Disp_Temp();
224 2 Set_TH_Temp();
225 2 break;
226 2 }
227 1 Compare_Temp(tl,th);
228 1 Tl_Al();
229 1 Th_Al();
230 1 }
231
232 //显示上下限温度
233 void Disp_Temp(void)
234 {
235 1
236 1 unsigned char tl_gw,tl_sw,tl_bw; //下限温度的个位,十位,百位
237 1 unsigned char th_gw,th_sw,th_bw; //上限温度的个位,十位,百位
238 1
239 1 tl_sign=tl>>7;
240 1 if(tl_sign)
241 1 {
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 5
242 2 tl_bw=(~(tl-1))/100; //计算百位
243 2 tl_sw=((~(tl-1))-tl_bw*100)/10; //计算十位
244 2 tl_gw=(~(tl-1))-tl_bw*100-tl_sw*10; //计算个位
245 2 }
246 1 else
247 1 {
248 2 tl_bw=(tl)/100;
249 2 tl_sw=(tl-tl_bw*100)/10;
250 2 tl_gw=tl-tl_bw*100-tl_sw*10;
251 2 }
252 1
253 1 if(tl_flash_flag==1)
254 1 {
255 2 if(flag==1)
256 2 {if(tl_sign)
257 3 {
258 4 DisplayOneChar(3,1,0x2d);
259 4 DisplayOneChar(4,1,tl_sw+0x30);
260 4 DisplayOneChar(5,1,tl_gw+0x30);
261 4 }
262 3 else
263 3 {
264 4 DisplayOneChar(3,1,tl_bw+0x30);
265 4 DisplayOneChar(4,1,tl_sw+0x30); //显示下限温度
266 4 DisplayOneChar(5,1,tl_gw+0x30);
267 4 }
268 3 }
269 2 else
270 2 {DisplayOneChar(3,1,0x20);
271 3 DisplayOneChar(4,1,0x20); //显示下限温度
272 3 DisplayOneChar(5,1,0x20);
273 3 }
274 2 }
275 1 else
276 1 {
277 2 DisplayOneChar(3,1,tl_bw+0x30);
278 2 DisplayOneChar(4,1,tl_sw+0x30); //显示下限温度
279 2 DisplayOneChar(5,1,tl_gw+0x30);
280 2 }
281 1
282 1
283 1 th_sign=th>>7;
284 1 if(th_sign)
285 1 {
286 2 th_bw=(~(th-1))/100; //计算百位
287 2 th_sw=((~(th-1))-th_bw*100)/10; //计算十位
288 2 th_gw=(~(th-1))-th_bw*100-th_sw*10; //计算个位
289 2 }
290 1 else
291 1 {
292 2 th_bw=(th)/100;
293 2 th_sw=(th-th_bw*100)/10;
294 2 th_gw=th-th_bw*100-th_sw*10;
295 2 }
296 1
297 1
298 1 if(th_flash_flag==1)
299 1 {
300 2 if(flag==1)
301 2 {if(th_sign)
302 3 {
303 4 DisplayOneChar(10,1,0x2d);
C51 COMPILER V8.02 CLOCK 07/24/2009 14:39:44 PAGE 6
304 4 DisplayOneChar(11,1,th_sw+0x30); //显示下限温度
305 4 DisplayOneChar(12,1,th_gw+0x30);
306 4 }
307 3 else
308 3 {
309 4 DisplayOneChar(10,1,th_bw+0x30);
310 4 DisplayOneChar(11,1,th_sw+0x30); //显示下限温度
311 4 DisplayOneChar(12,1,th_gw+0x30);
312 4 }
313 3 }
314 2 else
315 2 {
316 3 DisplayOneChar(10,1,0x20);
317 3 DisplayOneChar(11,1,0x20); //显示下限温度
318 3 DisplayOneChar(12,1,0x20);
319 3 }
320 2 }
321 1 else
322 1 {
323 2 DisplayOneChar(10,1,th_bw+0x30);
324 2 DisplayOneChar(11,1,th_sw+0x30); //显示下限温度
325 2 DisplayOneChar(12,1,th_gw+0x30);
326 2 }
327 1 }
328
329 //设置温度下限
330 void Set_TL_Temp(void)
331 {
332 1 if(P1_5==0)
333 1 {
334 2 Delay5Ms();
335 2 if(P1_5==0)
336 2 {
337 3 tl++;
338 3 if(tl>125) tl=-55;
339 3 //if(tl<-55) tl=155;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -