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

📄 test0.asm

📁 这是一个用A51编写的89C51汇编语言程序
💻 ASM
字号:
	  org       0000h
	  ljmp      MainInit
	  org       0003h
	  ljmp      Even0Int
	  org       000bh
	  ljmp      Time0Int
	  org       0013h
	  ljmp      Even1Int
	  org       0023h
	  ljmp      CommInt
	  
	  org       0030h
CommInt:  push      dph
          push      dpl
          push      acc
          push      psw
CommRec:  jnb       ri,CommEnd
          jb        20h.0,ReciEnd
          mov       a,30h
          add       a,r5
          mov       dpl,a
          mov       dph,31h
          mov       a,sbuf
          movx      @dptr,a
          inc       r5 
          mov       a,r5
          clr       c
          subb      a,r4
          jnz       $+4
          setb      20h.0
          clr       c
          subb      a,#6
          jc        $+6
          clr       20h.1
          sjmp      $+4
          setb      20h.1
ReciEnd:  clr       ri
CommEnd:  pop       psw
          pop       acc
          pop       dpl
          pop       dph
          reti
          
Time0Int: push      acc
          push      b
          push      psw
TimeFilt: mov       a,22h
          mov       c,p1.0
          rlc       a
          mov       22h,a
          mov       c,21h.0
          mov       b.0,c
          cjne      a,#0ffh,$+7
          setb      21h.0
          sjmp      FilterB
          cjne      a,#0,$+5
          clr       21h.0
FilterB:  mov       a,23h
          mov       c,p1.1
          rlc       a
          mov       23h,a
          cjne      a,#0ffh,$+7
          setb      21h.1
          sjmp      FiltEnd
          cjne      a,#0,$+5
          clr       21h.1
FiltEnd:  jb        b.0,TimeCoun
          jnb       21h.0,TimeCoun
          inc       42h
          mov       a,42h
          cjne      a,#0,$+5
          inc       43h
          jb        21h.1,$+9
          clr       21h.2 ;21h.2 = 1 stand for backward.0 for forward.             
          clr       p1.2
          sjmp      TimeCoun
          setb      21h.2 ;is backward
          setb      p1.2
TimeCoun: inc       44h
          mov       a,44h
          cjne      a,#0,$+5
          inc       45h
          mov       a,45h
JustA:    cjne      a,#4,JustB
          mov       44h,#0
          mov       45h,#0 
          sjmp      SaveDat
JustB:    cjne      a,#2,Time0End
          sjmp      Time0End
SaveDat:  mov       48h,40h ;save event1/2's count in define interval.
          mov       40h,#0  ;and clear to 0.
          mov       49h,41h
          mov       41h,#0
          mov       4ah,42h
          mov       42h,#0 
          mov       4bh,43h
          mov       43h,#0
          mov       a,48h
          cjne      a,#0,$+7
          clr       p1.3
          sjmp      $+4
          setb      p1.3
          setb      20h.6 ;requre for ready data.
          mov       a,4fh
          cjne      a,#0,rstwdg
          mov       a,4eh
          cjne      a,#0,rstwdg
          ljmp      0000h
rstwdg:   mov       4eh,#0          
          mov       4fh,#0
Time0End: mov       tl0,#00
          mov       th0,#0feh
          pop       psw
          pop       b
          pop       acc
          reti      

Even0Int: push      acc
          inc       40h
          mov       a,40h
          cjne      a,#0,Even0End
          inc       41h
Even0End: pop       acc
          reti

Even1Int: push      acc
          inc       42h
          mov       a,42h
          cjne      a,#0,Even1End
          inc       43h
Even1End: pop       acc
          reti
          
