📄 main.lst
字号:
C51 COMPILER V7.50 MAIN 06/02/2008 21:26:15 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /********************************************************************
2 本程序只供学习使用,未经作者许可,不得用于其它任何用途
3
4 欢迎访问我的USB专区:http://group.ednchina.com/93/
5 欢迎访问我的blog: http://www.ednchina.com/blog/computer00
6 http://computer00.21ic.org
7
8 欢迎大家访问wang1jin的博客:
9 http://www.ednchina.com/blog/wang1jin/
10
11 main.c file
12
13 作者:Computer-lov
14 建立日期:2007-11-20
15 修改日期:2007-11-20
16 版本:V1.0
17 版权所有,盗版必究。
18 Copyright(C) Computer-lov 2007-2017
19 All rights reserved
20 ********************************************************************/
21
22 #include "config.h"
23 #include "at89x52.h"
24 #include "Key.h"
25 #include "UART.h"
26 #include "MyType.h"
27 #include "led.h"
28 #include "lcd1602.h"
29 #include "adc.h"
30 #include "ds18b20.h"
31 #include "ds1302.h"
32 #include "time.h"
33 #include "main.h"
34
35
36 uint8 DispStatus;
37 uint8 DispBuffer[32];
38
39 code uint8 HeadTable[][72]={
40 "********************************************************************\r\n",
41 "****** EDN 51学习板测试程序 ******\r\n",
42 "****** 建立日期:",__DATE__," ******\r\n",
43 "****** 建立时间:",__TIME__," ******\r\n",
44 "****** 作者:电脑圈圈 ******\r\n",
45 "****** USB专区:http://group.ednchina.com/93/ ******\r\n",
46 "****** BLOG1:http://www.ednchina.com/blog/computer00 ******\r\n",
47 "****** BLOG2:http://computer00.21ic.org ******\r\n",
48 "********************************************************************\r\n",
49 };
50
51 /********************************************************************
52 函数功能:显示ADC结果函数。
53 入口参数:无。
54 返 回:无。
55 备 注:结果通过串口发送。如果使用了LCD,结果同时会显示在LCD上。
C51 COMPILER V7.50 MAIN 06/02/2008 21:26:15 PAGE 2
56 ********************************************************************/
57 void DispAdc(void)
58 {
59 1 uint32 Vadc;
60 1
61 1 Prints("ADC0: ");
62 1 Vadc=ReadAdc(0); //读ADC通道0
63 1 Vadc=Vadc*100*5; //换算为电压值
64 1 Vadc/=256;
65 1 DispBuffer[5]=0;
66 1 DispBuffer[4]='V'; //转换为显示的字符串
67 1 DispBuffer[3]='0'+Vadc%10;
68 1 Vadc/=10;
69 1 DispBuffer[2]='0'+Vadc%10;
70 1 Vadc/=10;
71 1 DispBuffer[1]='.';
72 1 DispBuffer[0]='0'+Vadc%10;
73 1 Prints(DispBuffer);
74 1 #ifdef LCD
75 1 if(DispStatus==DISP_ADC)
76 1 {
77 2 LcdCls();
78 2 LcdPrints("ADC0: ");
79 2 LcdPrints(DispBuffer);
80 2 }
81 1 #endif
82 1 Prints(" ADC1: ");
83 1 Vadc=ReadAdc(1);
84 1 Vadc=Vadc*100*5;
85 1 Vadc/=256;
86 1 DispBuffer[5]=0;
87 1 DispBuffer[4]='V';
88 1 DispBuffer[3]='0'+Vadc%10;
89 1 Vadc/=10;
90 1 DispBuffer[2]='0'+Vadc%10;
91 1 Vadc/=10;
92 1 DispBuffer[1]='.';
93 1 DispBuffer[0]='0'+Vadc%10;
94 1 Prints(DispBuffer);
95 1 Prints("\r\n");
96 1 #ifdef LCD
97 1 if(DispStatus==DISP_ADC)
98 1 {
99 2 LcdSetPosition(0x40);
100 2 LcdPrints("ADC1: ");
101 2 LcdPrints(DispBuffer);
102 2 }
103 1 #endif
104 1 }
105 ////////////////////////End of function//////////////////////////////
106
107 /********************************************************************
108 函数功能:显示温度函数。
109 入口参数:无。
110 返 回:无。
111 备 注:无。
112 ********************************************************************/
113 void DispTemperature(void)
114 {
115 1 uint32 T;
116 1 uint8 i;
117 1
C51 COMPILER V7.50 MAIN 06/02/2008 21:26:15 PAGE 3
118 1 Prints("Temperature: ");
119 1 DS18B20ReadScratchpad(); //读温度
120 1 DS18B20ConvertT(); //启动转换。转换需要750ms才能完成
121 1 i=0;
122 1 if(Temperature<0) //符号判断
123 1 {
124 2 DispBuffer[i++]='-';
125 2 T=Temperature*-1;
126 2 }
127 1 else
128 1 {
129 2 DispBuffer[i++]=' ';
130 2 T=Temperature;
131 2 }
132 1 T*=625; //转换为温度
133 1 DispBuffer[i++]='0'+(T%10000000)/1000000; //转换为显示的字符串
134 1 DispBuffer[i++]='0'+(T%1000000)/100000;
135 1 DispBuffer[i++]='0'+(T%100000)/10000;
136 1 DispBuffer[i++]='.';
137 1 DispBuffer[i++]='0'+(T%10000)/1000;
138 1 DispBuffer[i++]='0'+(T%1000)/100;
139 1 DispBuffer[i++]='0'+(T%100)/10;
140 1 DispBuffer[i++]='0'+(T%10);
141 1 DispBuffer[i++]=' ';
142 1 DispBuffer[i++]=0xdf;
143 1 DispBuffer[i++]='C';
144 1 DispBuffer[i]=0;
145 1
146 1 for(i=1;i<3;i++) //去掉前面多余的0
147 1 {
148 2 if(DispBuffer[i]!='0')
149 2 {
150 3 break;
151 3 }
152 2 }
153 1 DispBuffer[i-1]=DispBuffer[0];
154 1 Prints(&(DispBuffer[i-1]));
155 1 Prints("\r\n");
156 1 #ifdef LCD //如果有LCD,则同时显示到LCD上
157 1 if(DispStatus==DISP_TEMP)
158 1 {
159 2 LcdCls();
160 2 LcdPrints("Temperature: ");
161 2 LcdSetPosition(0x40);
162 2 LcdPrints(&(DispBuffer[i-1]));
163 2 }
164 1 #endif
165 1 }
166 ////////////////////////End of function//////////////////////////////
167
168 /********************************************************************
169 函数功能:显示按键按下函数。
170 入口参数:按下的键码。
171 返 回:无。
172 备 注:无。
173 ********************************************************************/
174 void DispKeyDown(uint8 k)
175 {
176 1 Prints("KEY");
177 1 UartPutChar(k+'0');
178 1 Prints(" down.\r\n");
179 1 }
C51 COMPILER V7.50 MAIN 06/02/2008 21:26:15 PAGE 4
180 ////////////////////////End of function//////////////////////////////
181
182 /********************************************************************
183 函数功能:显示按键弹起函数。
184 入口参数:弹起的键码。
185 返 回:无。
186 备 注:无。
187 ********************************************************************/
188 void DispKeyUp(uint8 k)
189 {
190 1 Prints("KEY");
191 1 UartPutChar(k+'0');
192 1 Prints(" up.\r\n");
193 1 }
194 ////////////////////////End of function//////////////////////////////
195
196 /********************************************************************
197 函数功能:主函数。
198 入口参数:无。
199 返 回:无。
200 备 注:无。
201 ********************************************************************/
202 void main(void)
203 {
204 1 uint8 i;
205 1 uint8 NeedRefresh;
206 1 uint16 BeepAlarmCount;
207 1 uint16 OldSystemTick;
208 1
209 1 DispStatus=DISP_TIME;
210 1
211 1 UartInit(); //初始化串口
212 1 InitKeyboard(); //初始化键盘
213 1
214 1 #ifdef LCD
215 1 LcdInit(); //LCD初始化
216 1 LcdPrints("Waiting.........");
217 1 #endif
218 1
219 1 DS1302Init();
220 1
221 1 for(i=0;i<13;i++) //显示信息
222 1 {
223 2 Prints(HeadTable[i]);
224 2 }
225 1
226 1 DS18B20Init();
227 1 // ReadAlarmClock();
228 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -