1、实验五 DAAD转换实验学实验五 D/A、A/D转换实验一、实验目的 了解数/模、模/数转换基本原理,掌握DAC0832、ADC0809的使用方法; 掌握定时数据采集程序的编制方法。二、实验内容 1、D/A转换实验通过0832D/A转换输出一个从0V开始逐渐升至5V,再从5V降至0V的可变电压输出驱动直流电机。(1)实验接线图 D/A转换实验接线图(2)实验程序框图 (3)实验程序清单CODE SEGMENT ;H0832-2.ASM 0-5vASSUME CS:CODEDAPORT EQU 0FF80hPA EQU 0FF20H ;字位口PB EQU 0FF21H ;字形口PC EQU 0F
2、F22H ;键入口 ORG 1110HSTART: JMP START0BUF DB ?,?,?,?,?,?data1: db 0c0h,0f9h,0a4h,0b0h,99h,92hdb 82h,0f8h,80h,90h,88h,83h,0c6h,0a1h db 86h,8eh,0ffh,0ch,89h,0deh,0c7hdb 8ch,0f3h,0bfh,8FHSTART0: call buf1DACON0: MOV AL,00HDACON1: MOV DX,DAPORT OUT DX,AL push ax call conv MOV CX,0040HDISCON: PUSH CX call
3、disp POP CX LOOP DISCON pop ax INC AL CMP AL,00H JNZ DACON1 MOV AL,0FFHDACON2: MOV DX,DAPORT OUT DX,AL push ax call conv MOV CX,0040HDISCON2: PUSH CX call disp POP CX LOOP DISCON2 pop ax DEC AL CMP AL,0FFH JNZ DACON2 JMP DACON0CONV: MOV AH,AL AND AL,0FH MOV BX,OFFSET BUF MOV BX+5,AL MOV AL,AH AND AL
4、,0F0H MOV CL,04H SHR AL,CL MOV BX+4,AL RETDISP: MOV AL,0FFH ;00H MOV DX,PA OUT DX,AL MOV CL,0DFH ;20H; 5ms显示子程序 MOV BX,OFFSET BUFDIS1: MOV AL,BX MOV AH,00H PUSH BX MOV BX,OFFSET DATA1 ADD BX,AX MOV AL,BX POP BX MOV DX,PB OUT DX,AL MOV AL,CL MOV DX,PA OUT DX,AL PUSH CXDIS2: MOV CX,00A0HDELAY: LOOP DE
5、LAY POP CX CMP CL,0FEH ;01H JZ LX1 INC BX ROR CL,1 ;SHR CL,1 JMP DIS1LX1: MOV AL,0FFH MOV DX,PB OUT DX,AL RETBUF1: MOV BUF,00H MOV BUF+1,08H MOV BUF+2,03H MOV BUF+3,02H MOV BUF+4,00H MOV BUF+5,00H RETDELY: PUSH CXDEL2: PUSH CXDEL3: PUSH CX LOOP $ POP CX LOOP DEL3 POP CX LOOP DEL2 POP CX LOOP DELY RE
6、TCODE ENDS END START2、A/D转换实验(数据采集)利用实验系统上电位器提供的可调电压作为0809模拟信号的输入,编制程序,将模拟量转换为数字量,通过数码管显示出来。(1)实验接线图 D/A转换实验接线图(2)编程指南 ADC0809的START端为A/D转换启动信号,ALE端为通道选择地址的锁存信号,实验电路中将其相连,以便同时锁存通道地址并开始A/D采样转换,其输入控制信号为CS和WR,故启动A/D转换只须如下两条指令:MOV DX,ADPORT ;ADC0809端口地址 OUT DX,AL ;发CS和WR信号并送通道地址用延时方式等待A/D转换结果,使用下述指令读取A/
7、D转换结果。 MOV DX,ADPORT ;ADC0809端口地址 INAL,DX 循环不断采样A/D转换的结果,边采样边显示A/D转换后的数字量。(3)实验程序框图 (4)实验步骤 将0809 CS4插孔连到译码输出FF80H插孔、连JX6JX17。将通道0模拟量输入端IN0连电位器W1的中心插头AOUT1(05V)插孔,8MHZT。运行实验程序如在PC机和实验系统联机状态下,运行该实验程序,可用鼠标左键单击菜单栏“文件”或工具栏“打开图标”,弹出“打开文件”的对话框,然后打开598K8ASM文件夹,点击H0809.ASM文件,单击“确定”即可装入A/D转换实验源文件,再单击工具栏中编译装载
8、,即可完成源文件自动编译、装载目标代码功能,再单击“调试”中“R运行”或工具图标运行,即开始运行程序。如果在没有PC机的情况下,则在8086K系统显示监控提示符“P.”时,用户段地址固定为0000(省略输入),按SCAL键,输入起始偏移地址1000,按EXEC键,在系统上显示“0809 XX”。“XX”表示输入模拟量转换后的数字量。调节电位器Wl, 显示器上会不断显示新的转换结果。模拟量和数字量对应关系的典型值为:0V00H +2.5V80H +5VFFH按RST键退出。以上两种方式运行结果完全一致,因此,在下面的实验中,不管按何种方式均能运行实验程序。(5)实验程序清单CODE SEGMEN
9、T ;H0809.ASMASSUME CS:CODEADPORT EQU 0FF80hPA EQU 0FF20H ;字位口PB EQU 0FF21H ;字形口PC EQU 0FF22H ;键入口 ORG 1000HSTART: JMP START0BUF DB ?,?,?,?,?,?data1: db 0c0h,0f9h,0a4h,0b0h,99h,92h,82hdb 0f8h,80h,90h,88h,83h,0c6h,0a1h db 86h,8eh,0ffh,0ch,89h,0deh,0c7hdb 8ch,0f3h,0bfh,8FHSTART0: CALL BUF1ADCON: MOV AL
10、,00 MOV DX,ADPORT OUT DX,AL MOV CX,0500HDELAY: LOOP DELAY MOV DX,ADPORT IN AL,DX CALL CONVERS CALL DISP JMP ADCONCONVERS: MOV AH,AL AND AL,0FH MOV BX,OFFSET BUF MOV BX+5,AL MOV AL,AH AND AL,0F0H MOV CL,04H SHR AL,CL MOV BX+4,AL RETDISP: MOV AL,0FFH ;00H MOV DX,PA OUT DX,AL MOV CL,0DFH ;20H 初始数位 MOV
11、BX,OFFSET BUFDIS1: MOV AL,BX MOV AH,00H PUSH BX MOV BX,OFFSET DATA1 ADD BX,AX MOV AL,BXPOP BX MOV DX,PB OUT DX,AL MOV AL,CL MOV DX,PA OUT DX,AL PUSH CXDIS2: MOV CX,00A0H LOOP $ POP CX CMP CL,0FEH ;01H JZ LX1 INC BX ROR CL,1 ;SHR CL,1 JMP DIS1LX1: MOV AL,0FFH MOV DX,PB OUT DX,AL RETBUF1: MOV BUF,00H
12、MOV BUF+1,08H MOV BUF+2,00H MOV BUF+3,09H MOV BUF+4,00H MOV BUF+5,00H RETCODE ENDSEND START3、数据采集实验要求:用8253定时器1通道定时,每隔半秒使从ADC0809的0通道IN0采集一个数据,若模拟电压在0-2V范围内(0-102),则使LED显示器L7-L4亮;若模拟电压大于2V,小于3V,则使L5-L2亮;若模拟电压大于等于3V,则使LED显示器L3-L0亮。(主程序重复所采集的数据)(1) 实验接线图(2) 实验程序框图主程序流程图中断程序流程(3)实验程序清单CODE SEGMENT ;H08
13、09.ASMASSUME CS:CODEINTPORT1 EQU 0FF80HINTPORT2 EQU 0FF81HINTQ3 EQU INTREEUP3TCONTR0 EQU 0043HTCON1 EQU 0041HIOCONPT EQU 0FF2BHIOBPT EQU 0FF29HIOAPT EQU 0FF28HPA EQU 0FF20H ;字位口PB EQU 0FF21H ;字形口PC EQU 0FF22H ;键入口ADPORT EQU 0FE00HORG 12D0HSTART: JMP START0BUF DB ?,?,?,?,?,?intcnt db ?RES DB ?data1 d
14、b 0c0h,0f9h,0a4h,0b0h,99h,92h,82hdb f8h,80h,90h,88h,83h,0c6h db 0a1h,86h,8eh,0ffh,0ch,89h,0dehdb 0c7h,8ch,0f3h,0bfh,8FHSTART0: CLD CALL BUF1 CALL WRINTVER ;WRITE INTRRUPT MOV AL,13H MOV DX,INTPORT1 OUT DX,AL MOV AL,08H MOV DX,INTPORT2 OUT DX,AL MOV AL,09H OUT DX,AL MOV AL,0F7H OUT DX,AL MOV intcnt,2
15、5 ;软件计数50(1秒=20ms*50) MOV DX,TCONTR0 MOV AL,74H OUT DX,AL MOV DX,TCON1 ;计数器1定时20ms MOV AX,40000 OUT DX,AL MOV AL,AH OUT DX,ALMOV DX,0FF2BH MOV AL,80H OUT DX,AL STIWATING: CALL DISP ;DISP 0809XX JMP WATINGWRINTVER: MOV AX,0H MOV ES,AX MOV DI,002CH LEA AX,INTQ3 STOSW MOV AX,0000h STOSW RETINTREEUP3: D
16、EC INTCNT JNZ INTRE2 MOV INTCNT, 25ADCON: MOV AX,00 MOV DX,ADPORT OUT DX,AL MOV CX,0500HDELAY: LOOP DELAY MOV DX,ADPORT IN AL,DX MOV RES,AL CALL CONVERSMOV AL,RES CMP AL, 66H JA NEXT1 MOV AL, 0F0H MOV DX, IOAPT OUT DX,AL JMP INTRE2NEXT1: CMP AL, 99H JA NEXT2 MOV AL, 0C3H MOV DX, IOAPT OUT DX,AL JMP
17、INTRE2NEXT2: MOV AL, 0FH MOV DX, IOAPT OUT DX,AL INTRE2: MOV AL,20H MOV DX,INTPORT1 OUT DX,AL IRETCONVERS: MOV AH,AL AND AL,0FH MOV BX,OFFSET BUF MOV BX+5,AL MOV AL,AH AND AL,0F0H MOV CL,04H SHR AL,CL MOV BX+4,AL RETDISP: MOV AL,0FFH ;00H MOV DX,PA OUT DX,AL MOV CL,0DFH ;20H MOV BX,OFFSET BUFDIS1: M
18、OV DX,PC OUT DX,AL MOV AL,BX MOV AH,00H PUSH BX MOV BX,OFFSET DATA1 ADD BX,AX MOV AL,BX POP BX MOV DX,PB OUT DX,AL MOV AL,CL MOV DX,PA OUT DX,AL PUSH CXDIS2: MOV CX,00A0H LOOP $ POP CX CMP CL,0FEH ;01H JZ LX1 INC BX ROR CL,1 JMP DIS1LX1: MOV AL,0FFH MOV DX,PB OUT DX,AL RETBUF1: MOV BUF,00H MOV BUF+1
19、,08H MOV BUF+2,00H MOV BUF+3,09H MOV BUF+4,00H MOV BUF+5,00H RETCODE ENDS END START思考题:用IN4采集数据,当电压大于4.5V,使PA口的LED全亮实验报告: 要求:用8253定时器1通道定时,每隔半秒从ADC0809的4通道IN4采集一个数据存于RES单元。当开关K1(PC0)闭合时进行如下检测:若模拟电压在0-2V范围内(0-102),则使LED显示器L7-L4亮;若模拟电压大于2V,小于3V,则使L5-L2亮;若模拟电压大于等于3V,则使LED显示器L3-L0亮,当电压大于4.5V,使PA口的LED全亮。
20、画出系统连接图,编写控制程序(对程序加以注释)(主程序重复显示0809XX)CODE SEGMENT ;H0809.ASMASSUME CS:CODEINTPORT1 EQU 0FF80HINTPORT2 EQU 0FF81HINTQ3 EQU INTREEUP3TCONTR0 EQU 0043HTCON1 EQU 0041HIOCONPT EQU 0FF2BHIOCPT EQU 0FF2AHIOBPT EQU 0FF29HIOAPT EQU 0FF28HPA EQU 0FF20H ;字位口PB EQU 0FF21H ;字形口PC EQU 0FF22H ;键入口ADPORT EQU 0FE00
21、HORG 12D0HSTART: JMP START0BUF DB ?,?,?,?,?,?intcnt db ?RES DB ?data1 db 0c0h,0f9h,0a4h,0b0h,99h,92h,82hdb 0f8h,80h,90h,88h,83h,0c6h, 0E6h db 0a1h,86h,8eh,0ffh,0ch,89h,0dehdb 0c7h,8ch,0f3h,0bfh,8FHSTART0: CLD CALL BUF1 CALL WRINTVER ;WRITE INTRRUPT MOV AL,13H MOV DX,INTPORT1 OUT DX,AL MOV AL,08H MOV
22、 DX,INTPORT2 OUT DX,AL MOV AL,09H OUT DX,AL MOV AL,0F7H OUT DX,AL MOV intcnt,25 ;软件计数25 (1秒=20ms*50) MOV DX,TCONTR0 MOV AL,74H OUT DX,AL MOV DX,TCON1 ;计数器1定时20ms MOV AX,40000 OUT DX,AL MOV AL,AH OUT DX,ALMOV DX,0FF2BH ;MOV AL,80H MOV AL,81H OUT DX,AL STIWATING: CALL DISP ;DISP 0809XX JMP WATINGWRINT
23、VER: MOV AX,0H MOV ES,AX MOV DI,002CH LEA AX,INTQ3 STOSW MOV AX,0000h STOSW RETINTREEUP3: DEC INTCNT JNZ INTRE2 MOV INTCNT, 25ADCON: MOV AX,04 MOV DX,ADPORT OUT DX,AL MOV CX,0500HDELAY: LOOP DELAY MOV DX,ADPORT IN AL,DX MOV RES,AL CALL CONVERS ;加开关,检查开关状态 MOV DX,IOCPT IN AL,DX TEST AL,01 ;K1状态闭合? JZ
24、 INTRE2MOV AL,RES CMP AL, 66H JA NEXT1 ;MOV AL, 0F0H MOV AL,0FH ;右边灯亮 MOV DX, IOAPT OUT DX,AL JMP INTRE2NEXT1: CMP AL, 99H JA NEXT2 MOV AL, 0C3H MOV DX, IOAPT OUT DX,AL JMP INTRE2NEXT2: CMP AL,0E6HJA NEXT3;MOV AL, 0FH MOV AL,0F0H;左边灯亮 MOV DX, IOAPT OUT DX,ALJMP INTRE2NEXT3: MOV AL,00H MOV DX,IOAPT O
25、UT DX,AL INTRE2: MOV AL,20H MOV DX,INTPORT1 OUT DX,AL IRETCONVERS: MOV AH,AL AND AL,0FH MOV BX,OFFSET BUF MOV BX+5,AL MOV AL,AH AND AL,0F0H MOV CL,04H SHR AL,CL MOV BX+4,AL RETDISP: MOV AL,0FFH ;00H MOV DX,PA OUT DX,AL MOV CL,0DFH ;20H MOV BX,OFFSET BUFDIS1: MOV DX,PC OUT DX,AL MOV AL,BX MOV AH,00H
26、PUSH BX MOV BX,OFFSET DATA1 ADD BX,AX MOV AL,BX POP BX MOV DX,PB OUT DX,AL MOV AL,CL MOV DX,PA OUT DX,AL PUSH CXDIS2: MOV CX,00A0H LOOP $ POP CX CMP CL,0FEH ;01H JZ LX1 INC BX ROR CL,1 JMP DIS1LX1: MOV AL,0FFH MOV DX,PB OUT DX,AL RETBUF1: MOV BUF,00H MOV BUF+1,08H MOV BUF+2,00H MOV BUF+3,09H MOV BUF+4,00H MOV BUF+5,00H RETCODE ENDS END START
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1