1 Star 0 Fork 1

LeeWei/SnowLight_STC8

forked from OvO/SnowLight_STC8 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
touch.LST 15.40 KB
一键复制 编辑 原始数据 按行查看 历史
OvO 提交于 2024-02-01 16:18 . build project snow light
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 1
C51 COMPILER V9.01, COMPILATION OF MODULE TOUCH
OBJECT MODULE PLACED IN touch.OBJ
COMPILER INVOKED BY: F:\study\Keil5\C51\C51\BIN\C51.EXE touch.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "reg51.h"
2 #include "intrins.h"
3
4 sfr P0M1 = 0x93;
5 sfr P0M0 = 0x94;
6 sfr P1M1 = 0x91;
7 sfr P1M0 = 0x92;
8 sfr P2M1 = 0x95;
9 sfr P2M0 = 0x96;
10 sfr P3M1 = 0xb1;
11 sfr P3M0 = 0xb2;
12 sfr P4M1 = 0xb3;
13 sfr P4M0 = 0xb4;
14 sfr P5M1 = 0xc9;
15 sfr P5M0 = 0xca;
16 sfr AUXR = 0x8E;
17 sfr INTCLKO = 0x8f;
18 #define EX4 0x40
19
20
21 sbit LED1 = P3^2;
22 sbit LED2 = P3^3;
23 sbit LED5 = P3^1;
24 sbit IN_TOUCH = P3^0;
25
26 sfr P5 = 0xC8;
27 sbit LED3 = P5^4;
28 sbit LED4 = P5^5;
29
30
31 #define IDL 0x01 //PCON.0
32 #define PD 0x02 //PCON.1
33
34 char flag_mode[5]={0};
35 char mode=0;
36 char run_flag=1;
37 int cnt=0;
38 int cnt_t=0;
39 int i=0;
40 int n=1;
41 int time_ms;
42 int pwm_change_time=0;
43 void LEDn_No(int LED_n);
44 void LEDn_Off(int LED_n);
45 void LED_PWM_Set(int LED_n,int PWM_Percentage);
46 void light_mode_1(void) ;
47 //void TM1_Isr() interrupt 3 //1ms定时器
48 //{
49 //
50 // cnt_t++;
51 // if(cnt_t==3000)
52 // {
53 //
54 // if(IN_TOUCH==0)
55 // {
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 2
56 // run_flag=-run_flag;
57 //
58 // }
59 // cnt_t=0;
60 // TR1 = 0; //
61 // ET1=0;
62 // }
63 //
64 //}
65
66 void TM0_Isr() interrupt 1
67 { //cnt 跟pwm改变时间会冲突
68 1
69 1 if(flag_mode[1]==1) //模式1
70 1 {
71 2 cnt++;
72 2 time_ms=1500;//1s亮一个
73 2 if(cnt>100)
74 2 {
75 3 cnt=0;
76 3 pwm_change_time++;
77 3 }
78 2 if(n<=5)
79 2 {
80 3 if(pwm_change_time<(time_ms/10))
81 3 i=(int)(pwm_change_time/(time_ms/1000));
82 3 switch(n)
83 3 {
84 4 case 1:LED_PWM_Set(1,i);break;
85 4 case 2:LED_PWM_Set(1,100),LED_PWM_Set(2,i);break;
86 4 case 3:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,i);break;
87 4 case 4:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,100),LED_PWM_Set(4,i);break;
88 4 case 5:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,100),LED_PWM_Set(4,100),LED_PWM_Set(5,i);brea
-k;
89 4 default:break;
90 4 }
91 3 }
92 2 if(n>5)
93 2 { if(pwm_change_time<(time_ms/10))
94 3 i=100-(int)(pwm_change_time/(time_ms/1000));
95 3 switch(n)
96 3 {
97 4 case 6:LED_PWM_Set(5,i);break;
98 4 case 7:LED_PWM_Set(5,0),LED_PWM_Set(4,i);break;
99 4 case 8:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,i);break;
100 4 case 9:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,0),LED_PWM_Set(2,i);break;
101 4 case 10:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,0),LED_PWM_Set(2,0),LED_PWM_Set(1,i);break;
102 4 default:break;
103 4 }
104 3 }
105 2
106 2
107 2 if(pwm_change_time>(time_ms/10))
108 2 {
109 3 pwm_change_time=0;
110 3 i=0;
111 3 n++;
112 3 }
113 2 if(n>10)
114 2 n=1;
115 2
116 2 }
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 3
117 1
118 1
119 1
120 1
121 1 if(flag_mode[2]==1) //模式2
122 1 {
123 2 //time_ms=3000; //可设定几秒
124 2 cnt++;
125 2 if(cnt>100)
126 2 {
127 3 cnt=0;
128 3 pwm_change_time++;
129 3 }
130 2 if(pwm_change_time<(time_ms/10))
131 2 i=(int)(pwm_change_time/(time_ms/1000));
132 2 if(pwm_change_time>=(time_ms/10))
133 2 i=200-(int)(pwm_change_time/(time_ms/1000));
134 2
135 2 LED_PWM_Set(1,i);
136 2 LED_PWM_Set(2,i);
137 2 LED_PWM_Set(3,i);
138 2 LED_PWM_Set(4,i);
139 2 LED_PWM_Set(5,i);
140 2 if(pwm_change_time>(time_ms/5))
141 2 {
142 3 pwm_change_time=0;
143 3 i=0;
144 3 }
145 2 }
146 1
147 1 if(flag_mode[3]==1) //模式3
148 1 {
149 2 cnt++;
150 2 time_ms=100;
151 2 if(cnt>100)
152 2 {
153 3 cnt=0;
154 3 pwm_change_time++;
155 3 }
156 2 if(pwm_change_time<time_ms/10)
157 2 {
158 3 LED_PWM_Set(1,10);
159 3 LED_PWM_Set(2,10);
160 3 LED_PWM_Set(3,10);
161 3 LED_PWM_Set(4,10);
162 3 LED_PWM_Set(5,10);
163 3 }
164 2 else
165 2 {
166 3 LED_PWM_Set(1,0);
167 3 LED_PWM_Set(2,0);
168 3 LED_PWM_Set(3,0);
169 3 LED_PWM_Set(4,0);
170 3 LED_PWM_Set(5,0);
171 3 }
172 2 if(pwm_change_time>time_ms/5)
173 2 pwm_change_time=0;
174 2 }
175 1
176 1 }
177
178
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 4
179 void Delay_500ms(void) //@11.0592MHz 500ms
180 {
181 1 unsigned char data i, j;
182 1
183 1 _nop_();
184 1 _nop_();
185 1 i = 6;
186 1 j = 93;
187 1 do
188 1 {
189 2 while (--j);
190 2 } while (--i);
191 1 }
192
193 void Delay2500ms(void) //@11.0592MHz
194 {
195 1 unsigned char data i, j, k;
196 1
197 1 _nop_();
198 1 _nop_();
199 1 i = 106;
200 1 j = 15;
201 1 k = 131;
202 1 do
203 1 {
204 2 do
205 2 {
206 3 while (--k);
207 3 } while (--j);
208 2 } while (--i);
209 1 }
210 //触摸检测中断
211 void INT4_Isr() interrupt 16
212 {
213 1 //1000微秒@11.0592MHz 启动定时器1
214 1 if(run_flag==1)
215 1 {
216 2 if(IN_TOUCH==0)
217 2 {Delay_500ms();
218 3 if(IN_TOUCH==0)
219 3
220 3 mode++;
221 3 }
222 2 if(mode>6)
223 2 mode=1;
224 2 }
225 1
226 1 if(run_flag==0)
227 1 {
228 2 if(IN_TOUCH==0)
229 2
230 2 {
231 3 Delay2500ms();
232 3 if(IN_TOUCH==0)
233 3 {
234 4 run_flag=1;
235 4
236 4 LED1=0;
237 4 Delay_500ms();
238 4 LED1=1;
239 4 mode=1;
240 4 }
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 5
241 3 }
242 2 }
243 1
244 1 }
245
246 void main()
247 {
248 1 void LEDn_No(int LED_n);
249 1 void LEDn_Off(int LED_n);
250 1 void LED_PWM_Set(int LED_n,int PWM_Percentage);
251 1
252 1 P3M0 = 0x00;
253 1 P3M1 = 0x00;
254 1 P5M0 = 0x00;
255 1 P5M1 = 0x00;
256 1
257 1 INTCLKO = EX4; //使能 INT4 中断
258 1
259 1
260 1 //定时器0用于pwm以及模式
261 1 TMOD = 0x00; //模式0
262 1 AUXR = 0x80; //1T模式
263 1 TL0 = 0xAE; //设置定时初始值 10khz T=100us
264 1 TH0 = 0xFB;
265 1 TR0 = 1; //启动定时器
266 1 ET0 = 1; //使能定时器中断
267 1 //定时器1用于计时
268 1 // AUXR |= 0x40; //定时器时钟1T模式
269 1 // TL1 = 0xCD; //设置定时初始值 1ms
270 1 // TH1 = 0xD4; //设置定时初始值
271 1 // TR1 = 1; //定时器1开始计
272 1
273 1 // ET1 = 1;
274 1 EA = 1;
275 1
276 1 LED1=1;
277 1 LED2=1;
278 1 LED3=1;
279 1 LED4=1;
280 1 LED5=1;
281 1 while (1)
282 1 {
283 2 // if(run_flag==1)
284 2 // {
285 2
286 2 switch(mode)
287 2 {
288 3 case 0:LED1=1,LED2=1,LED3=1,LED4=1,LED5=1; break;
289 3 case 1:flag_mode[0]=0,flag_mode[1]=1,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=0;TR0=1;break;
290 3 case 2:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=1,flag_mode[3]=0,flag_mode[4]=0;TR0=1;break;
291 3 case 3:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=1,flag_mode[4]=0;TR0=1;break;
292 3 case 4:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=1,TR0=0;light_mode_1();br
-eak;
293 3 // case 5:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=1,TR0=0;light_mode_1();
-break;
294 3 default: LED1=1,LED2=1,LED3=1,LED4=1,LED5=1,run_flag=0,cnt=0,n=0,PCON = PD;break;
295 3
296 3 }
297 2 //}
298 2
299 2
300 2 }
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 6
301 1
302 1
303 1
304 1 }
305
306
307
308 void LEDn_No(int LED_n) //led亮
309 {
310 1 switch(LED_n)
311 1 {
312 2 case 1:LED1=0;break;
313 2 case 2:LED2=0;break;
314 2 case 3:LED3=0;break;
315 2 case 4:LED4=0;break;
316 2 case 5:LED5=0;break;
317 2 default: break;
318 2 }
319 1 }
320
321 void LEDn_Off(int LED_n) //led灭
322 {
323 1 switch(LED_n)
324 1 {
325 2 case 1:LED1=1;break;
326 2 case 2:LED2=1;break;
327 2 case 3:LED3=1;break;
328 2 case 4:LED4=1;break;
329 2 case 5:LED5=1;break;
330 2 default: break;
331 2 }
332 1 }
333
334 void LED_PWM_Set(int LED_n,int PWM_Percentage) //led的pwm占空比控制
335 {
336 1 if(cnt<PWM_Percentage) //0-100
337 1 LEDn_No(LED_n);
338 1 else
339 1 LEDn_Off(LED_n);
340 1 // if(cnt>100)
341 1 // {
342 1 // cnt=0;
343 1 // }
344 1
345 1 }
346
347 void light_mode_1(void) //常亮
348 {
349 1 LED1=0,LED2=0,LED3=0,LED4=0,LED5=0;
350 1 }
351
352
353
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1427 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 19 ----
IDATA SIZE = ---- ----
C51 COMPILER V9.01 TOUCH 02/01/2024 23:27:29 PAGE 7
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/opwq/snow-light_-stc8.git
[email protected]:opwq/snow-light_-stc8.git
opwq
snow-light_-stc8
SnowLight_STC8
master

搜索帮助