《单片机AD转换0809.doc》由会员分享,可在线阅读,更多相关《单片机AD转换0809.doc(45页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date单片机AD转换0809一、实验目的和要求一、实验目的和要求 1、掌握单片机与ADC0809的接口设计方法2、掌握Proteus软件与Keil软件的使用方法二、设计要求1、用Proteus软件画出电路原理图,在单片机的外部扩展片外三 总线,并通过片外三总线与0809接口。2、在0809的某一模拟量输入通道上接外部模拟量。3、在单片机的外部扩展数码管显示器。4、分别采用延
2、时和查询的方法编写A/D转换程序。5、启动A/D转换,将输入模拟量的转换结果在显示器上显示。三、 电路原理图 四、 实验程序流程框图和程序清单 ORG 0000HSTART: LJMP MAIN ORG 0100HMAIN: MOV SP , #50H CLR EALOOP: MOV DPTR, #0700H MOVX DPTR, ALOOP1: JB P3.2 , LOOP1 MOVX A, DPTR MOV B, #51 DIV AB MOV R0, A MOV A, B MOV B, #5 DIV AB MOV R1,A MOV A, B MOV R2,A MOV DPTR, #TAB
3、MOV A, R0 MOVC A, A+DPTR MOV P2,#40H ANL A, #7FH MOV P1, A LCALLDELAY1MS MOVA, R1 MOVCA, A+DPTR MOVP2, #20H MOVP1, A LCALLDELAY1MS MOVA, R2 MOVCA, A+DPTR MOVP2, #10H MOVP1, A LCALLDELAY1MS LJMP LOOPDELAY1MS: ;误差 0us MOV R7, #01HDL1: MOV R6, #8EHDL0: MOV R5, #02H DJNZ R5, $ DJNZ R6, DL0 DJNZ R7, DL1
4、RETTAB:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H END ORG 0000HSTART: LJMP MAIN ORG 0100HMAIN: MOV SP , #50H CLR EALOOP: MOV DPTR, #0700H MOVX DPTR, A LCALL DELAY1MS MOVX A, DPTR MOV B,#51 DIV AB MOV R0,A MOV A,B MOV B,#5 DIV AB MOV R1,A MOV A,B MOV R2,A MOV DPTR,#TAB MOV A,R0 MOVC A,A+DPTR MOV
5、 P2,#40H ANL A, #7FH MOV P1,A LCALL DELAY1MS MOV A,R1 MOVC A,A+DPTR MOV P2,#20H MOV P1,A LCALL DELAY1MS MOV A,R2 MOVC A,A+DPTR MOV P2,#10H MOV P1,A LCALL DELAY1MS LJMP LOOPDELAY1MS: ;误差 0us MOV R7, #01HDL1: MOV R6, #8EHDL0: MOV R5, #02H DJNZ R5, $ DJNZ R6, DL0 DJNZ R7, DL1 RETTAB:DB 0C0H,0F9H,0A4H,0
6、B0H,99H,92H,82H,0F8H,80H,90HEND#include#include#define uchar unsigned char#define ADC0809 XBYTE 0x0700uchar code table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;uchar ge,yu1,yu2,data1,ge1;sbit P32=P32;void delay1ms(void) /误差 0us unsigned char a,b,c; for(c=1;c0;c-) for(b=142;b0;b-) for(a=2;a0
7、;a-);void main() SP=0X50; EA=0; while(1) ADC0809=0; while(P32);data1=ADC0809; ge=data1/51; yu1=data1%51/5; yu2=data1%51%5; ge1=tablege;ge1=ge1&0x7f;P2=0X40;P1=ge1;delay1ms();yu1=tableyu1;P2=0X20;P1=yu1;delay1ms();yu2=tableyu2;P2=0X10;P1=yu2;delay1ms(); #include#include#define uchar unsigned char#def
8、ine ADC0809 XBYTE 0x0700uchar code table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;uchar ge,yu1,yu2,data1,ge1;void delay200us(void) /误差 0us unsigned char a,b; for(b=1;b0;b-) for(a=97;a0;a-);void delay50us(void) /误差 0us unsigned char a,b; for(b=1;b0;b-) for(a=22;a0;a-);void main() SP=0X50; EA
9、=0; while(1) ADC0809=0; delay200us();data1=ADC0809; ge=data1/51; yu1=data1%51/5; yu2=data1%51%5; ge1=tablege;ge1=ge1&0x7f;P2=0X40;P1=ge1; delay50us();yu1=tableyu1;P2=0X20;P1=yu1;delay50us();yu2=tableyu2;P2=0X10;P1=yu2; delay50us(); 五、实验结果六、 实验总结通过本次实验基本掌握了单片机与ADC0809的接口设计方法,对于模数转换有了新的认识,其中对于得到的数据转换的
10、方法采用了近似原则设计的,所以实验结果有一定的误会,但误差不大,基本满足实验要求。另外对ADC0809的查询法,中断法,延时法有了基本认识。七、思考题1、采用中断的方法编写A/D转换程序,完成实验要求 ORG 0000HSTART: LJMP MAIN ORG 0003H LJMP INT00 ORG 0100HMAIN: MOV SP , #50H SETB IT0 SETB EA SETB EX0 MOV DPTR, #0700H MOVX DPTR, ALOOP: LJMP LOOP ORG 0200HINT00: MOVX A, DPTR MOVB,#51DIV ABMOVR0,AMO
11、VA,BMOVB,#5DIV ABMOVR1,AMOVA,BMOVR2,AMOVDPTR,#TABMOVA,R0MOVC A,A+DPTRMOVP2,#40HANL A, #7FHMOVP1,ALCALL DELAY1MSMOVA,R1MOVC A,A+DPTRMOVP2,#20HMOVP1,ALCALL DELAY1MSMOVA,R2MOVC A,A+DPTRMOVP2,#10HMOVP1,ALCALL DELAY1MSMOV DPTR, #0700HMOVX DPTR, A RETIDELAY1MS: ;误差 0us MOV R7, #01HDL1: MOV R6, #8EHDL0: MO
12、V R5, #02H DJNZ R5, $ DJNZ R6, DL0 DJNZ R7, DL1 RETTAB:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H END#include#include#define uchar unsigned char#define ADC0809 XBYTE 0x0700uchar code table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;uchar ge,yu1,yu2;void delay1ms(void) /误差 0us unsigned ch
13、ar a,b,c; for(c=1;c0;c-) for(b=142;b0;b-) for(a=2;a0;a-);void main() SP=0X50; IT0=1; EA=1; EX0=1; ADC0809=0; while(1);void INT00() interrupt 0using 0 uchar data1,ge1; data1=ADC0809; ge=data1/51; yu1=data1%51/5; yu2=data1%51%5; ge1=tablege;ge1=ge1&0x7f;P2=0X40;P1=ge1;delay1ms();yu1=tableyu1;P2=0X20;P1=yu1;delay1ms();yu2=tableyu2;P2=0X10;P1=yu2;delay1ms();ADC0809=0;其仿真结果可参考前两种方法的实验结果。(这里只改变了其A/D转换结束的检测方法)-