[求助]8086汇编,读取TLC549
用8255模拟SPI接口读取TLC549。我的程序如下程序代码:
.MODEL TINY ;PC.0-----------------CS----------KZ7 ;PC.1-----------------I/O CLK-----KZ5 ;PA.0-----------------DO----------KZ4 ; Con_8255 EQU 0F003H PC_8255 EQU 0F002H PA_8255 EQU 0F000H EXTRN Display8:NEAR .STACK 300 .DATA buffer DB 8 DUP(0) ;数据临时存放区 .CODE START: MOV AX,@DATA MOV DS,AX MOV ES,AX NOP CALL Init8255 MAIN: CALL Read549 ;从TLC549读取两次AD转换结果 CALL DL2 CALL Read549 CALL DIS_BCD CALL DelayTime ;提取电压数据,转换为非压缩型BCD码,并显示 JMP MAIN ;******************************** ;电压电流转换/显示 ;******************************** DIS_BCD PROC NEAR MOV AX,BX LEA DI,buffer+7 STD MOV AL,10H ;10H表示不需要显示 STOSB ;STD地址减,buffer+7654不显示 STOSB STOSB STOSB STOSB XOR AH,AH MOV BL,51 ;255/51 (16进制的1 = 1/51V) DIV BL OR AL,80H ;加上小数点 MOV BUFFER+2,AL MOV AL,10 MUL AH DIV BL MOV BUFFER+1,AL ;第一位小数 MOV AL,10 MUL AH DIV BL MOV BUFFER,AL ;第二位小数 LEA SI,buffer ;显示 CALL Display8 RET DIS_BCD ENDP ;延时程序 DelayTime PROC NEAR XOR CX,CX ;LOOP $ ;loop $ ;loop $ RET DelayTime ENDP DL1 PROC NEAR PUSH CX ;MOV CX,2000 ;DL11: LOOP DL11 POP CX RET DL1 ENDP DL2 PROC NEAR PUSH CX ;mov CX,20000 ;loop $ POP CX nop nop RET DL2 ENDP ;读操作 Read549 PROC NEAR PUSH CX MOV CX,8 ;数据一共有8位 MOV DX,PC_8255 ;CS=1,CS=0 MOV AL,0FFH OUT DX,AL mov dx,Con_8255 mov al,02H out dx,al nop nop nop nop mov AL,00H OUT DX,AL nop nop nop nop Read549_1: MOV DX,PA_8255 IN AL,DX ROR AL,1 RCL BL,1 MOV DX,Con_8255 ;MOV AL,00H ;CLK高,CS低,TLC549在外部CLK下降沿输出数据 ;OUT DX,AL mov AL,03H out dx,al call DL1 MOV AL,02H ;CLK低,CS低 OUT DX,AL LOOP Read549_1 MOV AL,03H MOV DX,Con_8255 out DX,AL mov al,01H out dx,al POP CX RET Read549 ENDP Init8255 PROC NEAR MOV DX,Con_8255 MOV AL,90H OUT DX,AL RET Init8255 ENDP END START
读出的结果总是10H
求人指导啊!
邮箱676665498@