⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r.a

📁 一个C style Assembler的source code
💻 A
字号:
;;; This particular piece of software is a demo of;;; (A) An 8052 multi-tasking architecture;;; (B) 9-bit serial communications (in mode 3) at 57600 baud;;; (C) A memory dump routine for Intel Hex Format.;;; It should operate reliably with a host connected over a RS-232, RS-422,;;; RS-423 or RS-485.  If using half-duplex, T0 is configured here as the;;; Transmit-Enable control output.;;; Binary Technology 8051/8052 Cross Assembler (sxa51) used.;;; The registers defined in the 8052.T2CON  equ 0xc8RCAP2L equ 0xcaRCAP2H equ 0xcbTL2    equ 0xccTH2    equ 0xcd;;; Addressible bits;;; Port 1T2   bit P1.0T2EX bit P1.1;;; IE and IPET2 bit IE.5PT2 bit IP.5;;; T2CONTF2    bit T2CON.7EXF2   bit T2CON.6RCLK   bit T2CON.5TCLK   bit T2CON.4EXEN2  bit T2CON.3TR2    bit T2CON.2C_T2   bit T2CON.1CP_RL2 bit T2CON.0;;; An 8052 multi-tasking kernel.;;; Process stackPSP   equ 73h  ;;; int **PSP;Stack equ 74h  ;;; int *Stack[8];;;; /* Interrupt descriptor table. */SP_RI   equ 7chSP_TI   equ 7dhSP_BASE equ 7ehorg 00hsjmp Startorg 23h   jbc TI, DidTx   jbc RI, DidRxretiDidTx:   mov R0, #SP_TI   acall ResumeretiDidRx:   mov R0, #SP_RI   acall ResumeretiStart: ;;; Install main(), set its return address to _Die().   mov PSP, #Stack         ;;; PSP = &Stack[0];   mov SP, #(SP_BASE - 1)  ;;; SP = SP_BASE - 1;   mov DPTR, #Exit   push DPL   push DPH                ;;; *SP++ = _Exit();   acall main_Die:   orl PCon, #1sjmp _DiePause:                     ;;; void Pause(int **R0) {   mov @R0, SP             ;;;    *R0 = SP;   dec PSP   mov R0, PSP   mov SP, @R0             ;;;    SP = *--PSP;ret                        ;;;    "idle until resume";Resume:   mov R1, PSP   inc PSP   mov @R1, SP             ;;;    *PSP++ = SP;   mov SP, @R0             ;;;    SP = *R0;   mov @R0, #(SP_BASE + 1) ;;;    *R0 = SP_BASE + 1;ret                        ;;; }Spawn:                   ;;; void Spawn(int *R0, void *(DPTR())) {   mov R1, PSP   inc PSP   mov @R1, SP           ;;;    *PSP++ = SP;   dec R0   mov SP, R0            ;;;    SP = --R0;   acall _Enter          ;;;    (*DPTR)();Exit:   dec PSP   mov R0, PSP   mov SP, @R0           ;;;    SP = *--PSP;ret                      ;;; }_Enter:   push DPL   push DPHret;;; RS-485 SERIAL COMMUNICATIONS.;;; Modes:;;; (1) Wait for address (REN = 1, T0 = 0, SM2 = 1);;; (2) Wait for data    (REN = 1, T0 = 0, SM2 = 0);;; (3) Send data        (REM = 0, T0 = 1)SER_ADDR equ ':'SetPort:   mov SCON, #11000000b ;;; Serial comm: 9 bits, no parity, 1 stop bit.   clr PS   clr RCLK   clr TCLK   mov A, TMOD   anl A, #0fh   add A, #00100000b ;;; Timer 1: baud rate timer.   mov TMOD, A   mov TH1, #-1         ;;; Baud rate: 28800 baud.   orl PCON, #80h       ;;; Baud rate now 57600 baud.   setb TR1   clr TB8   clr RI   clr TI   setb ESretSetRx: ;;; Set mode for "Wait for address"   clr T0   setb SM2   setb RENretSetTx: ;;; Set mode for "Send data"   clr REN   setb T0retgetchar:   getcharLoop:      mov R0, #SP_RI      acall Pause      mov A, SBUF   jnb SM2, getcharBreak      cjne A, #SER_ADDR, NoMatch         clr SM2         ;;; if (A == SER_ADDR) Set mode for "Wait for data";      NoMatch:   sjmp getcharLoop   getcharBreak:retnl:   mov A, #13   acall putchar   mov A, #10putchar:   mov SBUF, A   mov R0, #SP_TI   acall Pauseret;;; APPLICATIONputnib:   anl A, #0fh   cjne A, #10, $ + 3jc isdigit   add A, #('a' - 10)   acall putcharretisdigit:   add A, #'0'   acall putcharretputhex:   xch A, R3   add A, R3   xch A, R3   push ACC   swap A   acall putnib   pop ACC   acall putnibretputend:   mov A, #':'   acall putchar   mov R3, #0   mov A, #00h   acall puthex   mov A, DPH   acall puthex   mov A, DPL   acall puthex   mov A, #1   acall puthex   mov A, R3   cpl A   acall puthex   acall nlretputdata:   mov A, #':'   acall putchar   mov R3, #0   mov A, #10h   acall puthex   mov A, DPH   acall puthex   mov A, DPL   acall puthex   mov A, #0   acall puthex   mov R2, #10h   DataLoop:      clr A      movc A, @A + DPTR      inc DPTR      acall puthex   djnz R2, DataLoop   mov A, R3   cpl A   acall puthex   acall nlrethexs:   mov DPTR, #0000h   hexsLoop:   mov A, DPH   cjne A, #20h, $ + 3   jnc hexsBreak      acall putdata   sjmp hexsloophexsBreak:   acall putendretEcho:   acall SetPortEchoLoop:   acall SetRx   acall getcharX0: cjne A, #'s', X1   acall hexssjmp EchoLoopX1:   acall SetTx   acall putcharsjmp EchoLoopmain:   mov R0, #90h   mov DPTR, #Echo   acall Spawn   setb EAretend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -