📄 main.lst
字号:
C51 COMPILER V8.08 MAIN 01/17/2009 15:09:00 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*******************************************************
2
3
4 ******************************************************/
5
6 #include "STC516.h"
7
8 #include "OS_core.h"
9 #include "task_switch.h"
10 #include "MAIN.H"
11
12 #include "UART.H"
13
14 //#include<reg51.h>
15
16 //#include <at89c52.h>
17
18 #include <STDIO.H>
19 #include <absacc.h>
20 #define uchar unsigned char
21 #define uint unsigned int
22
23
24 #define shuzi P0
25 #define weixuan P2
26 #define key P1
27 #define TIME 2
28
29 code uchar sz[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
30 uchar keybit;
31 int data1,data2,data3,data4;
32
33 static uchar i1,i2,i3,i4,i5,i6,i7,i8;
34
35
36 volatile unsigned char second,minute,hour; //系统时钟
37
38 volatile unsigned char Msg_1_Receiver=0; //初始化无任务接收此消息
39
40 /////////////////////////////////////空闲任务,优先级最低///////////////////////////////////
41 ///////////////////////////////////// 注意,永远不要挂起空闲任务 //////////////////////////
42 ////////////////////////// 并且空闲任务必须第一个被创建,且优先级最低 /////////////////////
43 ////////////////在os_core.h中使用#define CPU_STAT后 可以用来统计CPU的使用率 ////////////////
44 void task_idle(void)
45 {
46 1 //static unsigned long int i; //使用static申明局部变量,避免变量被分配到相同的地址
47 1
48 1 #ifdef CPU_STAT //如果需要CPU使用率统计
49 1
50 1 static unsigned long int total_count; //则声明相应变量
51 1 static unsigned long int current_count;
52 1 static unsigned char time,j;
53 1
54 1 total_count=0;
55 1 current_count=0;
C51 COMPILER V8.08 MAIN 01/17/2009 15:09:00 PAGE 2
56 1
57 1
58 1 time=(unsigned char)OS_Run_Time; //初始化time
59 1
60 1 while(time==(unsigned char)OS_Run_Time); //等待,直到OS_Run_Time的值改变了
61 1
62 1 time=(unsigned char)OS_Run_Time; //保存这时的时间
63 1
64 1 while(1)
65 1 {
66 2 //此时所有任务都处于挂起状态,由统计这时的CPU资源
67 2 //使用跟下面一样的结构,使其生成一样的代码,提高准确性
68 2 if((unsigned char)OS_Run_Time-time>=100) //共统计1秒钟的时间
69 2 {
70 3 //这条语句的作用,是为了保证上下代码结构一样,让编译器生成一样结构的代码
71 3 j=(total_count-current_count)/(total_count);
72 3 break;
73 3 }
74 2 total_count++; //累加CPU资源
75 2 }
76 1
77 1
78 1 for(j=0;j<MAX_TASK;j++) //将挂起的任务唤醒
79 1 {
80 2 OS_pcb[j].Suspend=0;
81 2 }
82 1 #endif
83 1
84 1 while(1) //死循环
85 1 {
86 2
87 2 #ifdef CPU_STAT //如果需要统计CPU使用率
88 2 while(1)
89 2 {
90 3 //测量100个时钟节拍的CPU资源,然后跟没有其它任务运行时的CPU资源比较
91 3 if((unsigned char)OS_Run_Time-time>=100)
92 3 {
93 4 //计算比率
94 4 // CPU使用率越高,则本任务运行的时间就越短,current_count的值就越小
95 4 //total_count与current_count的差,占total_count的比例,就是CPU使用率
96 4 //最后结果被放大了100倍,保存在j中。
97 4 j=(total_count-current_count)/(total_count/100);
98 4
99 4
100 4 //将计算结果通过消息发送给接收消息的任务显示
101 4 OS_Send_Msg(OS_Current_ID,Msg_1_Receiver,j);
102 4
103 4 current_count=0; //清0
104 4 time=(unsigned char)OS_Run_Time;
105 4 while(time==(unsigned char)OS_Run_Time);
106 4 time=(unsigned char)OS_Run_Time; //重新开始统计
107 4 break;
108 4 }
109 3 current_count++; //累加CPU资源
110 3 }
111 2 #endif
112 2
113 2 }
114 1 }
115 void task_4(void)
116
117 {
C51 COMPILER V8.08 MAIN 01/17/2009 15:09:00 PAGE 3
118 1
119 1 while(1)
120 1 {
121 2 get_printer(); //申请打印机资源,显示系统时钟
122 2 //prints(" System Time:",0);
123 2 send_a_byte(i8); //显示小时
124 2 send_a_byte(i7);
125 2 send_a_byte(i6);
126 2 send_a_byte(i5);
127 2
128 2
129 2
130 2 give_up_printer(); //让出打印机使用权
131 2 OS_Delay(40);
132 2
133 2 }
134 1 }
135 //////////////////////////////////////////////////////////////////////////////////////////////
136
137 ///////////////////////////////////// 任务1 //////////////////////////
138 void task_1(void)
139 {
140 1
141 1
142 1
143 1
144 1 while(1)
145 1 {
146 2 weixuan=0x01;
147 2 shuzi=sz[data1/10];
148 2 OS_Delay(TIME);
149 2 weixuan=0x02;
150 2 shuzi=sz[data1%10];
151 2 OS_Delay(TIME);
152 2
153 2 weixuan=0x04;
154 2 shuzi=sz[data2/10];
155 2 OS_Delay(TIME);
156 2 weixuan=0x08;
157 2 shuzi=sz[data2%10];
158 2 OS_Delay(TIME);
159 2
160 2 weixuan=0x10;
161 2 shuzi=sz[data3/10];
162 2 OS_Delay(TIME);
163 2 weixuan=0x20;
164 2 shuzi=sz[data3%10];
165 2 OS_Delay(TIME);
166 2
167 2 weixuan=0x40;
168 2 shuzi=sz[data4/10];
169 2 OS_Delay(TIME);
170 2 weixuan=0x80;
171 2 shuzi=sz[data4%10];
172 2 OS_Delay(TIME);
173 2 shuzi=0x00;
174 2 weixuan=0x00;
175 2
176 2 }
177 1
178 1
179 1 }
C51 COMPILER V8.08 MAIN 01/17/2009 15:09:00 PAGE 4
180 ////////////////////////////////////////////////////////////////////////////////////////////////
181
182 unsigned char refresh_time=20; //用来调整LED1的闪烁快慢及杠的转动速度
183 ///////////////////////////////////// 任务2 ////////////////////////////////////
184 void task_2(void)
185 {
186 1
187 1 uchar a;
188 1
189 1 while(1)
190 1 {
191 2
192 2 a=key&0x0f;
193 2 if(a!=0x00)
194 2 {
195 3 OS_Delay(150);
196 3 if(a==0x0e) {keybit=1; while((key&0x0f)==0x0e); }
197 3 else if(a==0x0d) {keybit=2; while((key&0x0f)==0x0d); }
198 3 else if(a==0x0b) {keybit=3; while((key&0x0f)==0x0b); }
199 3 else if(a==0x07) {keybit=4; while((key&0x0f)==0x07); }
200 3 else keybit=0;
201 3 }
202 2
203 2
204 2
205 2
206 2 }
207 1 }
208 ////////////////////////////////////////////////////////////////////////////////////////////////
209
210 ///////////////////////////////////// 任务3 //////////////////////////
211 void task_3(void)
212 {
213 1 while(1)
214 1 {
215 2
216 2 if(keybit!=0)
217 2 {
218 3 if(keybit==1) {keybit=0;data1++;if(data1==100)data1=0;}
219 3 else if(keybit==2) {keybit=0;data2++;if(data2==100)data2=0;}
220 3 else if(keybit==3) {keybit=0;data3++;if(data3==100)data3=0;}
221 3 else if(keybit==4) {keybit=0;data4++;if(data4==100)data1=0;}
222 3 }
223 2 // while(com8255C==0xff);
224 2
225 2
226 2 //OS_Delay(50);
227 2
228 2
229 2
230 2 //OS_Delay(1);
231 2
232 2
233 2 }
234 1 }
235 ////////////////////////////////////////////////////////////////////////////////////////////////
236
237 unsigned char msg; //保存消息用的一个变量,也可以使用一个结构体来处理更多的信息
238
239 ///////////////////////////////////// 任务4 //////////////////////////////////////////////////
240
241 ////////////////////////////////////////////////////////////////////////////////////////////////
C51 COMPILER V8.08 MAIN 01/17/2009 15:09:00 PAGE 5
242
243
244 ///////////////////////////////////主函数//////////////////////////////////////////////////////
245 void main(void)
246 {
247 1 EA=0; //关中
248 1 ET2=1; //定时器2开中断
249 1
250 1 T2CON=0x00; //定时器自动重装模式
251 1 T2MOD=0x00; //如果提示这里编译通不过,可将本行删除;或自己将定义添上
252 1 //TH2 = 0xFF;
253 1 // TL2 = 0xEE; //因为keil自带的at89x52.h中没有T2MOD的定义
254 1 //RCAP2H=0xB1;
255 1 //RCAP2L=0xE0; //定时时间为10ms
256 1
257 1 RCAP2H=0xf5;
258 1 RCAP2L=0xEE; //定时时间为10ms
259 1
260 1 data1=data2=data3=data4=0;
261 1
262 1 UART_init(); //初始化串口为9600波特率
263 1
264 1
265 1 OS_Init(); //OS初始化
266 1
267 1
268 1 //参数意义 优先级 任务入口地址 消息指针
269 1 OS_Task_Create(255,(unsigned int)(&task_idle),0); //任务0初始化
270 1
271 1 // OS_Task_Create(3,(unsigned int)(&task_1),0); //任务1初始化
272 1
273 1 OS_Task_Create(2,(unsigned int)(&task_2),0); //任务2初始化
274 1 OS_Task_Create(1,(unsigned int)(&task_3),0); //任务3初始化
275 1 OS_Task_Create(0,(unsigned int)(&task_1),(unsigned char)&msg); //任务4初始化
276 1 // OS_Task_Create(4,(unsigned int)(&task_5),0); //任务1初始化
277 1
278 1 OS_Start(); //OS开始调度
279 1 //死循环。定时器中断发生后,任务开始调度
280 1
281 1 }
282
283
284
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 856 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 33 1
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -