You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
14 KiB

C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE LIGHT
OBJECT MODULE PLACED IN Light.OBJ
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE Light.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2)
line level source
1 #ifndef __LIGHT_H_
2 #define __LIGHT_H_
3
4 #include <REG51.H>
5 #include <math.h> //Keil library
6 #include <stdio.h> //Keil library
7
8
9 #define SlaveAddress 0x46 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĴӵ<EFBFBD>ַ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ALT ADDRESS<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD>ͬ<EFBFBD>޸<EFBFBD>
10 //ALT ADDRESS<EFBFBD><EFBFBD><EFBFBD>Žӵ<EFBFBD>ʱ<EFBFBD><EFBFBD>ַΪ0x46<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>Դʱ<EFBFBD><EFBFBD>ַΪ0xB8
11
12
13 sbit SCL=P1^0; //IICʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><EFBFBD><EFBFBD>
14 sbit SDA=P1^1; //IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><EFBFBD><EFBFBD>
15
16
17 typedef unsigned short WORD;
18
19 unsigned char BUF[8]; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
20
21 int dis_data; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
22
23 void delay_nms(unsigned int k);
24 void InitLcd();
25 void Init_BH1750(void);
26 void WriteDataLCM(uchar dataW);
*** ERROR C141 IN LINE 26 OF Light.c: syntax error near 'dataW', expected ')'
27 void WriteCommandLCM(uchar CMD,uchar Attribc);
*** ERROR C141 IN LINE 27 OF Light.c: syntax error near 'CMD', expected ')'
28 void DisplayOneChar(uchar X,uchar Y,uchar DData);
*** ERROR C141 IN LINE 28 OF Light.c: syntax error near 'X', expected ')'
29 void conversion(uint temp_data);
*** ERROR C141 IN LINE 29 OF Light.c: syntax error near 'temp_data', expected ')'
30
31 void Single_Write_BH1750(uchar REG_Address); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*** ERROR C141 IN LINE 31 OF Light.c: syntax error near 'REG_Address', expected ')'
32 uchar Single_Read_BH1750(uchar REG_Address); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ڲ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*** ERROR C129 IN LINE 32 OF Light.c: missing ';' before 'Single_Read_BH1750'
33 void Multiple_Read_BH1750(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ȡ<EFBFBD>ڲ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
34 //------------------------------------
35 void Delay5us();
36 void Delay5ms();
37 void BH1750_Start(); //<EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
38 void BH1750_Stop(); //ֹͣ<EFBFBD>ź<EFBFBD>
39 void BH1750_SendACK(bit ack); //Ӧ<EFBFBD><EFBFBD>ACK
40 bit BH1750_RecvACK(); //<EFBFBD><EFBFBD>ack
41 void BH1750_Sendunsigned char(unsigned char dat); //IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>д
42 unsigned char BH1750_Recvunsigned char(); //IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڶ<EFBFBD>
43
44
45 //-----------------------------------
46
47 //*********************************************************
48 void conversion(uint temp_data) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʮ<EFBFBD><EFBFBD><EFBFBD>٣<EFBFBD>ǧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
49 {
C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 2
50 wan=temp_data/10000+0x30 ;
51 temp_data=temp_data%10000; //ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
52 qian=temp_data/1000+0x30 ;
53 temp_data=temp_data%1000; //ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
54 bai=temp_data/100+0x30;
55 temp_data=temp_data%100; //ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
56 shi=temp_data/10+0x30;
57 temp_data=temp_data%10; //ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
58 ge=temp_data+0x30;
59 }
60
61 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ**************************
62 void delay_nms(unsigned int k)
63 {
64 unsigned int i,j;
65 for(i=0;i<k;i++)
66 {
67 for(j=0;j<121;j++)
68 {;}}
69 }
70
71 /*******************************/
72 void WaitForEnable(void)
73 {
74 DataPort=0xff;
75 LCM_RS=0;LCM_RW=1;_nop_();
76 LCM_EN=1;_nop_();_nop_();
77 while(DataPort&0x80);
78 LCM_EN=0;
79 }
80 /*******************************/
81 void WriteCommandLCM(uchar CMD,uchar Attribc)
82 {
83 if(Attribc)WaitForEnable();
84 LCM_RS=0;LCM_RW=0;_nop_();
85 DataPort=CMD;_nop_();
86 LCM_EN=1;_nop_();_nop_();LCM_EN=0;
87 }
88 /*******************************/
89 void WriteDataLCM(uchar dataW)
90 {
91 WaitForEnable();
92 LCM_RS=1;LCM_RW=0;_nop_();
93 DataPort=dataW;_nop_();
94 LCM_EN=1;_nop_();_nop_();LCM_EN=0;
95 }
96 /***********************************/
97 void InitLcd()
98 {
99 WriteCommandLCM(0x38,1);
100 WriteCommandLCM(0x08,1);
101 WriteCommandLCM(0x01,1);
102 WriteCommandLCM(0x06,1);
103 WriteCommandLCM(0x0c,1);
104 }
105 /***********************************/
106 void DisplayOneChar(uchar X,uchar Y,uchar DData)
107 {
108 Y&=1;
109 X&=15;
110 if(Y)X|=0x40;
111 X|=0x80;
C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 3
112 WriteCommandLCM(X,0);
113 WriteDataLCM(DData);
114 }
115
116 /**************************************
117 <EFBFBD><EFBFBD>ʱ5΢<EFBFBD><EFBFBD>(STC90C52RC@12M)
118 <EFBFBD><EFBFBD>ͬ<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>ʱ<EFBFBD>ӹ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD>޸<EFBFBD>
119 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1T<EFBFBD><EFBFBD>MCUʱ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
120 **************************************/
121 void Delay5us()
122 {
123 _nop_();_nop_();_nop_();_nop_();
124 _nop_();_nop_();_nop_();_nop_();
125 _nop_();_nop_();_nop_();_nop_();
126 _nop_();_nop_();_nop_();_nop_();
127 }
128
129 /**************************************
130 <EFBFBD><EFBFBD>ʱ5<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(STC90C52RC@12M)
131 <EFBFBD><EFBFBD>ͬ<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD>
132 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1T<EFBFBD><EFBFBD>MCUʱ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
133 **************************************/
134 void Delay5ms()
135 {
136 WORD n = 560;
137
138 while (n--);
139 }
140
141 /**************************************
142 <EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
143 **************************************/
144 void BH1750_Start()
145 {
146 SDA = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
147 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
148 Delay5us(); //<EFBFBD><EFBFBD>ʱ
149 SDA = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>
150 Delay5us(); //<EFBFBD><EFBFBD>ʱ
151 SCL = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
152 }
153
154 /**************************************
155 ֹͣ<EFBFBD>ź<EFBFBD>
156 **************************************/
157 void BH1750_Stop()
158 {
159 SDA = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
160 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
161 Delay5us(); //<EFBFBD><EFBFBD>ʱ
162 SDA = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
163 Delay5us(); //<EFBFBD><EFBFBD>ʱ
164 }
165
166 /**************************************
167 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
168 <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>:ack (0:ACK 1:NAK)
169 **************************************/
170 void BH1750_SendACK(bit ack)
171 {
172 SDA = ack; //дӦ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
173 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 4
174 Delay5us(); //<EFBFBD><EFBFBD>ʱ
175 SCL = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
176 Delay5us(); //<EFBFBD><EFBFBD>ʱ
177 }
178
179 /**************************************
180 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
181 **************************************/
182 bit BH1750_RecvACK()
183 {
184 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
185 Delay5us(); //<EFBFBD><EFBFBD>ʱ
186 CY = SDA; //<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
187 SCL = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
188 Delay5us(); //<EFBFBD><EFBFBD>ʱ
189
190 return CY;
191 }
192
193 /**************************************
194 <EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
195 **************************************/
196 void BH1750_Sendunsigned char(unsigned char dat)
197 {
198 unsigned char i;
199
200 for (i=0; i<8; i++) //8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
201 {
202 dat <<= 1; //<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
203 SDA = CY; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
204 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
205 Delay5us(); //<EFBFBD><EFBFBD>ʱ
206 SCL = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
207 Delay5us(); //<EFBFBD><EFBFBD>ʱ
208 }
209 BH1750_RecvACK();
210 }
211
212 /**************************************
213 <EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
214 **************************************/
215 unsigned char BH1750_Recvunsigned char()
216 {
217 unsigned char i;
218 unsigned char dat = 0;
219
220 SDA = 1; //ʹ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
221 for (i=0; i<8; i++) //8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
222 {
223 dat <<= 1;
224 SCL = 1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
225 Delay5us(); //<EFBFBD><EFBFBD>ʱ
226 dat |= SDA; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
227 SCL = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
228 Delay5us(); //<EFBFBD><EFBFBD>ʱ
229 }
230 return dat;
231 }
232
233 //*********************************
234
235 void Single_Write_BH1750(uchar REG_Address)
C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 5
236 {
237 BH1750_Start(); //<EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
238 BH1750_Sendunsigned char(SlaveAddress); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>ź<EFBFBD>
239 BH1750_Sendunsigned char(REG_Address); //<EFBFBD>ڲ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>
240 // BH1750_Sendunsigned char(REG_data); //<EFBFBD>ڲ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
241 BH1750_Stop(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD>ź<EFBFBD>
242 }
243
244 //********<EFBFBD><EFBFBD><EFBFBD>ֽڶ<EFBFBD>ȡ*****************************************
245 /*
246 uchar Single_Read_BH1750(uchar REG_Address)
247 { uchar REG_data;
248 BH1750_Start(); //<EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
249 BH1750_Sendunsigned char(SlaveAddress); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>ź<EFBFBD>
250 BH1750_Sendunsigned char(REG_Address); //<EFBFBD><EFBFBD><EFBFBD>ʹ洢<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD>ʼ
251 BH1750_Start(); //<EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
252 BH1750_Sendunsigned char(SlaveAddress+1); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ+<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
253 REG_data=BH1750_Recvunsigned char(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
254 BH1750_SendACK(1);
255 BH1750_Stop(); //ֹͣ<EFBFBD>ź<EFBFBD>
256 return REG_data;
257 }
258 */
259 //*********************************************************
260 //
261 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BH1750<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
262 //
263 //*********************************************************
264 void Multiple_read_BH1750(void)
265
266 { uchar i;
267 BH1750_Start(); //<EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
268 BH1750_Sendunsigned char(SlaveAddress+1); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ+<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
269
270 for (i=0; i<3; i++) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>BUF
271 {
272 BUF[i] = BH1750_Recvunsigned char(); //BUF[0]<EFBFBD>洢0x32<EFBFBD><EFBFBD>ַ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
273 if (i == 3)
274 {
275
276 BH1750_SendACK(1); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>NOACK
277 }
278 else
279 {
280 BH1750_SendACK(0); //<EFBFBD><EFBFBD>ӦACK
281 }
282 }
283
284 BH1750_Stop(); //ֹͣ<EFBFBD>ź<EFBFBD>
285 Delay5ms();
286 }
287
288
289 //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>BH1750<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>pdf<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>****
290 void Init_BH1750()
291 {
292 Single_Write_BH1750(0x01);
293
294 }
295
296
297 #endif
C51 COMPILER V9.56.0.0 LIGHT 04/30/2022 20:06:41 PAGE 6
C51 COMPILATION COMPLETE. 0 WARNING(S), 6 ERROR(S)