📄 fengshan.lst
字号:
C51 COMPILER V7.06 FENGSHAN 09/21/2008 16:50:11 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE FENGSHAN
OBJECT MODULE PLACED IN fengshan.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE fengshan.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*************************************************************************
2 **模块名称: 遥控风扇
3 **创建人:陈华伟
4 **日 期:
5 **修改人:
6 **日 期:
7 **功能描述: 通过无线遥控,控制风扇实现定时关机,另外增加控制日光灯。
8 ************设定好的时间可保存,掉电后不用重新设定
9 **************************************************************************/
10 #include "reg52.h"
11 #include "intrins.h" #include "stdio.h"
12 #include "IR.h"
13 #include "18b20.h"
14 #define uchar unsigned char
15 #define uint unsigned int
16 uint t,chu;
17 signed char sec,min,hour;
18 uint us1000;
19 sbit SDA=P3^7;
20 sbit SCL=P3^6;
21 sbit P3_1=P3^1;
22 sbit P2_0=P2^0;
23 sbit P2_1=P2^1;
24 sbit P2_3=P2^3;
25 sbit P2_4=P2^4;
26 sbit P2_5=P2^5;
27 sbit P2_6=P2^6;
28 sbit P2_7=P2^7;
29 sbit P1_0=P1^0;
30 sbit P1_1=P1^1;
31 sbit P1_2=P1^2;
32 sbit P1_3=P1^3;
33
34 bit flag;
35 uchar code tempt[]={0xc0,0xf9,0xa4,0xb0,0x99, //01234
36 0x92,0x82,0xf8,0x80,0x90,0xff};//56789
37 uint idata ucSendBuffer[1]=0;
38 uint idata ucReceData;
39 void ACK();
40 void inc_sec();
41 void inc_min();
42 void inc_hour();
43
44 /************************************************************
45 **函数名:延时函数
46 **输 入:
47 **输 出:
48 *************************************************************/
49 void delay(void)
50 {
51 1 uint i;
52 1 for(i=100;i>0;i--)
53 1 _nop_();
54 1 }
55 void delay1(uint n)
C51 COMPILER V7.06 FENGSHAN 09/21/2008 16:50:11 PAGE 2
56 {
57 1 uint i,j;
58 1 for(i=0;i<n;i++)
59 1 for(j=0;j<124;j++);
60 1 }
61
62 /*********************************************************
63 **名称:I2C_Start
64 **功能:启动I2C
65 **输入:无
66 **返回:无
67 *********************************************************/
68 void I2C_Start()
69 {
70 1 SDA=1;
71 1 delay();
72 1 SCL=1;
73 1 delay();
74 1 SDA=0;
75 1 delay();
76 1 SCL=0; //钳位I2C总线,准备发送数据
77 1 }
78 /**********************************************************
79 **名称:I2C_Stop
80 **功能:停止I2C
81 **输入:无
82 **返回:无
83 **********************************************************/
84 void I2C_Stop()
85 {
86 1 SDA=0;
87 1 delay();
88 1 SCL=1;
89 1 delay();
90 1 SDA=1;
91 1 delay();
92 1 }
93 /**********************************************************
94 **名称:Ack
95 **功能:应答信号
96 **输入:无
97 **返回:无
98 **********************************************************/
99 void Ack()
100 {
101 1 SDA=0;
102 1 delay();
103 1 SCL=1;
104 1 delay();
105 1 SCL=0;
106 1 delay();
107 1 SDA=1;
108 1 delay();
109 1 }
110 /********************************************************
111 **名称:NoAck
112 **功能:发送非应答信号
113 **输入:无
114 **返回:无
115 ********************************************************/
116 void NoAck()
117 {
C51 COMPILER V7.06 FENGSHAN 09/21/2008 16:50:11 PAGE 3
118 1 SDA=1;
119 1 delay();
120 1 SCL=1;
121 1 delay();
122 1 SCL=0;
123 1 delay();
124 1 SDA=0;
125 1 delay();
126 1 }
127 /********************************************************
128 **名称:Test_Ack()
129 **功能:检测应答位
130 **输入:无
131 **返回:flag,有应答时flag为0,无应答时flag为1
132 *********************************************************/
133 bit Test_Ack()
134 {
135 1 SCL=0;
136 1 SDA=1;//读入数据
137 1 _nop_();_nop_();_nop_();_nop_();
138 1 SCL=1;
139 1 _nop_();_nop_();_nop_();_nop_();
140 1 if(SDA==0)
141 1 flag=1;
142 1 else flag=0;
143 1 SCL=0;
144 1 return(flag);
145 1 }
146 /********************************************************
147 **名称:SendData()
148 **功能:发送一字节数据
149 **输入:buffer
150 **返回:
151 *******************************************************/
152 void SendData(uint buffer)
153 {
154 1 uint BitCnt=8;//一字节8位
155 1 uint temp=0;
156 1 do
157 1 {
158 2 temp=buffer;
159 2 SCL=0;
160 2 delay();
161 2 if((temp&0x80)==0) //判断最高位是0还是1
162 2 SDA=0;
163 2 else
164 2 SDA=1;
165 2 delay();
166 2 SCL=1;
167 2 temp=_crol_(buffer,1);//将buffer中的数据左移一位
168 2 buffer=temp;
169 2 BitCnt--;
170 2 }
171 1 while(BitCnt);
172 1 SCL=0;
173 1 }
174 /**************************************************************
175 **名称:uint ReceiveData()
176 **功能:接收一字节数据
177 **输入:
178 **返回:ucReceData
179 **说明:将接收的数据存放在ucReceData中
C51 COMPILER V7.06 FENGSHAN 09/21/2008 16:50:11 PAGE 4
180 **************************************************************/
181 uint ReceiveData()
182 {
183 1 uint BitCnt=8;
184 1 uint temp=0;
185 1 SDA=1;//读入数据
186 1 do
187 1 {
188 2 SCL=0;
189 2 delay();
190 2 SCL=1;
191 2 delay();
192 2 if(SDA==1)
193 2 ucReceData=ucReceData|0x01; //低位置1
194 2 else
195 2 ucReceData=ucReceData&0x0fe; //低位清0
196 2 if(BitCnt-1)
197 2 {
198 3 temp=_crol_(ucReceData,1); //数据左移一位
199 3 ucReceData=temp;
200 3 }
201 2 BitCnt--;
202 2 }
203 1 while(BitCnt);
204 1 SCL=0;
205 1 return(ucReceData);
206 1 }
207 /*************************************************************
208 **名称:bit WriteNByte()
209 **功能:主机向24C02中写入多字节数据
210 **输入:
211 **返回:
212 **说明:sla-器件地址 suba-数据地址,*s-写入的数据,n-写入的字节数(n<=8)
213 **************************************************************/
214 bit WriteNByte(uint sla,uint suba,uint *s,uint n)
215 {
216 1 uint i;
217 1 I2C_Start();//启动I2C
218 1 SendData(sla);//发送器件地址
219 1 Test_Ack();
220 1 if(flag==0) return(0);
221 1 SendData(suba);
222 1 Test_Ack();
223 1 if(flag==0) return(0);
224 1 for(i=0;i<n;i++)//写入8字节数据
225 1 {
226 2 SendData(*(s+i));
227 2 Test_Ack();
228 2 if(flag==0) return(0);
229 2 }
230 1 I2C_Stop();
231 1 return(1);
232 1 }
233 /*************************************************************
234 **名称:bit ReadNByte()
235 **功能:主机从24C02中读出N字节数据(n<=8)
236 **输入:
237 **返回:
238 **说明:随机地址读操作
239 **************************************************************/
240 bit ReadNByte(uint sla,uint suba,uint *p,uint n)
241 {
C51 COMPILER V7.06 FENGSHAN 09/21/2008 16:50:11 PAGE 5
242 1 uint i;
243 1 I2C_Start();//启动I2C
244 1 SendData(sla);//发送器件地址
245 1 Test_Ack();
246 1 if(flag==0) return(0);
247 1 SendData(suba);//发送器件内部地址
248 1 Test_Ack();
249 1 if(flag==0) return(0);
250 1
251 1 I2C_Start();
252 1 SendData(sla+1);
253 1 Test_Ack();
254 1 if(flag==0) return(0);
255 1 for(i=0;i<n-1;i++)//读取字节数据
256 1 {
257 2 *(p+i)=ReceiveData();//读取数据
258 2 ACK();
259 2 }
260 1 *(p+n-1)=ReceiveData();
261 1
262 1 NoAck();
263 1 I2C_Stop();
264 1 return(1);
265 1 }
266
267 /*********************************************************
268 **函数名:beep()
269 **输 入:
270 **输 出:
271 *********************************************************/
272 void beep()
273 {
274 1 int h;
275 1 for(h=0;h<600;h++)
276 1 {
277 2 int n;
278 2 P3_1=1;
279 2 for(n=0;n<50;n++);
280 2 P3_1=0;
281 2 for(n=0;n<50;n++);
282 2 }
283 1 }
284 /************************************************************
285 **函数名:显示函数
286 **输 入:
287 **输 出:
288 ************************************************************/
289 void led(uint sdate)
290 {
291 1 P2_6=0;
292 1 P0=tempt[sdate/10];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -