ORG 0000H
AJMP START
ORG 0040H
START:
MOV SP,#60H
MOV
A,#00H
MOV DPTR,#4000H 锯齿波缓冲区首址
NEXT:
MOVX @DPTR,A
填锯齿波数据
INC DPTR
INC A
JZNEXT1
写完256个数据后退出
AJMP NEXT
NEXT1:
MOV A,#00H
MOV
R0,#00H
MOV DPTR,#4100H 三角波缓冲区首址
NEXT2:
MOVX @DPTR,A
填三角波数据(上升部分)
INC DPTR
ADD A,#02H
INC R0
CJNE
R0,#80H,NEXT2
SUBB A,#02H
CLR C
NEXT3:
MOVX
@DPTR,A 填三角波数据(下升部分)
INC DPTR
SUBB A,#02H
INC
R0
CJNE R0,#00H,NEXT3写完256个数据后退出
--------------SIN
WAVE------------------
MOV R0,#10H
MOV R1,#00H
MOV
DPTR,#STEP 步长的浮点ASCII起始地址
READ:
MOV A,R1
MOVC
A,@A+DPTR
MOV @R0,A
INC R1
INC R0
CJNE
R1,#0AH,READ 将程序区的数据移到内部RAM区
MOV R0,#10H 十进制浮点数的首址
MOV
R1,#30H 三字节浮点数的首址(步长)
LCALL %FDTB3
带符号十进制数ASCII码浮点数
转换成三字节浮点数
MOV R2,#00H
MOV R3,#80H
电压的最大值
MOV R0,#18H 三字节浮点数的首址(最大电压)
LCALL %WTF31
双字节无符号数转换成
三字节浮点数
MOV R3,#00H STEP LENGTH
MOV
DPTR,#4200H 正弦波数据表首址
CALCSIN:
PUSH 3
PUSH DPH
PUSH
DPL
MOV R2,#00H
MOV R0,#38H FLOAT STEP ADDRESS
LCALL %WTF31 双字节无符号数转换成
三字节浮点数
MOV R0,#30H
MOV
R1,#38H
LCALL %FMUL3 三字节浮点数乘法子程序
MOV 40H,R4 MUL
ADDRESS
MOV 41H,R2
MOV 42H,R3
MOV R0,#40H
MOV R1,#48H SIN VALUE ADDRESS
LCALL %FSIN3
三字节浮点数正弦子程序
MOV R0,#18H
MOV R1,#48H
LCALL
%FMUL3 三字节浮点数乘法子程序
MOV 38H,R4 MUL ADDRESS
MOV
39H,R2
MOV 3AH,R3
MOV R0,#38H
LCALL %FTW3
三字节浮点数转换成
双字节无符号数
POP DPL
POP DPH
MOV
A,#80H
ADD A,R3
JNZ SIN90判断峰值
MOV
A,0FFH
SIN90:
MOVX @DPTR,A 把计算值填表
MOV A,DPL
ORL A,#80H 计算sin(a+180)
MOV DPL,A
MOV A,#80H
CLR C
SUBB A,R3
MOVX @DPTR,A 把计算值填表
MOV
A,DPL
ANL A,#7FH
MOV DPL,A
INC DPTR
POP
3
INC R3
CJNE R3,#80H,CALCSIN
判断计算完毕
波形显示程序
WAVE:
MOV R1,#00H
WAVE1:
MOV
DPTR,#4000H 显示锯齿波(256次)
LCALL D_A
DJNZ
R1,WAVE1
WAVE2:
MOV DPTR,#4100H 显示三角波(256次)
LCALL
D_A
DJNZ R1,WAVE2
WAVE3:
MOV DPTR,#4200H
显示正弦波(256次)
LCALL D_A
DJNZ R1,WAVE3
SJMP WAVE
循环显示
D_A:
MOV R0,#00H 置计数器
LOOP:
MOVX
A,@DPTR 查波形表
PUSH DPL
PUSH DPH
MOV
DPTR,#D_APORT
MOVX @DPTR,A 启动 D/A
POP DPH
POP
DPL
INC DPTR改变表格地址
INC R0
CJNE
R0,#00H,LOOP判断是否显示完
RET
步长的十进制ASCII码浮点数
STEP DB
30H,2EH,30H,32H,34H,35H,34H,34H,2CH'0.024544,'
END
T0832-1.asmD/A转换实验,产生方波
***************根据CHECK配置信息修改下列符号值*******************
IOY0 EQU 9C00H 片选IOY0对应的端口始地址
*****************************************************************
DA0832 EQU IOY0+00H*4 DA0832的端口地址
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
DATA SEGMENT
STR1 DB 'DA0832: Square Wave $'定义显示的字符串
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET STR1显示字符串
MOV AH,9
INT 21H
LOOP1: MOV DX,DA0832 写00H,输出低电平
MOV AL,00H
OUT DX,AL
CALL DALLY
MOV DX,DA0832 写0FH,输出高电平
MOV AL,7FH
OUT DX,AL
CALL DALLY
MOV AH,1 判断是否有按键按下
INT 16H
JZ LOOP1 无按键则跳回继续循环,有则退出
QUIT: MOV AX,4C00H 返回到DOS
INT 21H
DALLY PROC NEAR 软件延时子程序
PUSH CX
PUSH AX
MOV CX,0050H
D1: MOV AX,5000H
D2: DEC AX
JNZ D2
LOOP D1
POP AX
POP CX
RET
DALLY ENDP
CODE ENDS
END START
T0832-2.asm
D/A转换实验,产生三角波
***************根据CHECK配置信息修改下列符号值*******************
IOY0 EQU 9C00H 片选IOY0对应的端口始地址
*****************************************************************
DA0832 EQU IOY0+00H*4DA0832的端口地址
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
DATA SEGMENT
STR1 DB 'DA0832: Triangle Wave $'定义显示的字符串
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET STR1显示字符串
MOV AH,9
INT 21H
LOOP1: MOV AL,00HD/A转换起始值
UP: MOV DX,DA0832 启动D/A转换
OUT DX,AL
CALL DALLY
INC AL
CMP AL,7FH
JNE UP
DOWN: MOV DX,DA0832
OUT DX,AL
CALL DALLY
DEC AL
CMP AL,00H
JNE DOWN
MOV AH,1 判断是否有按键按下
INT 16H
JZ LOOP1 无按键则跳回继续循环,有则退出
QUIT: MOV AX,4C00H 返回到DOS
INT 21H
DALLY PROC NEAR 软件延时子程序
PUSH CX
PUSH AX
MOV CX,0010H
D1: MOV AX,0100H
D2: DEC AX
JNZ D2
LOOP D1
POP AX
POP CX
RET
DALLY ENDP
CODE ENDS
END START
IOY0 EQU 0D400H 片选IOY0端口始地址IOY1 EQU 0D440H 片选IOY1端口始地址
IOY2 EQU 0D480H 片选IOY2端口始地址
IOY3 EQU 0D4C0H 片选IOY3端口始地址
********************************************
ADC0809 EQU IOY0+00H ADC0809端口地址
PA55EQU IOY1+00H 8255的A口地址
PB55EQU IOY1+04H 8255的B口地址
PC55EQU IOY1+08H 8255的C口地址
PCTLEQU IOY1+0CH 8255的控制寄存器地址
DAC0832 EQU IOY2+00H DAC0832端口地址
TIMER0 EQU IOY3+00H 8254计数器0端口地址
TIMER1 EQU IOY3+04H 8254计数器1端口地址
TIMER2 EQU IOY3+08H 8254计数器2端口地址
TCTLEQU IOY3+0CH 8254控制寄存器端口地址
STACK1 SEGMENT STACK
DW 256 DUP(?)
STACK1 ENDS
DATA SEGMENT
STR1 DB'Please input password:',0AH,0DH,'$'
STR2 DB'The password is not right !!!Please try again!!!',0AH,0DH,'$'
STR3 DB'Welcome to the signal creat machine',0AH,0DH,'Loading ADC0809.....',0AH,0DH,'$'
STR4 DB 'The passward is right',0AH,0DH,'$'
DTABLE DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H 7段数码管的段位值
STABLE DB80H,8CH,98H,0A5H,0B0H,0BCH,0C7H,0D1H,0DAH,0E2H,0EAH,0F0H,0F6H,0FAH,0FDH,0FFH,0FFH,0FDH,0FAH,0F6H,0F0H,0EAH,0E2H,0DAH,0D1H,0C7H,0BCH,0B0H,0A5H,98H,8CH,80H,7FH,73H,67H,5AH,4FH,43H,38H,2EH,25H,1DH,15H,0FH,09H,05H,02H,00H,00H,02H,05H,09H,0FH,15H,1DH,25H,2EH,38H,43H,4FH,5AH,67H,73H,7FH
PASSWORD DB 41H,42H,43H,44H 预设密码
GAO DB 1 DUP (?) 预留显示十位
DIW DB 1 DUP (?) 预留显示个位
PW DB 4 DUP (?) 密码预留
YU DB 20 DUP (?) 预留20个空间存放数据
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
CALL CLK ADC0809 CLK输入
MOV DX,PCTL 初始化8255工作方式
MOV AL,88H 1000 1000方式0,A口,B口输出,C口高四位输入
OUT DX,AL
L0: CALL DIS
MOV DX,OFFSET STR1 显示提示信息
MOV AH,9
INT 21H
CALL DIS
*******识别密码***********
L1: MOV CX,4
MOV SI,OFFSET PW
L: MOV AH,01H 输入密码
INT 21H
MOV [SI],AL
INC SI
CMP AL,45H 检测有无E
JZ E
LOOP L
MOV CX,4
MOV SI,OFFSET PASSWORD取PASSWORD的偏移地址
MOV DI,OFFSET PW
TE: MOV AL,[DI]
CMP AL,[SI]
JNE TE1
INC DI
INC SI
LOOP TE
JMP Q
TE1: MOV DX,OFFSET STR2 显示密码错误
MOV AH,9D
INT 21H
JMP L0
E: JMP QUIT
*****启动ADC0809的INO***********
Q: MOV DX,OFFSET STR4
MOV AH,09H
INT 21H
MOV DX, OFFSET STR3 显示提示信息
MOV AH,09H
INT 21H
MOV AH,00H 将AH清零用于加法
MOV CX,20D
L2: MOV DX,ADC0809 启动0809的IN0
OUT DX,AL
L3: CALL DALLY
*****读取EOC的值****************
MOV DX,PC55
IN AL,DX 读C口的值
TEST AL,80H 检测出C7的值是否为1
JZ L3 C7不为1则跳到L3
*****读取0809IN0的值*************
CALL SIN
JMP L0
MOV DX,ADC0809 读取0809IN0的值
IN AL,DX
ADD AH,BL
LOOP L2 求20次数据的和
MOV AL,AH
MOV BL,20D
DIV BL 求采集数据20次的平均值(修改)
MOV BH,AL
MOV BL,AL
MOV CL,04H
SHR AL,CL 取出十位
MOV GAO,AL 存十位的值
MOV AL,BL
AND AL,0FH 取出个位
MOV DIW,AL 存个位的值
CALL DIS 调用数码管显示函数
CALL DIS
MOV AL,BL
CMP AL,15H
JL L4
MOV AL,BL
CMP AL,80H
JL L5
MOV AL,BL
CMP AL,0A0H
JL L6
MOV AL,BL
CMP AL,0C0H
JL L7
CALL FANG1K
JMP L0
L4: CALL JIETI
JMP L0
L5: CALL SIN
JMP L0
L6: CALLTIXING
JMP L0
L7: CALL FANG500
JMP L0
QUIT: MOV AX,4C00H 结束程序退出
INT 21H
DIS PROC NEAR 显示子函数
PUSH AX
PUSH DX
PUSH BX
MOV AL,0EFH 选通位LED 1110 1111
MOV DX,PA55
OUT DX,AL
MOV SI,OFFSET GAO 取个位地址
MOV AL,[SI] 取个位数据
MOV BX,OFFSET DTABLE
AND AX,00FFH
ADD BX,AX
MOV AL,[BX]
MOV DX,PB55
OUT DX,AL
MOV AL,0DFH 选通个位LED 1101 1111
MOV DX,PA55
OUT DX,AL
MOV SI,OFFSET DIW 取个位地址
MOV AL,[SI] 取个位数据
MOV BX,OFFSET DTABLE
AND AX,00FFH
ADD BX,AX
MOV AL,[BX]
MOV DX,PB55
OUT DX,AL
POP BX
POP DX
POP AX
RET
DIS ENDP
CLK PROC NEAR 方波CLK时钟18.432K子程序
****初始化8254计数器0工作在方式3,以十进制计数,初值为100*******
PUSH DX 保护现场
PUSH AX 保护现场
MOV DX,TCTL
MOV AL,17H 0001 0111B
OUT DX,AL
MOV DX,TIMER0 装初值100
MOV AL,100D
OUT DX,AL
POP AX 恢复现场
POP DX 恢复现场
RET
CLK ENDP
FANG1K PROC NEAR 方波1KHz子程序
***初始化8254计数器1工作在方式3,以十进制计数,初值为184******
PUSH DX 保护现场
PUSH AX 保护现场
MOV DX,TCTL
MOV AL,57H 0101 0111B
OUT DX,AL
MOV DX,TIMER1
MOV AL,0B8H184
OUT DX,AL
F: CALL DIS
MOV DL,0FFH 判断主键盘有无键按下
MOV AH,6
INT 21H
JZ F
POP AX 恢复现场
POP DX 恢复现场
RET
FANG1K ENDP
FANG500 PROC NEAR 方波500Hz子程序
***初始化8254计数器1工作在方式3,以十进制计数,初值为368******
PUSH DX 保护现场
PUSH AX 保护现场
MOV DX,TCTL
MOV AL,77H 0111 0111B
OUT DX,AL
MOV DX,TIMER1
MOV AL,70H368D分高低位写入
OUT DX,AL
MOV AL,01H
OUT DX,AL
F1: CALL DIS
MOV DL,0FFH 判断主键盘有无键按下
MOV AH,6
INT 21H
JZ F1
POP AX 恢复现场
POP DX 恢复现场
RET
FANG500 ENDP
JIETI PROC NEAR 阶梯波子程序
PUSH DX
PUSH AX
J0: MOV AL,00HAL=0
J1: MOV DX,DAC0832AL OUT
OUT DX,AL
ADD AL,33H
CALL DALLY1
CMP AL,0FFH
JNE J1
CALL DIS
MOV DL,0FFH 判断主键盘有无键按下
MOV AH,6
INT 21H
JZ J0
POP AX
POP DX
RET
JIETI ENDP
SIN PROC NEAR 正弦波子程序
PUSH AX
PUSH BX
PUSH DX
S0: MOV BX,10H
S1: MOV SI,OFFSET STABLE
MOV CX,64D
S2: MOV AL,[SI]
MOV DX,DAC0832
OUT DX,AL
INC SI
LOOP S2
JMP S1
DEC BX
CMP BX,00H
JNE S1
CALL DIS
MOV DL,0FFH 判断主键盘有无键按下
MOV AH,6
INT 21H
JZ S0
POP DX
POP BX
POP AX
RET
SIN ENDP
TIXING PROC NEAR 梯形波子程序
PUSH AX
PUSH DX
PUSH BX
T: MOV BX,10H
MOV AL,00H
MOV DX,DAC0832
OUT DX,AL
T0: MOV AL,33H
T1: MOV DX,DAC0832
OUT DX,AL
INC AL
CMP AL,0FFH
JNE T1
CALL DALLY1
T2: OUT DX,AL
DEC AL
CMP AL,33H
JNE T2
DEC BX
CMP BX,00H
JNE T0
CALL DIS
MOV DL,0FFH 判断主键盘有无键按下
MOV AH,6
INT 21H
JZ T
POP BX
POP DX
POP AX
RET
TIXING ENDP
****延时子程序**********************
DALLY1 PROC NEAR
PUSH CX
PUSH AX
MOV CX,1000H
D1: MOV AX,0100H
D2: DEC AX
JNZ D2
LOOP D1
POP AX
POP CX
RET
DALLY1 ENDP
DALLY PROC NEAR
PUSH CX
PUSH AX
MOV CX,4000H
D3: MOV AX,0600H
D4: DEC AX
JNZ D4
LOOP D3
POP AX
POP CX
RET
DALLY ENDP
CODE ENDS
END START
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)