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

📄 m1_2051.asm

📁 一卡通源码程序是我公司的一卡通源码程序,绝对难得
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;***************************************;
;        M1 卡发送数据转换并口数据      ;
;        DATE:    2005-01-03            ;
;        AUTHOR:  ZHANGTAIFENG          ;
;***************************************;
            requ     equ     p3.3        ;启动主CPU外部中断1
            mcall    equ     p3.7
            led      equ     p3.4

            ;===========================
            ;    DIFINE   ZERO
            ;===========================
            f_readid    bit  00h
            f_readmoney bit  01h
            f_writmoney bit  02h
            f_erra      bit  03h
            f_ok        bit  04h
            f_recieve   bit  05h

            f_send      bit  06h         ;从CPU发送完清标志
            f_sendcard  bit  07h         ;卡号已发送过标志
            f_money     bit  08h         ;接收到写卡命令

            ;===========================
            ;   ACCOUNT   DEFINE   ZERO
            ;===========================
            rega        equ     08h
            rimod       equ     09h
            exrimod     equ     0ah

            ricon       equ     0bh   ;接收存储指针
            sicon       equ     0ch   ;发送存储指针

            checksum    equ     0dh   ;接受校验和
            recievnum   equ     0eh   ;接收字节数

            sendnum     equ     0fh   ;发送字节数
            ;========================
            ;02+idnum(3bytes)+money(3bytes)+0d
            ;========================
            idbuf0       equ     10h   ;
            idbuf1       equ     11h
            idbuf2       equ     12h
            idbuf3       equ     13h
            idbuf4       equ     14h
            idbuf5       equ     15h
            idbuf6       equ     16h
            idbuf7       equ     17h

            idbuf8       equ     18h
            idbuf9       equ     19h
            idbuf10      equ     1ah
            idbuf11      equ     1bh




            timeout      equ     22h
            rrx          equ     23h

            ex0_rimod    equ     24h
            rrx0         equ     25h
            rricon       equ     26h
            ;ledtime      equ     27h

            recievebuf   equ     60h
            recievebuf0  equ     61h
            recievebuf1  equ     62h
            recievebuf2  equ     63h
            recievebuf3  equ     64h
            recievebuf4  equ     65h
            recievebuf5  equ     66h
            recievebuf6  equ     67h
            recievebuf7  equ     68h
            recievebuf8  equ     69h
            recievebuf9  equ     6ah
            recievebuf10 equ     6bh
            recievebuf11 equ     6ch
            recievebuf12 equ     6dh
            recievebuf13 equ     6eh
            recievebuf14 equ     6fh
            recievebuf30 equ     7eh
            recievebuf31 equ     7fh


            sendbuf      equ     27h




            r_sp        equ      50h



            ;============================
            ;常数定义
            ;============================
            stx     equ      02h
            ext     equ      03h

            baud    equ      0fdh        ;波特率设置值
            ;============================



              org    0000h

              ljmp   main

              org    0003h
              ljmp   _int_0


              org    000bh
              ljmp   _time_0


              org    0023h
              ljmp   r_recieve



main:         mov    sp,#r_sp
              lcall  iniall
              clr    f_recieve
              clr    f_sendcard
              clr    f_send
              clr    f_money
              mov    rimod,#0
              mov    ex0_rimod,#0

              lcall  delay
              lcall  delay
              lcall  delay
              lcall  delay
              mov    idbuf0,#02h
              mov    idbuf11,#0dh




wait:         clr    f_money
              jnb    mcall,wait           ;判断是否有卡
              lcall  delay
              jnb    mcall,wait



;=============================================
;read  idnumber  from  sector 9  and  36 block
;0x02+0x46+0x09+0x36+0x03+checksum
;=============================================

read_id:      mov    r0,#sendbuf
              mov    @r0,#stx
              inc    r0
              mov    @r0,#34h
              inc    r0
              mov    @r0,#36h
              inc    r0
              mov    @r0,#30h
              inc    r0
              mov    @r0,#39h
              inc    r0
              mov    @r0,#32h
              inc    r0
              mov    @r0,#34h
              inc    r0
              mov    @r0,#ext
              inc    r0
              mov    @r0,#0dh
              mov    sendnum,#09h
              mov    sicon,#sendbuf
              clr    f_recieve
              setb   ti


              mov    timeout,#0

waitid:       jb     f_recieve,connectdata
              mov    a,timeout
              cjne   a,#20,waitid
              lcall  delay
              ljmp   wait

connectdata:  clr    f_recieve
              mov    a,recievnum
              cjne   a,#2,connectdata0
              lcall  delay


              ljmp   wait
connectdata0:
              lcall  change

              lcall  delay




;=======================================
;readmoney
;0x02+0x34+0x36+0x30+0x39+0x32+0x35+0x03+0x0C
;=======================================
readmoney:    mov    r0,#sendbuf
              mov    @r0,#stx
              inc    r0
              mov    @r0,#34h
              inc    r0
              mov    @r0,#36h
              inc    r0
              mov    @r0,#30h
              inc    r0
              mov    @r0,#39h
              inc    r0
              mov    @r0,#32h
              inc    r0
              mov    @r0,#35h
              inc    r0
              mov    @r0,#ext
              inc    r0
              mov    @r0,#0ch
              mov    sendnum,#09h
              mov    sicon,#sendbuf
              setb   ti

              mov    timeout,#0
waitmoney:    jb     f_recieve,connectmoney
              mov    a,timeout
              cjne   a,#20,waitmoney
              lcall  delay
              ljmp   wait


connectmoney: clr     f_recieve
              mov     a,recievnum
              cjne    a,#2,connectmoney0
              lcall   delay
              ljmp    wait



connectmoney0:lcall   change0

;========================================
;通过并口发送到主CPU
;========================================

sendidcard:   jnb     mcall,return
              mov     sicon,#idbuf0
              mov     rrx,#12
              mov     timeout,#0
              setb    f_send
              setb    requ
              nop
              nop
              nop
              nop
              nop
              clr     requ
              nop
              nop
              nop
              nop
              nop
              setb    requ
              nop
              nop

wait_send:    jnb    f_send,wait_writemoney
              mov    a,timeout
              cjne   a,#40,wait_send
              sjmp   return

;==============================
;发送完或超时
;==============================
return:
              clr    f_send
              lcall  delay
              ljmp   wait













wait_writemoney:
              jnb    mcall,wait_writemoney0
              jnb    f_money,wait_writemoney
              clr    f_money
              lcall  hextoassic
              lcall  delay
              ljmp   write_money

wait_writemoney0:ljmp  wait

;======================================================
;写卡子程序
;0x02+0x34+0x0x36+0x30+0x39+0x32+0x35+(money_h+money_l+money_dot+4bytes+
;======================================================

write_money:
              mov   r0,#sendbuf
              mov   checksum,#0
              mov   @r0,#stx
              inc   r0
              mov   a,#34h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   a,#37h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   a,#30h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   a,#39h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   a,#32h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   a,#35h
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              mov   rrx,#32
              mov   r1,#recievebuf
write_money0: mov   a,@r1
              mov   @r0,a
              xrl   checksum,a
              inc   r0
              inc   r1
              djnz  rrx,write_money0
              ;inc   r0
              mov   @r0,#ext
              inc   r0
              mov   a,checksum
              mov   @r0,a
              mov   sicon,#sendbuf
              mov   sendnum,#41
              mov   timeout,#0
              setb  ti

wait_write:   jb    f_recieve,wait_writemoney1
              mov   a,timeout
              cjne  a,#30,wait_write
              clr   f_money
wait_write1:  ljmp  wait_writemoney


wait_writemoney1:
              mov   a,recievebuf
              cjne  a,#30h, wait_write2
              ljmp  wait_write1

wait_write2:  nop
              ljmp  wait_writemoney







;=============================================
;turn    assic   to   hex
;=============================================
change0:      mov     rrx,#14
              mov     r0,#recievebuf
chang20:      mov     a,@r0
              clr     c
              cjne    a,#40h,chang00

chang00:      jc      chang10
              clr     c
              subb    a,#37h
              mov     @r0,a
              inc     r0
              djnz    rrx,chang20

⌨️ 快捷键说明

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