?? main.lst
字號(hào):
C51 COMPILER V9.02 MAIN 11/08/2012 21:34:06 PAGE 1
C51 COMPILER V9.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN ..\output\main.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\source\main.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(..\outpu
-t\main.lst) OBJECT(..\output\main.obj)
line level source
1 /*
2 **********************************************************************************************************
-***
3 * Kingst-51
4 * Development board samples
5 *
6 * (c) Copyright 2009-2012, Kingst Studio
7 * All Rights Reserved
8 *
9 * http://www.kingst.org
10 * 文件名:main.c
11 * 描 述:工程主文件
12 * 版本號(hào):1.0.0
13 **********************************************************************************************************
-***
14 */
15 #define _MAIN_C
16 #include <string.h>
17 #include "config.h"
18 #include "main.h"
19 #include "UartCom.h"
20 #include "KeyBoard.h"
21 #include "Lcd1602.h"
22 #include "LedNumber.h"
23
24
25 /*
26 ********************************************************************************
27 * ----------------------- Local variables -------------------------------------
28 ********************************************************************************
29 */
30 /* 通信命令與其響應(yīng)函數(shù)的封裝結(jié)構(gòu) */
31 typedef struct _sComAnswer{
32 const uint8 *cmdstr; //命令字符串的指針
33 const uint8 cmdlen; //命令字符串的長(zhǎng)度
34 void (*answer) (uint8 *para, int8 len); //響應(yīng)函數(shù)的指針
35 } sComAnswer;
36
37 /* 蜂鳴器開關(guān)狀態(tài)的枚舉類型 */
38 typedef enum {
39 BUZZ_OFF, BUZZ_ON
40 } eBuzzSwitch;
41 static bit BuzzSwitch = BUZZ_OFF; //蜂鳴器開關(guān)狀態(tài)
42
43 static bit flag100ms = 0; //100ms定時(shí)間隔標(biāo)志
44 static bit staStopwatch = 1; //秒表狀態(tài)
45 static uint32 tmrStopwatch = 0; //秒表定時(shí)器
46
47
48 /*
49 ***************************************************************************************************
50 * ---------------------------------- Source codes ------------------------------------------------
51 ***************************************************************************************************
52 */
C51 COMPILER V9.02 MAIN 11/08/2012 21:34:06 PAGE 2
53 void ComHandle(void);
54 void Stopwatch(void);
55
56
57 /*
58 *==============================================================================
59 * 函數(shù)名:main
60 * 描 述:C語言main函數(shù),即程序執(zhí)行入口
61 *==============================================================================
62 */
63 void main (void)
64 {
65 1 /* 配置T0作為系統(tǒng)定時(shí)器 */
66 1 TMOD &= 0xF0;
67 1 TMOD |= 0x01;
68 1 ET0 = 1;
69 1 TR0 = 1;
70 1
71 1 UartComInit();
72 1 Lcd1602Init();
73 1 LedNumberInit();
74 1
75 1 /* 使能中斷,開始主循環(huán) */
76 1 EA = 1;
77 1 while(1) {
78 2 KeyHandle();
79 2 ComHandle();
80 2 Stopwatch();
81 2 }
82 1 }
83
84
85 /*
86 * 描 述:以下皆為串口命令響應(yīng)函數(shù),參數(shù)相同,功能見各自開頭的描述
87 * 輸 入:para - 串口命令之后附帶的參數(shù)指針
88 * len - 參數(shù)長(zhǎng)度
89 * 輸 出:無
90 */
91 /* 回傳命令,將命令碼之后的字符回傳給上位機(jī) */
92 void ComCallback(uint8 *para, int8 len)
93 {
94 1 if (len > 0) {
95 2 UartWrite(para, len);
96 2 }
97 1 else {
98 2 UartWrite("none\r\n", sizeof("none\r\n")-1);
99 2 }
100 1 }
101 /* 蜂鳴器開關(guān)命令,控制蜂鳴器鳴叫的開啟和關(guān)閉 */
102 void ComBuzzSwitch(uint8 *para, int8 len)
103 {
104 1 para++; //消除編譯器警告
105 1 len++; //消除編譯器警告
106 1 if (BuzzSwitch == BUZZ_OFF) {
107 2 BuzzSwitch = BUZZ_ON;
108 2 UartWrite("turn on\r\n", sizeof("turn on\r\n")-1);
109 2 }
110 1 else {
111 2 BuzzSwitch = BUZZ_OFF;
112 2 UartWrite("turn off\r\n", sizeof("turn off\r\n")-1);
113 2 }
114 1 }
C51 COMPILER V9.02 MAIN 11/08/2012 21:34:06 PAGE 3
115 /* 字符串顯示命令,在液晶上顯示命令碼之后的字符串 */
116 void ComShowString(uint8 *para, int8 len)
117 {
118 1 if ((*para==' ') && (len>1)) {
119 2 /* 顯示命令碼之后的字符 */
120 2 para++;
121 2 len--;
122 2 *(para+len) = '\0';
123 2 Lcd1602ShowStr(para, 0, 0);
124 2 /* 不滿一行時(shí)清楚屏幕后續(xù)字符位 */
125 2 if (len < 16) {
126 3 Lcd1602Clear(len, 0, 16-len);
127 3 }
128 2 UartWrite("complete\r\n", sizeof("complete\r\n")-1);
129 2 }
130 1 else {
131 2 UartWrite("error\r\n", sizeof("error\r\n")-1);
132 2 }
133 1 }
134
135 /*
136 * 函數(shù)名:ComHandle
137 * 描 述:串口通信命令解析處理函數(shù)
138 */
139 void ComHandle(void)
140 {
141 1 int8 i,len;
142 1 uint8 xdata buff[40];
143 1
144 1 /* 可響應(yīng)的所有命令列表 */
145 1 const sComAnswer code ca[] = {
146 1 {"callback", sizeof("callback")-1, ComCallback},
147 1 {"buzz switch", sizeof("buzz switch")-1, ComBuzzSwitch},
148 1 {"showstr", sizeof("showstr")-1, ComShowString}
149 1 };
150 1
151 1 /* 監(jiān)控串口接收狀態(tài) */
152 1 if (UartRxSta == RX_NONE) {
153 2 return;
154 2 }
155 1 UartRxSta = RX_NONE;
156 1
157 1 /* 接收完一幀命令后處理該命令 */
158 1 len = UartRead(buff, sizeof(buff));
159 1 for (i=0; i<ArraySize(ca); i++) {
160 2 if (memcmp(buff, ca[i].cmdstr, ca[i].cmdlen) == 0) {
161 3 ca[i].answer(buff+ca[i].cmdlen, len-ca[i].cmdlen);
162 3 return;
163 3 }
164 2 }
165 1
166 1 /* 命令不在支持列表中時(shí)返回"無效命令"信息 */
167 1 if (i >= ArraySize(ca)) {
168 2 UartWrite("invalid command\r\n", sizeof("invalid command\r\n")-1);
169 2 }
170 1 }
171
172
173 /*
174 * 函數(shù)名:Stopwatch
175 * 描 述:秒表功能函數(shù)
176 */
C51 COMPILER V9.02 MAIN 11/08/2012 21:34:06 PAGE 4
177 void Stopwatch(void)
178 {
179 1 if (flag100ms) {
180 2 flag100ms = 0;
181 2 /* 每隔100ms,秒表計(jì)數(shù)器+1 */
182 2 if (staStopwatch) {
183 3 tmrStopwatch++;
184 3 }
185 2 /* 秒表計(jì)數(shù)器當(dāng)前值顯示在數(shù)碼管上 */
186 2 LedNumberShow(tmrStopwatch, 1);
187 2 }
188 1 }
189 /*
190 * 函數(shù)名:ResetStopwatch
191 * 描 述:重置秒表,定時(shí)器歸零
192 */
193 void ResetStopwatch(void)
194 {
195 1 staStopwatch = 0;
196 1 tmrStopwatch = 0;
197 1 }
198 /*
199 * 函數(shù)名:KickStopwatch
200 * 描 述:?jiǎn)?dòng)/停止秒表計(jì)數(shù)
201 */
202 void KickStopwatch(void)
203 {
204 1 staStopwatch = ~staStopwatch;
205 1 }
206
207
208
209 /*
210 * 函數(shù)名:Timer0_ISR
211 * 描 述:Timer0定時(shí)中斷服務(wù)函數(shù)
212 */
213 void Timer0_ISR() interrupt 1
214 {
215 1 static uint8 t100ms = 0;
216 1
217 1 /* Timer1定時(shí)1ms */
218 1 TL0 = (uint8)((65535 - SYS_MCLK/1000) + 18);
219 1 TH0 = (uint8)(((65535 - SYS_MCLK/1000) + 18) >> 8);
220 1
221 1 /* 蜂鳴器控制 */
222 1 if (BuzzSwitch == BUZZ_ON) {
223 2 BUZZ_CTRL = 0;
224 2 }
225 1
226 1 /* 100ms定時(shí)標(biāo)志處理 */
227 1 t100ms++;
228 1 if (t100ms >= 100) {
229 2 t100ms = 0;
230 2 flag100ms = 1;
231 2 }
232 1
233 1 /* 其他需定時(shí)處理的函數(shù) */
234 1 KeyScan();
235 1 LedNumberScan();
236 1 UartRxMonitor(1);
237 1
238 1 BUZZ_CTRL = 1;
C51 COMPILER V9.02 MAIN 11/08/2012 21:34:06 PAGE 5
239 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 592 ----
CONSTANT SIZE = 115 ----
XDATA SIZE = ---- 40
PDATA SIZE = ---- ----
DATA SIZE = 5 6
IDATA SIZE = ---- ----
BIT SIZE = 3 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -