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

📄 mpu.asm

📁 scara机器人的一种简单的实现方法
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;       please be sure to protect these three register.
;entry:
;exit:  sspdcp_count
;-------------------------------------------------------------------
glisten0:       clr     ea              ;disable all the interrupt
                cpl     sspd_cp
                mov     a,  sspdcp_count
                inc     sspdcp_count
                jb      acc.0, gsspd_sdp ;test "odd" or "even".
                ajmp    gsspd_exit

gsspd_sdp:      jnb     sspd_adsmpl, sspd_smpl2
                ajmp    sample1
sspd_smpl2:     ajmp    sample2
sample1:        mov     dptr,#gsspd_select1
                jmp     @a+dptr         ;jump to the selected term.
gsspd_select1:  nop
                ajmp    gsspd_c_st      ;1  begin the sspd "start".
                setb    sspd_st         ;3  stop the sspd "start".
                ajmp    gsspd_exit           ;5
                ajmp    gsspd_exit           ;7
                ajmp    gsspd_exit           ;9
                ajmp    gsspd_exit           ;11
                ajmp    gsspd_exit           ;13
                ajmp    gsspd_exit           ;15
                ajmp    gsspd_exit           ;17
                ajmp    gsspd_exit           ;19
                ajmp    gsspd_exit           ;21
                ajmp    gsspd_exit           ;23
                ajmp    gsspd_exit           ;25
                ajmp    gsspd_exit           ;27
                setb    sspd_rst        ;29 enable No.1 S/H holding.
                ajmp    gsspd_exit           ;31
                ajmp    gsspd_exit           ;33
                ajmp    gsspd_exit           ;35
                ajmp    gsspd_exit           ;37
                ajmp    gsspd_exit           ;39
                ajmp    gsspd_adstart  ;41 the 1st sampling and discharging. 
                ajmp    gsspd_dis1     ;43 read the 1st data.
                ajmp    gsspd_exit           ;45
                ajmp    gsspd_exit           ;47
                ajmp    gsspd_exit           ;49
                ajmp    gsspd_exit           ;51
                ajmp    gsspd_exit           ;53
                ajmp    gsspd_exit           ;55
                ajmp    gsspd_exit           ;57
                ajmp    gsspd_exit           ;59
                setb    sspd_rst         ;61 enable No.3 S/H holding.
                ajmp    gsspd_exit           ;63
                ajmp    gsspd_exit           ;65
                ajmp    gsspd_exit           ;67
                ajmp    gsspd_exit           ;69
                ajmp    gsspd_adstart ;71 the 3rd sampling and discharging.
                ajmp    gsspd_dis2    ;73 read the 3rd data.
                ajmp    gsspd_exit           ;75
                ajmp    gsspd_exit           ;77
                ajmp    gsspd_exit           ;79
                ajmp    gsspd_exit           ;81
                ajmp    gsspd_exit           ;83
                ajmp    gsspd_exit           ;85
                ajmp    gsspd_exit           ;87
                setb    sspd_rst         ;89 enable No.5 S/H holding.
                ajmp    gsspd_exit           ;91
                ajmp    gsspd_exit           ;93
                ajmp    gsspd_exit           ;95
                ajmp    gsspd_exit           ;97
                ajmp    gsspd_adstart ;99 the 5th sampling and discharging.
                ajmp    gsspd_dis3    ;101 read the 5th data.
                ajmp    gsspd_exit           ;103
                ajmp    gsspd_exit           ;105
                ajmp    gsspd_exit           ;107
                ajmp    gsspd_exit           ;109
                ajmp    gsspd_exit           ;111
                ajmp    gsspd_exit           ;113
                ajmp    gsspd_exit           ;115
                mov     sspdcp_count,#0      ;117 clear sspd clock counter.
;                mov     a, sample_number
;                inc     a
;                mov     sample_number, a
;                cjne    a, #0ffh, select1_exit
;                clr     tr0
;                clr     et0
select1_exit:   ajmp    gsspd_exit

sample2:        mov     dptr,#gsspd_select2
                jmp     @a+dptr         ;jump to the selected term.
