📄 uart.ls1
字号:
0009 223 ORG 9
0009 224 tmp?753: DS 2
225
---- 226 RSEG ?BI?UART
0000 227 SbufWorking: DBIT 1
228
---- 229 RSEG ?ID?UART
0000 230 InputBuf: DS 32
231
---- 232 RSEG ?XD?UART
0000 233 OutputBuf: DS 16
0010 234 InputOutTime: DS 2
0012 235 OutputOutTime: DS 2
236
---- 237 RSEG ?DT?UART
0000 238 IBufGetIdx: DS 1
0001 239 IBufPutIdx: DS 1
0002 240 OBufGetIdx: DS 1
0003 241 OBufPutIdx: DS 1
242
---- 243 RSEG ?C_INITSEG
0000 C100 F 244 DB 0C1H, SbufWorking + 000H ; bit-init
245
0002 42 246 DB 042H
0003 0000 F 247 DW InputOutTime
0005 0000 248 DW 00000H
249
0007 42 250 DB 042H
0008 0000 F 251 DW OutputOutTime
000A 0000 252 DW 00000H
253
000C 01 254 DB 001H
000D 00 F 255 DB IBufGetIdx
A51 MACRO ASSEMBLER UART 03/13/2009 15:44:52 PAGE 5
000E 00 256 DB 000H
257
000F 01 258 DB 001H
0010 00 F 259 DB IBufPutIdx
0011 00 260 DB 000H
261
0012 01 262 DB 001H
0013 00 F 263 DB OBufGetIdx
0014 00 264 DB 000H
265
0015 01 266 DB 001H
0016 00 F 267 DB OBufPutIdx
0017 00 268 DB 000H
269
270 ; //////////////////////////////////////////////
271 ; // uart.c //
272 ; // 设置波特率(需要晶振频率支持) //
273 ; // 晶振频率:11m0592,12m0,18m0,24m0 //
274 ; // design by: 刘俐训 //
275 ; //////////////////////////////////////////////
276 ;
277 ; #include<reg52.h>
278 ; #include"uart.h"
279 ; #include"stimer.h"
280 ; #include"ascii.h"
281 ; #include <v51rx2.h>
282 ;
283 ; #include "intrsc.h"
284 ;
285 ; #ifndef BUF_SIZE
286 ; #define BUF_SIZE 32
287 ; #define OBUF_SIZE 16
288 ; #endif
289 ;
290 ; #ifndef enable
291 ; #define enable() EA=1
292 ; #define disable() EA=0
293 ; #endif
294 ;
295 ; #define StartSend() TI=1
296 ;
297 ; static bit SbufWorking=0;
298 ;
299 ; static unsigned char idata InputBuf[BUF_SIZE];
300 ; static unsigned char xdata OutputBuf[OBUF_SIZE];
301 ; static unsigned int InputOutTime=0;
302 ; static unsigned int OutputOutTime=0;
303 ;
304 ; #if (BUF_SIZE>256)
305 ; static unsigned int data IBufGetIdx=0;
306 ; static unsigned int data IBufPutIdx=0;
307 ; #else
308 ; static unsigned char data IBufGetIdx=0;
309 ; static unsigned char data IBufPutIdx=0;
310 ; #endif
311 ; #if (OBUF_SIZE>256)
312 ; static unsigned int data OBufGetIdx=0;
313 ; static unsigned int data OBufPutIdx=0;
314 ; #else
315 ; static unsigned char data OBufGetIdx=0;
316 ; static unsigned char data OBufPutIdx=0;
317 ; #endif
318 ;
319 ; static bit PutInputData( void );
320 ; static int GetInputData( void );
321 ; static bit PutOutputData( unsigned char abyte );
A51 MACRO ASSEMBLER UART 03/13/2009 15:44:52 PAGE 6
322 ; static bit GetOutputData( void );
323 ; #define EnterCrtcl() ES = 0
324 ; #define LeaveCrtcl() ES = 1
325 ;
---- 326 CSEG AT 00023H
0023 020000 F 327 LJMP InterruptCom
328
329 ; void InterruptCom(void) interrupt SIO_VECTOR using 1
330
---- 331 RSEG ?PR?InterruptCom?UART
332 USING 1
0000 333 InterruptCom:
0000 C0E0 334 PUSH ACC
0002 C0F0 335 PUSH B
0004 C083 336 PUSH DPH
0006 C082 337 PUSH DPL
0008 C0D0 338 PUSH PSW
339 USING 1
000A 75D008 340 MOV PSW,#08H
341 ; SOURCE LINE # 57
342 ; {
343 ; if(RI)
344 ; SOURCE LINE # 59
000D 309805 345 JNB RI,?C0001
346 ; {
347 ; SOURCE LINE # 60
348 ; RI=0;
349 ; SOURCE LINE # 61
0010 C298 350 CLR RI
351 ; PutInputData();
352 ; SOURCE LINE # 62
0012 120000 F 353 LCALL PutInputData
354 ; }
355 ; SOURCE LINE # 63
0015 356 ?C0001:
357 ;
358 ; if(TI)
359 ; SOURCE LINE # 65
0015 309905 360 JNB TI,?C0003
361 ; {
362 ; SOURCE LINE # 66
363 ; TI=0;
364 ; SOURCE LINE # 67
0018 C299 365 CLR TI
366 ; GetOutputData();
367 ; SOURCE LINE # 68
001A 120000 F 368 LCALL GetOutputData
369 ; }
370 ; SOURCE LINE # 69
371 ; }
372 ; SOURCE LINE # 70
001D 373 ?C0003:
001D D0D0 374 POP PSW
001F D082 375 POP DPL
0021 D083 376 POP DPH
0023 D0F0 377 POP B
0025 D0E0 378 POP ACC
0027 32 379 RETI
380 ; END OF InterruptCom
381
382 ;
383 ; bit PutInputData( void )
384
---- 385 RSEG ?PR?PutInputData?UART
0000 386 PutInputData:
387 USING 0
A51 MACRO ASSEMBLER UART 03/13/2009 15:44:52 PAGE 7
388 ; SOURCE LINE # 72
389 ; {
390 ; SOURCE LINE # 73
391 ; #if (BUF_SIZE!=256)
392 ; if( IBufGetIdx ==0 )
393 ; SOURCE LINE # 75
0000 E500 F 394 MOV A,IBufGetIdx
0002 7007 395 JNZ ?C0004
396 ; {
397 ; SOURCE LINE # 76
398 ; if( IBufPutIdx == BUF_SIZE-1 )
399 ; SOURCE LINE # 77
0004 E500 F 400 MOV A,IBufPutIdx
0006 B41F02 401 CJNE A,#01FH,?C0004
402 ; return 0;
403 ; SOURCE LINE # 78
0009 C3 404 CLR C
000A 22 405 RET
406 ; }
407 ; SOURCE LINE # 79
000B 408 ?C0004:
409 ; #endif
410 ;
411 ; if(IBufPutIdx == IBufGetIdx-1)
412 ; SOURCE LINE # 82
000B E500 F 413 MOV A,IBufGetIdx
000D 14 414 DEC A
000E 6500 F 415 XRL A,IBufPutIdx
0010 7002 416 JNZ ?C0007
417 ; {
418 ; SOURCE LINE # 83
419 ; return 0;
420 ; SOURCE LINE # 84
0012 C3 421 CLR C
0013 22 422 RET
423 ; }
424 ; SOURCE LINE # 85
0014 425 ?C0007:
426 ; InputBuf[IBufPutIdx] = SBUF;
427 ; SOURCE LINE # 86
0014 7400 F 428 MOV A,#LOW (InputBuf)
0016 2500 F 429 ADD A,IBufPutIdx
0018 F8 430 MOV R0,A
0019 A699 431 MOV @R0,SBUF
432 ; IBufPutIdx++;
433 ; SOURCE LINE # 87
001B 0500 F 434 INC IBufPutIdx
435 ;
436 ; #if (BUF_SIZE != 256)
437 ; if(IBufPutIdx==BUF_SIZE)
438 ; SOURCE LINE # 90
001D E500 F 439 MOV A,IBufPutIdx
001F B42003 440 CJNE A,#020H,?C0008
441 ; IBufPutIdx=0;
442 ; SOURCE LINE # 91
0022 E4 443 CLR A
0023 F500 F 444 MOV IBufPutIdx,A
0025 445 ?C0008:
446 ; #endif
447 ;
448 ; return 1;
449 ; SOURCE LINE # 94
0025 D3 450 SETB C
451 ; }
452 ; SOURCE LINE # 95
0026 453 ?C0006:
A51 MACRO ASSEMBLER UART 03/13/2009 15:44:52 PAGE 8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -