DAC0832
一、使用软件延时方法实现锯齿波、方波、三角波、梯形波。
1.1 延时法,16 次产生锯齿波,最高点-5V
;0832 Ua-示波器观察延时法
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 00H
AGAIN:
MOV DX, 280H;端口号
OUT DX, AL
CALL DELAY
ADD AL, 10H;从00H-10H-20H-30H-40H-50H-60H-70H-80H-90H-A0H-B0H-C0H-D0H-E0H-F0H一共16次,后面又回到00H
JMP AGAIN
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH CX
MOV CX, 0FFFFH
L1:
LOOP L1
MOV CX, 0FFFFH
L2:
LOOP L2
POP CX
RET
DELAY ENDP
CODE ENDS
END START
1.2 延时法,32 次产生锯齿波,最高点-5V
;0832 Ua-示波器观察延时法
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
;0832cs280H~287H
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 00H
AGAIN:
MOV DX, 280H
OUT DX, AL
CALL DELAY
ADD AL, 08H;从00000000-00001000-0001100……11111000一共32次,后面又回到00H
JMP AGAIN
MOV AH, 4CH
INT 21H
DELAY PROC NEAR
PUSH CX
MOV CX, 0FFFFH
L1:
LOOP L1
MOV CX, 0FFFFH
L2:
LOOP L2
POP CX
RET
DELAY ENDP
CODE ENDS
END START
2.延时法,产生方波,最高点-5V
;0832 Ua-示波器观察延时法
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 5H
AGAIN:
MOV DX, 280H;端口号
OUT DX, AL
CALL DELAY
NEG AL;取相反数
JMP AGAIN
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH CX
MOV CX, 0FFFFH
L1:
LOOP L1
MOV CX, 0FFFFH
L2:
LOOP L2
POP CX
RET
DELAY ENDP
CODE ENDS
END START
3.延时法,16 次产生三角波,最高点-2.5V
;0832 Ua-示波器观察延时法
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 0H
DRAW_ASCEND_LINE: ;画上升的边
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 80H
JZ DRAW_DESCEND_LINE ;跳转到画下降的边
ADD AL, 08H
JMP DRAW_ASCEND_LINE
DRAW_DESCEND_LINE: ;画下降的边
SUB AL, 08H
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 00H
JZ DRAW_ASCEND_LINE ;跳转到画上升的边
JMP DRAW_DESCEND_LINE
MOV AH,4CH ;退出到 DOS, 即程序运行结束
INT 21H
DELAY PROC NEAR
PUSH CX
MOV CX, 200H
L1:
LOOP L1
POP CX
RET
DELAY ENDP
CODE ENDS
END START
4.延时法,16 次产生梯形波,最高点-2.5V
;0832 Ua-示波器观察延时法
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 00H
DRAW_ASCEND_LINE: ;画上升的腰
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 80H
JZ DRAW_HORIZON_LINE ;跳转到画梯形上底
ADD AL, 08H
JMP DRAW_ASCEND_LINE
DRAW_HORIZON_LINE: ;画梯形上底
MOV CX, 10H
AGAIN:
OUT DX, AL
CALL DELAY
LOOP AGAIN
DRAW_DESCEND_LINE: ;画下降的腰
SUB AL, 08H
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 00H
JZ DRAW_ASCEND_LINE;跳转到画上升的腰
JMP DRAW_DESCEND_LINE
MOV AH, 4CH ;退出到 DOS, 即程序结束
INT 21H
DELAY PROC NEAR
PUSH CX
MOV CX, 200H
L1:
LOOP L1
POP CX
RET
DELAY ENDP
CODE ENDS
END START
一、使用硬件【8253+8255】延时方法实现锯齿波、方波、三角波、梯形波。
1.1 16 次产生锯齿波,最高点-5V
;0832 Ua-示波器观察
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
;8253 -288H~28BH;CLK0-2MHZ;GATE0-VCC;OUT0-PC7
;8255 -290H~293H;
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
T0_8253 EQU 288H
KZ_8253 EQU 28BH
PC_8255 EQU 292H
KZ_8255 EQU 293H
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
CALL Init_8253
CALL Init_8255
MOV AL, 00H
AGAIN:
MOV DX, 280H;端口号
OUT DX, AL
CALL DELAY
ADD AL, 10H
JMP AGAIN
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH DX
PUSH AX
NEXT1:
MOV DX,PC_8255
IN AL,DX
AND AL,80H;1000 0000B-PC7
JNZ NEXT1
NEXT2:
MOV DX,PC_8255
IN AL,DX
AND AL,80H
JZ NEXT2
POP AX
POP DX
RET
DELAY ENDP
Init_8253 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8253
MOV AL,00100111B ;选择通道0-OUT0,写入高字节,方式3,用BCD码
OUT DX,AL
MOV DX,T0_8253
MOV AL,20H
OUT DX,AL
;8253产生1mS的连续方波*/
POP AX
POP DX
RET
Init_8253 ENDP
;初始化8255
Init_8255 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8255 ;8255方式字控制字控制;10011000
MOV AL,98H
OUT DX,AL
POP AX
POP DX
RET
Init_8255 ENDP
CODE ENDS
END START
2. 产生方波,最高点-5V
;0832 Ua-示波器观察
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
;8253 -288H~28BH;CLK0-2MHZ;GATE0-VCC;OUT0-PC7
;8255 -290H~293H;
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
T0_8253 EQU 288H
KZ_8253 EQU 28BH
PC_8255 EQU 292H
KZ_8255 EQU 293H
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
CALL Init_8253
CALL Init_8255
MOV AL, 5H
AGAIN:
MOV DX, 280H;端口号
OUT DX, AL
CALL DELAY
NEG AL
JMP AGAIN
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH DX
PUSH AX
NEXT1:
MOV DX,PC_8255
IN AL,DX
AND AL,80H;1000 0000B-PC7
JNZ NEXT1
NEXT2:
MOV DX,PC_8255
IN AL,DX
AND AL,80H
JZ NEXT2
POP AX
POP DX
RET
DELAY ENDP
Init_8253 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8253
MOV AL,00100111B ;选择通道0-OUT0,写入高字节,方式3,用BCD码
OUT DX,AL
MOV DX,T0_8253
MOV AL,20H
OUT DX,AL
;8253产生1mS的连续方波*/
POP AX
POP DX
RET
Init_8253 ENDP
;初始化8255
Init_8255 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8255 ;8255方式字控制字控制;10011000
MOV AL,98H
OUT DX,AL
POP AX
POP DX
RET
Init_8255 ENDP
CODE ENDS
END START
3. 16 次产生三角波,最高点-5V
;0832 Ua-示波器观察
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
;8253 -288H~28BH;CLK0-2MHZ;GATE0-VCC;OUT0-PC7
;8255 -290H~293H;
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
T0_8253 EQU 288H
KZ_8253 EQU 28BH
PC_8255 EQU 292H
KZ_8255 EQU 293H
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
CALL Init_8253
CALL Init_8255
MOV AL, 00H
DRAW_ASCEND_LINE: ;画上升的边
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 80H
JZ DRAW_DESCEND_LINE ;跳转到画下降的边
ADD AL, 08H
JMP DRAW_ASCEND_LINE
DRAW_DESCEND_LINE: ;画下降的边
SUB AL, 08H
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 00H
JZ DRAW_ASCEND_LINE ;跳转到画上升的边
JMP DRAW_DESCEND_LINE
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH DX
PUSH AX
NEXT1:
MOV DX,PC_8255
IN AL,DX
AND AL,80H;1000 0000B-PC7
JNZ NEXT1
NEXT2:
MOV DX,PC_8255
IN AL,DX
AND AL,80H
JZ NEXT2
POP AX
POP DX
RET
DELAY ENDP
Init_8253 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8253
MOV AL,00100111B ;选择通道0-OUT0,写入高字节,方式3,用BCD码
OUT DX,AL
MOV DX,T0_8253
MOV AL,20H
OUT DX,AL
;8253产生1mS的连续方波*/
POP AX
POP DX
RET
Init_8253 ENDP
;初始化8255
Init_8255 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8255 ;8255方式字控制字控制;10011000
MOV AL,98H
OUT DX,AL
POP AX
POP DX
RET
Init_8255 ENDP
CODE ENDS
END START
4. 16 次产生梯形波,最高点-5V
;0832 Ua-示波器观察
;0832cs280H~287H
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
;8253 -288H~28BH;CLK0-2MHZ;GATE0-VCC;OUT0-PC7
;8255 -290H~293H;
;Ua=-Uxef/256*N;Ub=-Uxef/256*N-5
DATA SEGMENT
T0_8253 EQU 288H
KZ_8253 EQU 28BH
PC_8255 EQU 292H
KZ_8255 EQU 293H
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA, SS:STACK1
START:
MOV AX, DATA
MOV DS, AX
CALL Init_8253
CALL Init_8255
MOV AL, 00H
DRAW_ASCEND_LINE: ;画上升的腰
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 80H
JZ DRAW_HORIZON_LINE ;跳转到画梯形上底
ADD AL, 08H
JMP DRAW_ASCEND_LINE
DRAW_HORIZON_LINE: ;画梯形上底
MOV CX, 10H
AGAIN:
OUT DX, AL
CALL DELAY
LOOP AGAIN
DRAW_DESCEND_LINE: ;画下降的腰
SUB AL, 08H
MOV DX, 280H
OUT DX, AL
CALL DELAY
CMP AL, 00H
JZ DRAW_ASCEND_LINE;跳转到画上升的腰
JMP DRAW_DESCEND_LINE
MOV AH, 4CH; 退出到 DOS,即结束程序运行
INT 21H
DELAY PROC NEAR
PUSH DX
PUSH AX
NEXT1:
MOV DX,PC_8255
IN AL,DX
AND AL,80H;1000 0000B-PC7
JNZ NEXT1
NEXT2:
MOV DX,PC_8255
IN AL,DX
AND AL,80H
JZ NEXT2
POP AX
POP DX
RET
DELAY ENDP
Init_8253 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8253
MOV AL,00100111B ;选择通道0-OUT0,写入高字节,方式3,用BCD码
OUT DX,AL
MOV DX,T0_8253
MOV AL,20H
OUT DX,AL
;8253产生1mS的连续方波*/
POP AX
POP DX
RET
Init_8253 ENDP
;初始化8255
Init_8255 PROC
PUSH DX
PUSH AX
MOV DX,KZ_8255 ;8255方式字控制字控制;10011000
MOV AL,98H
OUT DX,AL
POP AX
POP DX
RET
Init_8255 ENDP
CODE ENDS
END START