?? 485.lst
字號:
C51 COMPILER V6.12 485 03/19/2008 09:25:24 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE 485
OBJECT MODULE PLACED IN .\485.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\485.c DEBUG OBJECTEXTEND
stmt level source
1 #ifndef __485_C__
2 #define __485_C__
3
4 #include <AT89X51.H>
5 #include <string.h>
6
7 #define unsigned char uchar;
8 #define unsigned int uint;
*** WARNING 317 IN LINE 8 OF .\485.c: redefinition of macro 'unsigned'
9
10 /* 通信命令 */
11 #define __ACTIVE_ 0x01 ; // 主機詢問從機是否存在
12 #define __GETDATA_ 0x02; // 主機發送讀設備請求
13 #define __OK_ 0x03 ; // 從機應答
14 #define __STATUS_ 0x04; // 從機發送設備狀態信息
15
16 #define __MAXSIZE 0x08; // 緩沖區長度
17
18
19 #define __ERRLEN 12; // 任何通信幀長度超過12則表示出錯
20
21 uchar; dev; // 該字節用于保存本機設備號
22 uchar; dbuf[__MAXSIZE]; // 該緩沖區用于保存設備狀態信息
*** ERROR C141 IN LINE 22 OF .\485.C: syntax error near ';', expected ']'
23
24
25 sbit M_DE = P1^0; // 驅動器使能,1有效
26 sbit M_RE = P1^1; // 接收器使能,0有效
27
28 void get_status(); // 調用該函數獲得設備狀態信息,函數代碼未給出
29 void send_data(uchar type, uchar len, uchar *buf); // 發送數據幀
*** ERROR C141 IN LINE 29 OF .\485.C: syntax error near 'type', expected ')'
30 bit recv_cmd(uchar *type); // 接收主機命令,主機請求僅包含命令信息
*** ERROR C141 IN LINE 30 OF .\485.C: syntax error near '*', expected ')'
31 void send_byte(uchar da); // 該函數發送一幀數據中的一個字節,由send_data()函數調用
*** ERROR C141 IN LINE 31 OF .\485.C: syntax error near 'da', expected ')'
32
33 void main()
34 {
35 1 uchar type;
*** ERROR C141 IN LINE 35 OF .\485.C: syntax error near 'type'
*** ERROR C202 IN LINE 35 OF .\485.C: 'type': undefined identifier
36 1 uchar len;
*** ERROR C141 IN LINE 36 OF .\485.C: syntax error near 'len'
*** ERROR C202 IN LINE 36 OF .\485.C: 'len': undefined identifier
37 1
38 1 /* 系統初始化 */
39 1 P1 = 0xff; // 讀取本機設備號
40 1 dev = (P1>>2);
41 1 TMOD = 0x20; // 定時器T1使用工作方式2
42 1 TH1 = 250; // 設置初值
43 1 TL1 = 250;
44 1 TR1 = 1; // 開始計時
45 1 PCON = 0x80; // SMOD = 1
46 1 SCON = 0x50; // 工作方式1,波特率9600bps,允許接收
C51 COMPILER V6.12 485 03/19/2008 09:25:24 PAGE 2
47 1 ES = 0; // 關閉串口中斷
48 1 IT0 = 0; // 外部中斷0使用電平觸發模式
49 1 EX0 = 1; // 開啟外部中斷0
50 1 EA = 1; // 開啟中斷
51 1
52 1 /* 主程序流程 */
53 1 while(1) // 主循環
54 1 {
55 2 if(recv_cmd(&type) == 0) // 發生幀錯誤或幀地址與本機地址不符,丟棄當前幀后返回
*** ERROR C202 IN LINE 55 OF .\485.C: 'type': undefined identifier
56 2 continue;
57 2 switch(type)
*** ERROR C202 IN LINE 57 OF .\485.C: 'type': undefined identifier
58 2 {
59 3 case __ACTIVE_: // 主機詢問從機是否存在
*** ERROR C141 IN LINE 59 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 59 OF .\485.C: syntax error near ':'
60 3 send_data(__OK_, 0, dbuf); // 發送應答信息,這里buf的內容并未用到
*** ERROR C141 IN LINE 60 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 60 OF .\485.C: syntax error near ','
*** ERROR C202 IN LINE 60 OF .\485.C: 'dbuf': undefined identifier
*** ERROR C141 IN LINE 60 OF .\485.C: syntax error near ')'
61 3 break;
62 3 case __GETDATA_:
*** ERROR C141 IN LINE 62 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 62 OF .\485.C: syntax error near ':'
63 3 len = strlen(dbuf);
64 3 send_data(__STATUS_, len, dbuf); // 發送設備狀態信息
*** ERROR C141 IN LINE 64 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 64 OF .\485.C: syntax error near ','
*** ERROR C202 IN LINE 64 OF .\485.C: 'len': undefined identifier
*** ERROR C141 IN LINE 64 OF .\485.C: syntax error near ')'
65 3 break;
66 3 default:
67 3 break; // 命令類型錯誤,丟棄當前幀后返回
68 3 }
69 2 }
70 1 }
71
72 void READSTATUS() interrupt 0 using 1 // 產生外部中斷0時表示設備狀態發生改變,該函數使用寄存器組1
73 {
74 1 get_status(); // 獲得設備狀態信息,并將其存入dbuf指向的存儲區,數據最后一字節置0表示數據結束
75 1 }
76
77 /* 該函數接收一幀數據并進行檢測,無論該幀是否錯誤,函數均會返回
78 * 函數參數type保存接收到的命令字
79 * 當接收到數據幀錯誤或其地址位不為0時(非主機發送幀),函數返回0,反之返回1
80 */
81 bit recv_cmd(uchar *type)
*** ERROR C141 IN LINE 81 OF .\485.C: syntax error near '*', expected ')'
82 {
83 1 bit db = 0; // 當接收到的上一個字節為0xdb時,該位置位
84 1 bit c0 = 0; // 當接收到的上一個字節為0xc0時,該位置位
85 1 uchar data_buf[__ERRLEN]; // 保存接收到的幀
*** ERROR C141 IN LINE 85 OF .\485.C: syntax error near 'data_buf'
*** ERROR C141 IN LINE 85 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 85 OF .\485.C: syntax error near ']'
86 1 uchar tmp;
*** ERROR C141 IN LINE 86 OF .\485.C: syntax error near 'tmp'
*** ERROR C202 IN LINE 86 OF .\485.C: 'tmp': undefined identifier
87 1 uchar ecc = 0;
*** ERROR C141 IN LINE 87 OF .\485.C: syntax error near 'ecc'
C51 COMPILER V6.12 485 03/19/2008 09:25:24 PAGE 3
*** ERROR C202 IN LINE 87 OF .\485.C: 'ecc': undefined identifier
88 1 uchar i;
*** ERROR C141 IN LINE 88 OF .\485.C: syntax error near 'i'
*** ERROR C202 IN LINE 88 OF .\485.C: 'i': undefined identifier
89 1
90 1 M_DE = 0; // 置發送禁止,接收允許
91 1 M_RE = 0;
92 1
93 1 /* 接收一幀數據 */
94 1 i = 0;
*** ERROR C202 IN LINE 94 OF .\485.C: 'i': undefined identifier
95 1 while(!c0) // 循環直至幀接收完畢
96 1 {
97 2 RI = 0;
98 2 while(!RI);
99 2 tmp = SBUF;
*** ERROR C202 IN LINE 99 OF .\485.C: 'tmp': undefined identifier
100 2 RI = 0;
101 2 if(db == 1) // 接收到的上一個字節為0xdb
102 2 {
103 3 switch(tmp)
*** ERROR C202 IN LINE 103 OF .\485.C: 'tmp': undefined identifier
104 3 {
105 4 case 0xdd:
106 4 data_buf[i] = 0xdb; // 0xdbdd表示0xdb
*** ERROR C202 IN LINE 106 OF .\485.C: 'i': undefined identifier
107 4 ecc = ecc^0xdb;
*** ERROR C202 IN LINE 107 OF .\485.C: 'ecc': undefined identifier
108 4 db = 0;
109 4 break;
110 4 case 0xdc
111 4 data_buf[i] = 0xc0; // 0xdbdc表示0xc0
*** ERROR C141 IN LINE 111 OF .\485.C: syntax error near 'data_buf'
*** ERROR C202 IN LINE 111 OF .\485.C: 'i': undefined identifier
112 4 ecc = ecc^0xc0;
*** ERROR C202 IN LINE 112 OF .\485.C: 'ecc': undefined identifier
113 4 db = 0;
114 4 break;
115 4 default
116 4 return 0; // 幀錯誤,返回
*** ERROR C141 IN LINE 116 OF .\485.C: syntax error near 'return', expected ':'
117 4 }
118 3 i++;
*** ERROR C202 IN LINE 118 OF .\485.C: 'i': undefined identifier
119 3 }
120 2 switch(tmp) // 正常情況
*** ERROR C202 IN LINE 120 OF .\485.C: 'tmp': undefined identifier
121 2 {
122 3 case 0xc0: // 幀結束
123 3 c0 = 1;
124 3 break;
125 3 case 0xdb: // 檢測到轉義字符
126 3 db = 1;
127 3 break;
128 3 default: // 普通數據
129 3 data_buf[i] = tmp; // 保存數據
*** ERROR C202 IN LINE 129 OF .\485.C: 'i': undefined identifier
130 3 ecc = ecc^tmp; // 計算校驗字節
*** ERROR C202 IN LINE 130 OF .\485.C: 'ecc': undefined identifier
131 3 i++;
*** ERROR C202 IN LINE 131 OF .\485.C: 'i': undefined identifier
132 3 }
C51 COMPILER V6.12 485 03/19/2008 09:25:24 PAGE 4
133 2 if(i == __ERRLEN) // 幀超長,錯誤,返回
*** ERROR C202 IN LINE 133 OF .\485.C: 'i': undefined identifier
*** ERROR C141 IN LINE 133 OF .\485.C: syntax error near ';'
*** ERROR C141 IN LINE 133 OF .\485.C: syntax error near ')'
134 2 return 0;
135 2 }
136 1 /* 判斷幀是否錯誤 */
137 1 if(i<4) // 幀過短,錯誤,返回
*** ERROR C202 IN LINE 137 OF .\485.C: 'i': undefined identifier
138 1 return 0;
139 1 if(ecc != 0) // 校驗錯誤,返回
*** ERROR C202 IN LINE 139 OF .\485.C: 'ecc': undefined identifier
140 1 return 0;
141 1 if(data_buf[0] != dev) // 非訪問本機命令,錯誤,返回
*** ERROR C202 IN LINE 141 OF .\485.C: 'data_buf': undefined identifier
142 1 return 0;
143 1 *type = data_buf[1]; // 獲得命令字
*** ERROR C202 IN LINE 143 OF .\485.C: 'type': undefined identifier
144 1 return 1; // 函數成功返回
145 1 }
146
147 /* 該函數發送一幀數據幀,參數type為命令字、len為數據長度、buf為要發送的數據內容 */
148 void send_data(uchar type, uchar len, uchar *buf)
*** ERROR C141 IN LINE 148 OF .\485.C: syntax error near 'type', expected ')'
149 {
150 1 uchar i;
*** ERROR C141 IN LINE 150 OF .\485.C: syntax error near 'i'
*** ERROR C202 IN LINE 150 OF .\485.C: 'i': undefined identifier
151 1 uchar ecc = 0; // 該字節用于保存校驗字節
*** ERROR C141 IN LINE 151 OF .\485.C: syntax error near 'ecc'
*** ERROR C202 IN LINE 151 OF .\485.C: 'ecc': undefined identifier
152 1
153 1 M_DE = 1; // 置發送允許,接收禁止
154 1 M_RE = 1;
155 1
156 1 send_byte(dev); // 發送本機地址
157 1 ecc = dev;
*** ERROR C202 IN LINE 157 OF .\485.C: 'ecc': undefined identifier
158 1 send_byte(type); // 發送命令字
*** ERROR C202 IN LINE 158 OF .\485.C: 'type': undefined identifier
159 1 ecc = ecc^type;
*** ERROR C202 IN LINE 159 OF .\485.C: 'ecc': undefined identifier
160 1 send_byte(len); // 發送長度
*** ERROR C202 IN LINE 160 OF .\485.C: 'len': undefined identifier
161 1 ecc = ecc^len;
*** ERROR C202 IN LINE 161 OF .\485.C: 'ecc': undefined identifier
162 1 for(i=0; i<len; i++) // 發送數據
*** ERROR C202 IN LINE 162 OF .\485.C: 'i': undefined identifier
163 1 {
164 2 send_byte(*buf);
*** ERROR C202 IN LINE 164 OF .\485.C: 'buf': undefined identifier
165 2 ecc = ecc^(*buf);
*** ERROR C202 IN LINE 165 OF .\485.C: 'ecc': undefined identifier
166 2 buf++;
*** ERROR C202 IN LINE 166 OF .\485.C: 'buf': undefined identifier
167 2 }
168 1 send_byte(ecc); // 發送校驗字節
*** ERROR C202 IN LINE 168 OF .\485.C: 'ecc': undefined identifier
169 1
170 1 TI = 0; // 發送幀結束標志
171 1 SBUF = 0xc0;
172 1 while(!TI);
C51 COMPILER V6.12 485 03/19/2008 09:25:24 PAGE 5
173 1 TI = 0;
174 1 }
175
176 /* 該函數發送一個數據字節,若該字節為0xdb,則發送0xdbdd,若該字節為0xc0則,發送0xdbdc */
177 void send_byte(uchar da)
*** ERROR C141 IN LINE 177 OF .\485.C: syntax error near 'da', expected ')'
178 {
179 1 switch(da)
*** ERROR C202 IN LINE 179 OF .\485.C: 'da': undefined identifier
180 1 {
181 2 case 0xdb: // 字節為0xdb,發送0xdbdd
182 2 TI = 0;
183 2 SBUF = 0xdb;
184 2 while(!TI);
185 2 TI = 0;
186 2 SBUF = 0xdd;
187 2 while(!TI)
188 2 TI = 0;
189 2 break;
190 2 case 0xc0: // 字節為0xc0,發送0xdbdc
191 2 TI = 0;
192 2 SBUF = 0xdb;
193 2 while(!TI);
194 2 TI = 0;
195 2 SBUF = 0xdc;
196 2 while(!TI)
197 2 TI = 0;
198 2 break;
199 2 default: // 普通數據則直接發送
200 2 TI = 0;
201 2 SBUF = da;
*** ERROR C202 IN LINE 201 OF .\485.C: 'da': undefined identifier
202 2 while(!TI);
203 2 TI = 0;
204 2 }
205 1 }
206
207 #endif
C51 COMPILATION COMPLETE. 1 WARNING(S), 71 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -