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

📄 final3.bak

📁 单片机实现数据采集并传送到上位机
💻 BAK
字号:
;********************************************************
; 		Variables  definition
;********************************************************
              writeflag  equ 	21h
              readflag   equ    22h
              addflag    equ    23h
              flengtha 	 equ 	24h
              flengthb 	 equ 	25h
              flengthc   equ    31h
              comaddress equ    26h
              lightflag	 equ	27h
              startadda	 equ	28h
              startaddb	 equ    29h
              startaddc  equ    30h
              startaddflag equ  31h
              org 	00h
              jmp 	main
              org 	23h
              jmp 	gg

;*********************************************************
;		System initialization
;********************************************************

main:           call initial
                lcall highres                  ;RAM置成高阻态
     		lcall disable                  ;不使能RAM
     		mov sp,#50h
                clr tr1
     		mov pcon,#00h
    		mov scon,#50h
    		mov tmod,#21h
    		mov th1,#0feh
    		mov tl1,#0feh
    		clr et0
loop1:          setb ea
    		clr ti
    		clr ri
    		setb tr1
    		setb es
    		jmp $



;************************************************
;		Interrupt routines
;***********************************************

gg:             clr       es
                jbc       ri,writeflag0              ;是接受中断跳转
                mov       r0,readflag
                cjne      r0,#00h,main9              ;判断读指令发完了没有?
                mov       r0,addflag
                cjne      r0,#00h,main9              ;判断文件大小发完了没有?
                mov       r0,startaddflag
                cjne      r0,#00h,main9
                call      sendbyte
                ljmp      wait
main9:          call      jmain
                ljmp      wait
writeflag0:     mov       r0,writeflag
                cjne      r0,#00H,readflag0          ;判断读指令字发完了没有,是则接着发文件大小
                mov       r0,addflag
                cjne      r0,#03h,waddflag2          ;发送文件大小高字节
                mov       a,sbuf
                mov       r7,a                       ;高字节存在r7中
                mov       addflag,#02h
                ljmp      wait
waddflag2:      mov       r0,addflag                 ;发送文件大小次高字节
                cjne      r0,#02h,waddflag1
                mov       a,sbuf
                mov       r6,a                       ;次高字节存在r6中
                mov       addflag,#01h
                ljmp      wait
waddflag1:      mov       r0,addflag                 ;发送文件大小低字节
                cjne      r0,#01h,waddflag0
                mov       a,sbuf
                mov       r5,a                        ;低字节存在r5中
                mov       addflag,#00h
                ljmp      wait
waddflag0:      mov       r0,addflag
                cjne      r0,#00h,main5
startaddress:	mov	  r0,startaddflag          ;文件大小发完,接着发起始地址
		cjne      r0,#03h,startaddress2    ;发送起始地址高字节
		mov	  a,sbuf
		mov       startaddc,a
		mov       startaddflag,#02h
		ljmp      wait
startaddress2:  mov       r0,startaddflag          ;发送起始地址次高字节
		cjne	  r0,#02h,startaddress3
		mov	  a,sbuf
		mov	  startaddb,a
		mov	  startaddflag,#01h
		ljmp	  wait
startaddress3:  mov       r0,startaddflag          ;发送起始地址低字节
		cjne	  r0,#01h,startaddress4
		mov       a,sbuf
		mov       startadda,a
		mov       startaddflag,#00h
		ljmp	  wait
startaddress4:  mov       r0,startaddflag
		cjne      r0,#00h,main5
loop4:          call      receivebyte
                ljmp      wait
main5:          call      jmain
                ljmp      wait




readflag0:      mov       r0,readflag
                cjne      r0,#00H,writeflag1    ;判断指令字发完了没有?有则接着发文件大小
                mov       r0,addflag
                cjne      r0,#03h,raddflag2
                mov       a,sbuf
                mov       r7,a
                mov       addflag,#02h
                ljmp      wait
raddflag2:	mov	  r0,addflag
		cjne	  r0,#02h,raddflag1
		mov	  a,sbuf
		mov	  r6,a
		mov       addflag,#01h
		ljmp      wait
raddflag1:      mov       r0,addflag
                cjne      r0,#01h,startaddress5
                mov       a,sbuf
                mov       r5,a
                mov       addflag,#00h
                ljmp	  wait
startaddress5:  mov       r0,addflag
		cjne      r0,#00h,main7        ;文件大小发完了,发起始地址
		mov       r0,startaddflag
		cjne      r0,#03h,startaddress6
		mov	  a,sbuf
		mov       startaddc,a
		mov       startaddflag,#02h
		ljmp      wait
startaddress6:  mov       r0,startaddflag
		cjne	  r0,#02h,startaddress7
		mov	  a,sbuf
		mov	  startaddb,a
		mov	  startaddflag,#01h
		ljmp	  wait
startaddress7:  mov       r0,startaddflag
		cjne	  r0,#01h,main7
		mov       a,sbuf
		mov       startadda,a
		mov       startaddflag,#00h
                call      sendintial
                ljmp      wait
                
                
main7:          call      jmain
                ljmp      wait
writeflag1:     mov       r0,writeflag
                cjne      r0,#01h,readflag1
                call      judge55
                jnb       f0,main3
                mov       writeflag,#00h
                ljmp      wait
main3:          call      jmain
                ljmp      wait
readflag1:      mov       r0,readflag
                cjne      r0,#01h,writeflag2
                call      judgeaa
                jnb       f0,main4
                mov       readflag,#00h
                ljmp      wait
main4:          call      jmain
                ljmp      wait
writeflag2:     mov       r0,writeflag
                cjne      r0,#02h,readflag2
                call      judge55
                jnb       f0,main1
                mov       writeflag,#01h
                ljmp      wait
main1:          call      jmain
                ljmp      wait
readflag2:      mov       r0,readflag
                cjne      r0,#02h,writeflag3
                call      judgeaa
                jnb       f0,main2
                mov       readflag,#01h
                ljmp      wait
main2:          call      jmain
                ljmp      wait
writeflag3:     mov       r0,writeflag
                cjne      r0,#03h,readflag3
                call      judge55
                jnb       f0,main10
                mov       writeflag,#02h
                ljmp      wait
main10:         call      jmain
                ljmp      wait
readflag3:      mov       r0,readflag
                cjne      r0,#03h,writeflag4
                call      judgeaa
                jnb       f0,main8
                mov       readflag,#02h
                ljmp      wait
main8:          call      jmain
                ljmp      wait
writeflag4:     mov       r0,writeflag
                cjne      r0,#04h,readflag4
                call      judge55
                jnb       f0,readflag4
                mov       writeflag,#03h
                ljmp      wait
readflag4:      mov       r0,readflag
                cjne      r0,#04h,main6
                call      judgeaa
                jnb       f0,main6
                mov       readflag,#03h
                ljmp      wait
main6:          call      jmain
                ljmp      wait
wait:           setb      es
                reti



;********************************************************************
;		Subroutines
;********************************************************************


receivebyte:    clr p3.2                        ;指示灯
                setb p3.3
                mov a,sbuf
                clr   p3.4
                mov r0,startaddc
                cjne r0,#01,loopa		;写RAM子程序
                setb  p3.4
loopa:		mov p1,startadda
		mov p2,startaddb
		lcall enable
		lcall writeable
		mov p0,a
		lcall delay1ms
		lcall highres
		lcall disable
                mov   a,startadda
                cjne  a,#0ffh,gooo3
                mov   r0,startaddb
                cjne  r0,#0ffh,gooo4
                mov   r1,startaddc
                cjne  r1,#01h,gooo6
                jmp   gooo5
gooo3:          inc   startadda
                jmp   judgeflength
gooo4:          inc   startaddb
                mov   startadda,#00h
                jmp   judgeflength
gooo6:          mov   startaddc,#01h
		mov   startaddb,#00h
		mov   startadda,#00h
		jmp   judgeflength
judgeflength:   cjne  r5,#00h,gooo9
		cjne  r6,#00h,gooo7
		cjne  r7,#00h,gooo8
		jmp   gooo5
gooo9:          dec   r5
                jmp   goo2
gooo7:		dec   r6
		mov   r5,#0ffh
		jmp   goo2
gooo8:		dec   r7
		mov   r6,#0ffh
		mov   r5,#0ffh
		jmp   goo2
gooo5:          mov   writeflag,#04h
                mov   readflag,#04h
                mov   addflag  ,#03h
                mov   startaddflag,#03h
                call  infree
                jmp   goo2
goo2:           setb  es
		ret


;********************************************************
;发送初始化子程序
;********************************************************
sendintial:	call inwork
                clr   p3.4
                mov r0,startaddc
                cjne r0,#01,loopb
                setb  p3.4
loopb:          mov p1,startadda
                mov p2,startaddb
                lcall enable
                lcall readenable
                lcall delay1ms
                mov a,p0
                mov r3,a
                lcall highres
                lcall disable
                mov   a,startadda
                cjne  a,#0ffh,gooo10
                mov   r0,startaddb
                cjne  r0,#0ffh,gooo11
                mov   r1,startaddc
                cjne  r1,#01h,gooo12
                jmp   loopd
gooo10:          inc   startadda
                jmp   __judgeflength
gooo11:          inc   startaddb
                mov   startadda,#00h
                jmp   __judgeflength
gooo12:          mov   startaddc,#01h
		mov   startaddb,#00h
		mov   startadda,#00h
		jmp   __judgeflength
__judgeflength:  cjne  r5,#00h,gooo15
		cjne  r6,#00h,gooo16
		cjne  r7,#00h,gooo17
		jmp   loopd
gooo15:         dec   r5
                jmp   loopc
gooo17:		dec   r7
		mov   r6,#0ffh
		mov   r5,#0ffh
		jmp   loopc
gooo16:		dec   r6
		mov   r5,#0ffh
		jmp   loopc
loopd:          mov   writeflag,#04h
                mov   readflag,#04h
                mov   addflag  ,#03h
                mov   startaddflag,#03h
                call  infree
                jmp   loope
loopc:     	setb es
                mov a,r3
                mov sbuf,a
loope:     	ret


;****************************************************
;发送子程序
;*****************************************************
sendbyte:	clr ti
  		clr   p3.4
                mov r0,startaddc
                cjne r0,#01,loopm
                setb  p3.4
loopm:		mov p1,startadda
		mov p2,startaddb
		lcall enable
		lcall readenable
                lcall delay1ms
		mov a,p0
                mov r3,a
		lcall highres
		lcall disable
                mov   a,startadda
                cjne  a,#0ffh,goo7
                mov   r0,startaddb
                cjne  r0,#0ffh,goo4
                mov   r1,startaddc
                cjne  r1,#01h,goo6
                jmp   goo3
goo7:           inc   startadda
                jmp   _judgeflength
goo4:           inc   startaddb
                mov   startadda,#00h
                jmp   _judgeflength
goo6:           mov   startaddc,#01h
		mov   startaddb,#00h
		mov   startadda,#00h
		jmp   _judgeflength
_judgeflength:  cjne  r5,#00h,gooo14
		cjne  r6,#00h,gooo13
		cjne  r7,#00h,gooo
		jmp   goo3
gooo14:         dec   r5
                jmp   goo1
gooo:		dec   r7
		mov   r6,#0ffh
		mov   r5,#0ffh
		jmp   goo1
gooo13:		dec   r6
		mov   r5,#0ffh
		jmp   goo1
goo3:		mov  writeflag,#04h
                mov  readflag,#04h
                mov  addflag,#03h
                mov  startaddflag,#03h
                call infree
goo1:           setb  es
                mov   a,r3
                mov   sbuf,a
		ret


;***********************************************
;系统初始化子程序
;***********************************************
initial:        setb	p3.2
		setb	p3.3
		call	delay1s
                clr	p3.2
		clr	p3.3
		call	delay1s
		setb	p3.2
		setb	p3.3
		call	delay1s
		clr	p3.2
		clr	p3.3
		call	delay1s
		setb	p3.2
		setb	p3.3
		call	delay1s
		clr	p3.2
		clr	p3.3
		call	delay1s
		setb    p3.2
                clr     p3.3
                mov writeflag,#04h
                mov readflag ,#04h
                mov addflag  ,#03h
                mov flengtha ,#00h
                mov flengthb ,#00h
                mov flengthc ,#00h
                mov startadda,#00h
                mov startaddb,#00h
                mov startaddc,#00h
                mov startaddflag,#03h
		ret

inwork:		setb	p3.3
		clr	p3.2
		ret
infree:		clr	p3.3
		setb	p3.2
		ret


judge55:        clr     f0
                mov     a,sbuf
                cjne    a,#55h,ret55
                setb    f0
ret55:          ret
judgeaa:        clr     f0
                mov     a,sbuf
                cjne    a,#0aah,retaa
                setb    f0
retaa:          ret
jmain:          clr       ti
                clr       ri
                mov       addflag,#03h
                mov       writeflag,#04h
                mov       readflag,#04h
                mov       startaddflag,#03h
                ret
enable:  	;clr p3.4
         	setb p3.5
         	ret
disable: 	;setb p3.4
         	setb  p3.5
         	ret
readenable:	setb  p3.6                    ;写
         	clr   p3.7                    ;读
         	ret
writeable:	clr  p3.6
         	setb  p3.7
         	ret
highres: 	setb p3.6
         	setb p3.7
         	ret
delay1ms:	mov r4,#13
loop:    	nop
         	djnz r4,loop
         	ret


count5ms:	mov  r0,#0ffh
loop2:		nop
                nop
                nop
                djnz r0,loop2
                ret


delay1s:	mov r4,#0ffh
loop3:		call count5ms
                call count5ms
		djnz r4,loop3
		ret


         	end

⌨️ 快捷键说明

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