📄 timer1.lst
字号:
C51 COMPILER V9.01 TIMER1 05/06/2012 20:40:06 PAGE 1
C51 COMPILER V9.01, COMPILATION OF MODULE TIMER1
OBJECT MODULE PLACED IN timer1.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE timer1.c ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <stc90.h>
2 #include <hardware.h>
3 #include <intrins.h>
4 #include <eeprom.h>
5
6 unsigned char BeepTimes;
7 unsigned char KeyCode ;
8 //按键值
9 unsigned char KeyPressing1,KeyPressed1,KeyPressing2,KeyPressed2 ;
10 //按键持续按下的键盘码 按键点按的键盘码
11
12 unsigned char Key1PressingTime ,Key2PressingTime;
13 //按键持续按下的时间
14 bit IsKeyPressed ;
15 bit IsScanKeyTime ;
16 void keyScan(void);
17 void KeyProgram(void);
18
19
20 #define BLACK 0xff
21 //段码送BLACK 就是熄灭
22 code unsigned char Led7Code[]=
23 {
24 // 0 - - -9 //- //- // ~ //~ //_//_
25 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xbf,0xbf, 0xbf, 0xbf,0xbf,0xbf
26 };
27 //共阳 低电平点亮
28 code unsigned char LedBIt[4]=
29 {
30 0x7F,0XBF,0xDF,0xEF
31 }
32 ;
33 //位码口数据
34 unsigned char BitNum ;
35 //当前点亮第几个数码管
36 unsigned char DisplayData[4]=
37 {
38 0x00,0x00,0x00,0x00
39 }
40 ;
41 //4个数码管分别要显示的数据值
42 unsigned char IsFlash[4]=
43 {
44 0x00,0x00,0x00,0x00
45 }
46 ;
47 //4个数码管是否要闪烁 00表示不闪烁 01表示要闪烁
48 unsigned char Time5ms ;
49 //用于闪烁的5ms
50 bit IsFlashTime ;
51 //当前是否为闪烁时间。
52 bit IsDisplay1BitTime ;
53 //当前是否到了1bit的显示时间 就是5ms的时间
54 bit IsTime1s;
55 //bit IsGo;//时间是否跑。
C51 COMPILER V9.01 TIMER1 05/06/2012 20:40:06 PAGE 2
56 //unsigned char Time300ms ;
57
58 void Display(void);
59 unsigned char IsRun[6];
60 unsigned char TimeSave[6]=
61 {
62 0,0,0,0,0,0
63 };
64 unsigned char TimeDelay[6]=
65 {
66 0,0,0,0,0,0
67 };
68 //00-99表示秒为单位 100-199表示分为单位 范围为00-99
69 //6个延时控制引脚延时时间,0或者100则不需要延时或者已经到了延时时间 非0则需要延时控制。
70 unsigned char CurrLed;//当前显示第几路led开关的数据。
71 //unsigned char Time1000ms;
72 bit IsSetFirst;
73 #define SET1 1
74 #define SET2 2
75 #define SET3 3
76 #define SET4 4
77 #define SET5 5
78 #define SET6 6
79
80 #define WORK 0
81
82 unsigned char MachineState ;
83 //机器状态 倒计时状态 设置状态
84 ///开机为正常倒计时状态,全部数据为0 ,
85 //按下任何一个颜色按键 进入设置状态,屏幕显示相关设置值或者该颜色端口的当前倒计时的时间。
86 //10s后没有继续按键,则退出到正常显示。
87 //设置结束 则退出到正常显示 , 循环显示各个端口的倒计时时间。
88 //后台进行时间检测 时间到则自动修改输出电平。
89
90 void funUp(void);
91 void funDown(void);
92 void funLeft(void);
93 void funRight(void);
94 void funOk(void) ;
95 unsigned char Time60s;
96
97
98
99 main()
100 {
101 1 unsigned char i ;
102 1
103 1 PLed0=1 ;
104 1 PLed1=1 ;
105 1 PLed2=1 ;
106 1 PLed3=1 ;
107 1 PLed4=1 ;
108 1 PLed5=1 ;
109 1 //开机所有电路都是低电平。
110 1 TMOD=0X01 ;
111 1
112 1 TH0=0XeC ;
113 1 //5ms定时中断 4个数码管 所以每个数码管20ms刷新一次。
114 1 TL0=0X78 ;
115 1 ET0=1 ;
116 1 PT0=0 ;
117 1 //定时器0作为显示用 低优先级。
C51 COMPILER V9.01 TIMER1 05/06/2012 20:40:06 PAGE 3
118 1 TR0=1 ;
119 1
120 1 EA=1 ;
121 1
122 1
123 1
124 1 delay(60000);
125 1 for(i=0;i<6;i++)
126 1 {
127 2 TimeSave[i]=byte_read(0x4000+i);
128 2 TimeDelay[i]=TimeSave[i];
129 2 IsRun[i]=0 ;
130 2 }
131 1 MachineState=WORK ;
132 1 //开机后处于正常工作状态。
133 1 //但是时间不运行。
134 1
135 1 BeepTimes=2;//上电短响1次。
136 1 //开机显示4个0 直到按下任意按键。
137 1
138 1
139 1
140 1
141 1
142 1 while(1)
143 1 {
144 2 if(IsDisplay1BitTime==1)
145 2 {
146 3 IsDisplay1BitTime=0 ;
147 3 Display();
148 3 }
149 2 if((PKeyPort1!=0xff)||(PKeyPort2&0x0e)!=0x0e)
150 2 break ;
151 2 }
152 1
153 1
154 1 while(1)
155 1 {
156 2 //到了显示时间 执行显示子程序
157 2 if(IsDisplay1BitTime==1)
158 2 {
159 3 IsDisplay1BitTime=0 ;
160 3 Display();
161 3 }
162 2
163 2 // 50ms时间到 则检测一次按键 带消抖
164 2 if(IsScanKeyTime==1)
165 2 {
166 3 IsScanKeyTime=0 ;
167 3 KeyProgram();
168 3 }
169 2 //每一路时间-1,并检查 是否到了
170 2 if(MachineState==WORK)
171 2 {
172 3 //工作状态下 每秒钟执行一次这个代码 修改并检查每个时间是否到位。
173 3 unsigned char i ;
174 3 if((IsTime1s==1))
175 3 {
176 4 IsTime1s=0 ;
177 4 //每分钟以分为单位的线路自减1
178 4 if(++Time60s>=60)
179 4 {
C51 COMPILER V9.01 TIMER1 05/06/2012 20:40:06 PAGE 4
180 5 Time60s=0 ;
181 5 for(i=0;i<6;i++)
182 5 {
183 6 if(IsRun[i])
184 6 if((TimeDelay[i]>100))
185 6 TimeDelay[i]--;
186 6 }
187 5 }
188 4
189 4 //每秒钟以秒为单位的线路自减1
190 4 for(i=0;i<6;i++)
191 4 {
192 5 if(IsRun[i])
193 5 if((TimeDelay[i]>0)&&(TimeDelay[i]<100))
194 5 TimeDelay[i]--;
195 5 }
196 4
197 4 //倒计时部分代码
198 4 if(IsRun[0]==1)
199 4 {
200 5 if((TimeDelay[0]==0)||(TimeDelay[0]==100))
201 5 {
202 6 PLed0=1 ;
203 6 IsRun[0]=0 ;
204 6 if(TimeSave[0]!=0)
205 6 BeepTimes=2;
206 6 }
207 5 else
208 5 PLed0=0 ;
209 5 }
210 4 else
211 4 PLed0=1 ;
212 4 if(IsRun[1]==1)
213 4 {
214 5 if((TimeDelay[1]==0)||(TimeDelay[1]==100))
215 5 {
216 6 PLed1=1 ;
217 6 IsRun[1]=0 ;
218 6 if(TimeSave[1]!=0)
219 6 BeepTimes=4;
220 6
221 6 }
222 5 else PLed1=0 ;
223 5 }
224 4 else
225 4 PLed1=1 ;
226 4 if(IsRun[2]==1)
227 4 {
228 5 if((TimeDelay[2]==0)||(TimeDelay[2]==100))
229 5 {
230 6 PLed2=1 ;
231 6 IsRun[2]=0 ;
232 6 if(TimeSave[2]!=0)
233 6 BeepTimes=6;
234 6 }
235 5 else PLed2=0 ;
236 5 }
237 4 else
238 4 PLed2=1 ;
239 4 if(IsRun[3]==1)
240 4 {
241 5 if((TimeDelay[3]==0)||(TimeDelay[3]==100))
C51 COMPILER V9.01 TIMER1 05/06/2012 20:40:06 PAGE 5
242 5 {
243 6 PLed3=1 ;
244 6 IsRun[3]=0 ;
245 6 if(TimeSave[3]!=0)
246 6 BeepTimes=8;
247 6 }
248 5 else PLed3=0 ;
249 5 }
250 4 else
251 4 PLed3=1 ;
252 4 if(IsRun[4]==1)
253 4 {
254 5 if((TimeDelay[4]==0)||(TimeDelay[4]==100))
255 5 {
256 6 PLed4=1 ;
257 6 IsRun[4]=0 ;
258 6 if(TimeSave[4]!=0)
259 6 BeepTimes=10;
260 6 }
261 5 else PLed4=0 ;
262 5 }
263 4 else
264 4 PLed4=1 ;
265 4 if(IsRun[5]==1)
266 4 {
267 5 if((TimeDelay[5]==0)||(TimeDelay[5]==100))
268 5 {
269 6 PLed5=1 ;
270 6 IsRun[5]=0 ;
271 6 if(TimeSave[5]!=0)
272 6 BeepTimes=12;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -