以下是我用msp430f2121编的一个读写at88sc102的完整的汇编程序,
- #include "STD_DEF.s43" ; Standard Equations
- _CPU_ SET 5
- ; vre.1.1 2002.9.28
- ;------------------------------------------------------------------------
- #include
- #include "ICDXDY.s43"
- FLASH_orig EQU 0F000h ; F212(1) FLASH 起始地址
- NAME yufsdnb
- RSEG CODE
- main
- ;------------------------------------------------------------------------
- RESET mov.w #300h,SP ; Initialize stackpointer
- StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
- mov.b &CALBC1_1MHZ,&BCSCTL1 ; Set DCO
- mov.b &CALDCO_1MHZ,&DCOCTL
- call #RAMCLR
- ; mov #22,&DL_22
- mov.b #10,&GZAIJL
- mov.b #10,&TOUZHI
- mov #S_code,&Y_code
- mov #1010h,&ICKCMKL
- mov.b #38h,&P2DIR ; 定义P2.0,1,2为输入口
- mov.b #0ffh,&P1DIR ; 定义P1.7,6,5,4,3,2,1,0为输出口
- clr.b &P1SEL ; 端口定义
- clr.b &P2SEL ; 端口定义
- bic.b #13h,&IE1 ; 关闭振荡器故障中断
- INIT1 bis.b #ICRT,&P1OUT
- mov.b #ICK,&P2IES ; 定义ICKC中断输入口下降沿有效
- mov.b #ICK,&P2IE ; 开ICKC口中断
- clr.b &P2IFG
- LP_3 bis.w #LPM2+GIE,SR ; LPM1低功耗
- nop
- ;-------------------------RAMCLR 清除子程序------------------------------
- RAMCLR mov #GUODU4,r4
- CLRD clr 0(r4)
- incd r4
- cmp #NICKD+1,r4
- jlo CLRD
- ret
- ;-------------------------------------------------------------------------
- P2INT bit.b #ICK,&P2IFG
- jnz ICKC
- clr.b &P2IFG
- reti
- ;------------------------ICKC IC卡插入处理-----------------------------
- ICKC ; mov.b #30h,&DCOCTL ; 系统时钟频率:
- ; mov.b #85h,&BCSCTL1
- clr r10
- call #SONGXAD0 ;插卡清显示屏
- call #YANSHI100
- clr.b &P2IFG
- bit.b #ICK,&P2IN ;延时100ms防抖
- jnz SONGXAD
- bis.b #ICRT,&P1OUT
- mov.b #06h,r5 ; 读卡标识
- call #RD88
- cmp.b #68h,r6
- jeq ICKC00
- mov #5200h,r10 ;不是用户卡" 68"送显"NNNN"退出
- jmp SONGXAD
- ICKC00 mov.b #04h,r5 ; 读用户号
- call #RD88
- mov.b r6,r7
- mov.b #05h,r5 ; 读用户号
- call #RD88
- mov.b r6,r8
- swpb r7
- bis r7,r8
- cmp #1234h,r8
- jeq ICMM
- mov #3f00h,r10 ;用户号比较出错送显"0000",退出
- jmp SONGXAD
- ICMM mov.b #0ch,r5 ; 读密码比较次数
- call #RD88
- cmp.b #07fh,r6
- jhs ICKC01
- mov #7600h,r10 ;已经有密码错,送显"HHHH"退出
- jmp SONGXAD
- ICKC01 ; mov #S_code,r8 ; 用户密码比较
- mov.b #0ah,r5
- call #CMP_88
- tst.b r7
- jnz ICKC005
- mov #4000h,r10 ; 用户密码有误送显"----"退出
- jmp SONGXAD
- ICKC005 mov #7100h,r10 ;送显"FFFF"退出
- jmp SONGXAD
- ;---------------RST 复位子程序-------------------------------------
- ;入==SD=X CLOK=X PGM=X 出 SD=输入 ICRT=0 CLOK=0 PGM=0
- RST_88 bic.b #SD,P1DIR ;SD为输入
- bis.b #ICRT,&P1OUT
- bic.b #PGM,&P1OUT
- call #DELY
- bic.b #CLOK,&P1OUT
- call #DELY
- bic.b #ICRT,&P1OUT
- call #DELY
- ret
- ;------------WR88 写字子程序-------------------------------------------------
- ;入==R4=单元地址,出==R6=待写入数据
- WR88 bis.b #SD,&P1DIR ;=====SD=输出
- call #RST_88 ;复位
- call INC_88 ;修改地址
- call #ERASEW ;先擦除
- call #RST_88 ;复位
- call INC_88 ;修改地址
- call #BT88_W ;写高字节
- swpb r6
- call #BT88_W ;写低字节
- ret
- ;-------------CMP 主密码比较----------------------------------------------------
- ; 入 r6=ram密码地址 r5=卡中密码地址 r4=密码长度 r7=1/0密码正确/错误
- ; r8=待比较的密码
- CMP_88 call #RST_88
- mov #0ah,r5 ;卡中密码地址
- call #INC_88
- bis.b #SD,&P1DIR
- CMP881 mov.b #12h,r6 ;密码高字节12
- call #BI88_C
- mov.b #34h,r6 ;密码低字节34
- call #BI88_C
- mov.b #03h,r4
- call #VLD_88
- ret
- ;------------BI 比较8位密码---------------------------------------------------
- ; r6=8位密码
- BI88_C mov #08h,r5 ;比较8位密码
- BC88LP rla.b r6 ; C <-----bit7--<--bit0<---0
- jc HI88_C
- bic.b #SD,&P1OUT
- jmp LO88_C
- HI88_C bis.b #SD,&P1OUT
- LO88_C call #BIT_88
- dec.b r5
- jnz BC88LP
- ret
- ;---------------RD 读字节子程序-------------------------------------
- ;入==R4=单元地址,出==R6=读出数据
- RD88 call #RST_88
- call #INC_88
- BT88_R mov.b #08h,r5
- clr.b r6
- BR88LP bit.b #SD,&P1IN
- jc LO88_R
- clrc
- jmp HI88_R
- LO88_R setc
- HI88_R rlc.b r6
- call #BIT_88
- dec.b r5
- jnz BR88LP
- ret
- ;---------------BIT 位加1 时钟子程序-------------------------------------------
- BIT_88 call #DELY
- bis.b #CLOK,&P1OUT
- call #DELY
- bic.b #CLOK,&P1OUT
- ret
- ;------------------INC_88 修改地址指针------------------------------------------
- ; 入 r5=卡内单元地址
- INC_88 rla r5 ;左移3次=×8
- rla r5 ;单元地址×8位=需移位数
- rla r5
- ICN882 call #BIT_88
- dec r5
- jnz ICN882
- ret
- ;-------------PGM 建立PMP 信号-------------------------------------------------
- PGM_88 bis.b #PGM,&P1OUT
- call #DELY
- bis.b #SD,&P1DIR
- bis.b #CLOK,&P1OUT
- call #DELY
- bic.b #PGM,&P1OUT
- call #YANSHI
- bic.b #CLOK,&P1OUT
- bic.b #SD,&P1DIR
- call #DELY
- call #DELY
- call #DELY
- ret
- ;-----------------ERASEW 擦除地址所指的字--------------------------------
- ERASEW bis.b #SD,&P1OUT
- call #PGM_88
- call #BIT_88
- ret
- ;----------------VLD 校验子程序-----------------------------------------
- VLD_88 bic.b #SD,&P1DIR ;SD=输入 接收信号
- call #DELY
- VLD_888 bit.b #SD,&P1IN
- jnz VLD_881 ;输入为1跳至校验处理
- call #BIT_88
- dec.b r4
- jnz VLD_888
- jmp VLD882
- VLD_881 bic.b #SD,&P1OUT
- call #PGM_88
- bit.b #SD,&P1IN
- ; jnz VLD882
- bis.b #SD,&P1OUT
- call #PGM_88
- bit.b #SD,&P1IN
- jz VLD882
- mov.b #01h,r7
- ret
- VLD882 clr.b r7
- ret
- ;------------BT 写一字节子程序---------------------------------------------
- BT88_W mov.b #08h,r5
- BW88P1 rlc.b r6
- jc HT88W1
- bic.b #SD,&P1OUT
- LO88W1 call #PGM_88
- HT88W1 call #BIT_88
- dec.b r5
- jnz BW88P1
- ret
- ;--------------------------SONGXAD 显示送数-----------------------------
- SONGXAD call #SONGXAD0
- reti
- SONGXAD0 bic.b #RCK,&P2OUT
- mov.b #16,r6
- SONGXAD1 bic.b #CLK,&P1OUT
- rla r10
- jc SONGXAD2
- bic.b #CSD,&P1OUT
- jmp SONGXAD3
- SONGXAD2 bis.b #CSD,&P1OUT
- SONGXAD3 bis.b #CLK,&P1OUT
- dec.b r6
- jnz SONGXAD1
- ; bic.b #CLK,&P1OUT
- bis.b #RCK,&P2OUT
- bic.b #RCK,&P2OUT
- ret
- ;--------------------------------------------------------------
- DELY nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- ret
- ;------------------------YANSHI 5ms延时----------------------------------
- YANSHI push r14
- mov #1000,r14
- YANSHI0 dec r14
- jnz YANSHI0
- pop r14
- ret
- ;-------------------------YANSHI 100ms延时---------------------------------
- YANSHI100 push r13
- mov #300,r13
- YANSHI1001 call #YANSHI
- dec r13
- jnz YANSHI1001
- pop r13
- ret
- ;------------------------------------------------------------------------
- TAB DB 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00h,38h,40h,49h,79h,71h
- ;------------------------------------------------------------------------
- RSEG INTVEC ; MSP430x11x1 Interrupt vectors
- ;------------------------------------------------------------------------
- DW RESET ; no source
- DW RESET ; no source
- DW RESET ; P1.x
- DW P2INT ; P2.x
- DW RESET ; no source
- DW RESET ; no source
- DW RESET ; no source
- DW RESET ; no source
- DW RESET ; Timer_AX
- DW RESET ; Timer_A0
- DW RESET ; Watchdog/Timer, Timer mode
- DW RESET ; Comparator_A
- DW RESET ; no source
- DW RESET ; no source
- DW RESET ; NMI, Osc. fault
- DW RESET ; POR, ext. Reset, Watchdog
- ;------------------------------------------------------------------------
- END main
复制代码
0
|
|
|
|