DATA1 SEGMENT
; TABLE DB R(S*N) DUP (?) ;S为选针器数=16,N为总针数=1024,R为转数=1,2,3...。
;R循环次数R(S*N)当R等于1时为花型图片的基本单元,R的最大数(不包括纵行外循环)要求能达到200。
TABLE1
DB 01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,01H,00H,00H,00H,00H,00H,00H,00H
DB 00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,01H,00H,00H,00H,00H,00H,00H
DB 00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H
DB 00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H
DB 00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H
DB 00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H
DB 00H,00H,00H,00H,00H,00H,01H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,00H
DB 00H,00H,00H,00H,00H,00H,00H,01H,01H,00H,00H,00H,00H,00H,00H,00H,01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H
DATA1 ENDS
STACK1 SEGMENT STACK 'STG'
DW 256 DUP(?) ;是否可以,还是要通过其它方法实现?
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA1,SS:STACK1
BEG: MOV AX,DATA1 ;设置DS
MOV DS,AX
LEA DI,TABLE1 ;表首址
MOV BL,0 ;初始列号,实际是16列
MOV CX,16 ;外循环计数初值,即转数
LOP1: PUSH CX ;暂存外循环计数的初值,循环时CL=CL-1
INC BL
MOV AL,10000001B ;设置8255-1工作方式为0,A口输出,B口输出,C口输入
MOV DX,303H ;8255-1控制字寄存器端口地址
OUT DX,AL ;写入控制字寄存器
TEST1: MOV DX,302H ;8255-1C口端口地址
IN AL,DX ;读C口外设状态信息,即接近开关,PC0的状态信息是1/0
TEST AL,01H ;测试8255-1C口状态CF=1数据准备就绪等待,CF=0转移到下一步,即开始内循环,对否?
JC TEST1
MOV AL,00H
MOV DX,301H
OUT DX,AL
MOV BX,0 ;初始行号
MOV CX,1024
LOP2: INC BX ;列号计数加1,即列地址从0开始进入第一个16列数据输出
MOV AL,BL
MUL BX
MOV AL,00000101B ;设置8253计数器0,工作方式2(因初值不修正时能自动重复设定)读写低8位,二进制
MOV DX,30FH ;8253控制字寄存器端口地址
OUT DX,AL ;写入控制字到寄存器
MOV AL,10 ;设置计数初值,因不能是整数,如何修正,中间还应加一段程序?
MOV DX,30FH
OUT DX,AL ;写入计数器0的计数初值
MOV AL,00H ;设置计数器0通道的计数值的锁存命令字
MOV DX,30CH ;将锁存命令字写入寄存器,锁存命令字读一次后必须写一次,否则第二次就读不到计数值
OUT DX,AL
TEST2: IN AL,00H ;读计数器0的计数值
TEST AL,00H ;测试计数值CF=0转移到下一步,CF=1等待,对否?
JNC TEST2
MOV DX,300H ;输出内存数据,是否应16个字存储单元,一个字存储单元对应一个选针器,
;内含选针器的地址和8个选针器中的一个选针1/0信息,16个选针器的8个选针点都是一一对应的。
;是否可将16个选针器的地址先设置好,这样就能发16个低8位的选针信息1/0就方便了
OUT DX,AX ;将数据写入8255-1B口置PB0=0作为选针器的选通信号
INC DI ;表数据+1
LOOP LOP2 ;内循环开始
POP CX ;内循环计数器CX=CX+1
LOOP LOP1 ;外循环开始
MOV AH,4CH ;返回DOS系统
INT 21H
CODE ENDS ;结束
END BEG
想用电脑控制织布机,读入花型数据,这里就用00H,01H表示了。
硬件应该已经接好了,用厂家提供的程序可以运转。
8255上的指示灯怎么都不亮,没有数据?