gsspd_select2:  nop
                ajmp    gsspd_c_st      ;1  begin the sspd "start".
                setb    sspd_st         ;3  stop the sspd "start".
                ajmp    gsspd_exit           ;5
                ajmp    gsspd_exit           ;7
                ajmp    gsspd_exit           ;9
                ajmp    gsspd_exit           ;11
                ajmp    gsspd_exit           ;13
                ajmp    gsspd_exit           ;15
                ajmp    gsspd_exit           ;17
                ajmp    gsspd_exit           ;19
                ajmp    gsspd_exit           ;21
                ajmp    gsspd_exit           ;23
                ajmp    gsspd_exit           ;25
                ajmp    gsspd_exit           ;27
                ajmp    gsspd_exit           ;29
                ajmp    gsspd_exit           ;31
                ajmp    gsspd_exit           ;33
                ajmp    gsspd_exit           ;35
                ajmp    gsspd_exit           ;37
                ajmp    gsspd_exit           ;39
                ajmp    gsspd_exit           ;41
                ajmp    gsspd_exit           ;43
                ajmp    gsspd_exit           ;45
                setb    sspd_rst         ;47 enable No.2 S/H holding.
                ajmp    gsspd_exit           ;49
                ajmp    gsspd_exit           ;51
;               ajmp    gsspd_exit           ;53
                ajmp    gsspd_adstart ;53 the 2nd sampling and discharging.
                ajmp    gsspd_dis1    ;55 read the 6th data.
                ajmp    gsspd_exit           ;57
                ajmp    gsspd_exit           ;59
                ajmp    gsspd_exit           ;61
                ajmp    gsspd_exit           ;63
                ajmp    gsspd_exit           ;65
                ajmp    gsspd_exit           ;67
                ajmp    gsspd_exit           ;69
                ajmp    gsspd_exit           ;71
                ajmp    gsspd_exit           ;73
                setb    sspd_rst         ;75 enable No.4 S/H holding.
                ajmp    gsspd_exit           ;77
                ajmp    gsspd_exit           ;79

                ajmp    gsspd_exit           ;81
                ajmp    gsspd_exit           ;83
                ajmp    gsspd_adstart ;85 the 4th sampling and discharging.
                ajmp    gsspd_dis2    ;87 read the 4th data.
                ajmp    gsspd_exit           ;89
                ajmp    gsspd_exit           ;91
                ajmp    gsspd_exit           ;93
                ajmp    gsspd_exit           ;95
                ajmp    gsspd_exit           ;97
                ajmp    gsspd_exit           ;99
                ajmp    gsspd_exit           ;101
                setb    sspd_rst         ;103 enable No.6 S/H holding.
                ajmp    gsspd_exit           ;105
                ajmp    gsspd_exit           ;107
                ajmp    gsspd_exit           ;109
                ajmp    gsspd_exit           ;111
                ajmp    gsspd_adstart ;113 the 6th sampling and discharging.
                ajmp    gsspd_dis3    ;115 read the 6th data.
                mov     sspdcp_count,#0    ;117 clear sspd clock counter.
;                mov     a, sample_number
;                inc     a
;                mov     sample_number, a
;                cjne    a, #0ffh, gsspd_exit
;                clr     tr0
;                clr     et0

gsspd_exit:     mov     th0,sspdcpbuffh
                mov     tl0,sspdcpbuffl
                setb    ea              ;enable all the interrupt
                reti                    ;2us

gsspd_c_st:     clr     sspd_st
                ajmp    gsspd_exit

gsspd_adstart:  clr     adrc    ;enable "start" signal:"--___--" .
                setb    adrc
                jb      adst,$
                clr     sspd_rst        ;S/H discharging.
                ajmp    gsspd_exit

gsspd_dis1:     mov     sspd_adbuff13l,sspd_adbuff12l
                mov     sspd_adbuff13h,sspd_adbuff12h
                mov     sspd_adbuff12l,sspd_adbuff11l
                mov     sspd_adbuff12h,sspd_adbuff11h
                clr     ada0            ;ada0="0" status.
                mov     sspd_adbuff11h,p1;read the No.1 high eight bit.
                setb    ada0            ;ada0="1" status.
                mov     sspd_adbuff11l,p1;read the No.1 low four bit.
                ajmp    gsspd_exit
                  
gsspd_dis2:     mov     sspd_adbuff23l,sspd_adbuff22l
                mov     sspd_adbuff23h,sspd_adbuff22h
                mov     sspd_adbuff22l,sspd_adbuff21l
                mov     sspd_adbuff22h,sspd_adbuff21h
                clr     ada0            ;ada0="0" status.
                mov     sspd_adbuff21h,p1;read the No.1 high eight bit.
                setb    ada0            ;ada0="1" status.
                mov     sspd_adbuff21l,p1;read the No.1 low four bit.
                ajmp    gsspd_exit
                  
gsspd_dis3:     mov     sspd_adbuff33l,sspd_adbuff32l
                mov     sspd_adbuff33h,sspd_adbuff32h
                mov     sspd_adbuff32l,sspd_adbuff31l
                mov     sspd_adbuff32h,sspd_adbuff31h
                clr     ada0            ;ada0="0" status.
                mov     sspd_adbuff31h,p1;read the No.1 high eight bit.
                setb    ada0            ;ada0="1" status.
                mov     sspd_adbuff31l,p1;read the No.1 low four bit.
                ajmp    gsspd_exit
                  

;******************************************************************
;               KEY AND LED SUB_PROCEDURE
;******************************************************************
;==================================================================
;name: ls164k
;number:
;used resoures: external kclk,kdat;internal Acc,b
;algorithm: shift the data in the Acc to 74LS164(kdat)
;entry: Acc=the data which is shifted into 74LS164(kdat)
;exit:  No
;------------------------------------------------------------------
ls164k:         push    psw
                push    acc
                push    b

                mov     b,#8
ls164k_loop:    clr     kclk
                rlc     a
                mov     kdat,c
                nop
                setb    kclk
                djnz    b,ls164k_loop

                setb    kdat
                pop     b
                pop     acc
                pop     psw
                ret

;==================================================================
;name: ls164l
;number:
;used resoures: external kclk,kdat;internal Acc,b
;algorithm: shift the data in the Acc to 74LS164(ldat)
;entry: Acc=the data which is shifted into 74LS164(ldat)
;exit:  No
;------------------------------------------------------------------
ls164l:         push    psw
                push    acc
                push    b

                mov     b,#8
ls164l_loop:    clr     lclk
                rlc     a
                mov     ldat,c
                nop
                setb    lclk
                djnz    b,ls164l_loop

                setb    ldat
                pop     b
                pop     acc
                pop     psw
                ret

;==================================================================
;name: led
;number:
;used resoures: external dspbuffl to dspbuffh
;               internal Acc,r0,r1,dptr
;               acall ls164l 
;algorithm: shift the data storaged in the "dspbuffl to dspbuffh"
;       into the eight 74LS164(ldat) of display led
;entry: dspbuffl to dspbuffh--the displaying data
;exit:  No
;------------------------------------------------------------------
led:            push    psw
                push    acc
                push    b
                push    r1
                push    r0
                push    dph
                push    dpl

                jnb     dsp_xflag,led_dsp_y
                clr     dsp_xflag

                mov     r0,#hex_l       ;convert the data that will
                mov     @r0,dsp_xl      ; display in X coordinate
                inc     r0              ; to compressed BCD,store in 
                mov     @r0,dsp_xh      ; the dec buffer.
                lcall   hexdec          
                
                mov     r0,#dec_l       ;decode the compressed BCD
                mov     r1,#dspbuffx0   ; in the dec_l-dec_h for
                mov     b,#2            ; X coordinate.
led_dsp_xloop:  mov     a,@r0
                anl     a,#0fh
                mov     @r1,a
                inc     r1

                mov     a,@r0
                anl     a,#0f0h
                swap    a
                mov     @r1,a
                inc     r1
                inc     r0
                djnz    b,led_dsp_xloop
;//convert dsp_xl(hex) to dec to displaying BCD code and
;//put them into the display buffer(hight forth byte)

led_dsp_y:      jnb     dsp_yflag,led_dsp_pt
                clr     dsp_yflag

                mov     r0,#hex_l       ;convert the data that will
                mov     @r0,dsp_yl      ; display in Y coordinate
                inc     r0              ; to compressed BCD,store in 
                mov     @r0,dsp_yh      ; the dec buffer.
                lcall   hexdec          

                mov     r0,#dec_l       ;decode the compressed BCD
                mov     r1,#dspbuffy0   ; in the dec_l-dec_h for
                mov     b,#2            ; Y coordinate.
led_dsp_yloop:  mov     a,@r0
                anl     a,#0fh
                mov     @r1,a
                inc     r1

                mov     a,@r0
                anl     a,#0f0h
                swap    a
                mov     @r1,a
                inc     r1
                inc     r0
                djnz    b,led_dsp_yloop
;//convert dsp_yl(hex) to dec to displaying BCD code and
;//put them into the display buffer(low forth byte).

led_dsp_pt:     jnb     dsppointflag,led_dsp_hide
                clr     dsppointflag

                mov     r0,#dspbuffy0
                inc     r0
                inc     r0
                mov     a,@r0
                add     a,#32
                mov     @r0,a

                mov     r0,#dspbuffx0
                inc     r0
                inc     r0
                mov     a,@r0
                add     a,#32
                mov     @r0,a

⌨️ 快捷键说明

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