MainInit: clr	    a
	  mov	    psw,a
	  mov	    ie,a
	  mov       sp,#6fh
	  mov       20h,#0ah ;set work's status:bit0 stands for rbuff full. bit1 for rbuff empty,bit2 for sbuff full,bit3 for sbuff empty.bit4 for r/s status,bit5 for req r/s status.bit6 for need refresh send data.
          ;mov       21h,#3   ;filtered p1(lsb 2).bit 2 stand for 熄火 or not. 
	  ;mov       22h,#0ffh ;Signal A (serial)
	  ;mov       23h,#0ffh ;Signal B (serial)
	  mov       30h,#00h ;set Rbuff base address
	  mov       31h,#80h
	  mov       34h,#00h ;set Sbuff base address
	  mov       35h,#81h
	  mov       37h,#0d7h
	  mov       38h,#06h  ;ready for Send message.
          mov       39h,#'S'
          mov       3ah,#'1'
          mov       3dh,#'E'
          mov       40h,#00h ;init event0's counts
	  mov       41h,#00h
	  mov       42h,#00h ;init event1's counts
	  mov       43h,#00h
	  mov       44h,#00h ;init Timer1,16bit.
	  mov       45h,#00h
	  mov       4eh,#00h
	  mov       4fh,#00h
	  mov       r4,#00h ;recieve buff head
	  mov       r5,#00h ;recieve buff tail
	  mov       r6,#00h ;send buff head
	  mov       r7,#00H ;send buff tail
	  mov	    tmod,#21h ;tr1 use for baud generate,tr0 use for mod 1,that is a 16's timer.
	  mov	    tl0,#00h 
	  mov	    th0,#0feh ;2000 times/second
	  mov	    th1,#0fdh ;comm's baud is 9600b/s
	  mov	    tl1,#0fdh
	  mov	    scon,#50h ;set comm1 in mod 1,enable recieve,ri=1 until counter efficient stop bit.
	  setb	    tr1    ;enable comm and t1  work.
	  setb      tr0    ;enable t0 work.
	  setb      it0    ;enable int0 triggle by edge.
	  setb      it1    ;enable int1 triggle by edge.
	  cpl       p1.7   ;feed hard dog.
	  mov       ie,#93h   ;enable all interupt except t1
	  nop
MainLoop: inc       4eh
          mov       a,4eh
          cjne      a,#0,$+5
          inc       4fh
          jb        20h.6,ReadyDat ;20h.6 stand for need refresh send data.
          ljmp      ReadRbuf
ReadyDat: jnb       21h.2,vforward  ;21h.2 stand for vehicl go forward.
          mov       a,3ah
          add       a,#80h
          mov       3ah,a
vforward: mov       a,48h
          add       a,#31h
          mov       3bh,a
          mov       a,4ah
          add       a,#31h
          mov       3ch,a
          mov       r2,#1  ;Send one times.
          clr       20h.6  ;answer datum has ready.
SendBuff: mov       r0,#37h
PutNext:  mov       a,@r0
          mov       sbuf,a
          inc       r0
          jnb       ti,$
          clr       ti
          cjne      r0,#3eh,PutNext
          djnz      r2,SendBuff
          cpl       p1.7 ;feed hard wdg.
          mov       3ah,#'1'
ReadRbuf: jnb       20h.1,$+5  ;if Rbuf not empty.
          sjmp      MainLoop
          mov       a,30h
          add       a,r4
          mov       dpl,a
          mov       dph,31h
          movx      a,@dptr
          cjne      a,#'S',$+5
          sjmp      $+5
          ljmp      NextChar
          mov       a,dpl
          add       a,#4
          mov       dpl,a 
          movx      a,@dptr
          cjne      a,#'E',$+5
          sjmp      $+5
          ljmp      NextChar
          mov       a,dpl
          clr       c
          subb      a,#03h
          mov       dpl,a
          movx      a,@dptr
          cjne      a,#'1',$+5
          sjmp      $+5
          ljmp      NextChar
          mov       a,dpl   ;E/O validate.
          add       a,#4
          mov       dpl,a
          movx      a,@dptr
          cjne      a,#0,$+5
          sjmp      $+5
          ljmp      NextChar
          mov       a,r4
          add       a,#5 ;r4 pointer to '0'.
          mov       r4,a
          clr       c
          subb      a,#3
          mov       dpl,a
          movx      a,@dptr
          cjne      a,#31h,Restore
          clr       p1.4 ;熄火。
          sjmp      NextChar
Restore:  setb      p1.4             
NextChar: inc       r4
          clr       20h.0 ;Rbuff not full
          mov       a,r5
          clr       c
          subb      a,r4
          jz        RbufEmpt
          clr       c
          subb      a,#6
          jnc       $+4
RbufEmpt: setb      20h.1
          ljmp      MainLoop
          mov       a,#00h
          mov       ie,a      ;disable interupt
          end

⌨️ 快捷键说明

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