版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
三.程序清单及程序流程框图 ORG0000H LJMPMAIN MAIN:MOVR0,#30H MOVR2,#10H CLRA A1: MOV@R0,A INCR0 INC A DJNZR2,A1 MOVR0,#30H MOVR1,#40H MOVR2,#10H A2:MOVA,@R0 MOV@R1,A INCR0 INCR1 DJNZR2,A2 MOVR1,#40H MOVDPTR,#4800H MOVR2,#10H A3:MOVA,@R1 MOVX@DPTR,A INCR1 INCDPTR DJNZR2,A3 MOVSP,#60H MOVR2,#10H MOVDPTR,#4800H PUSHDPL PUSHDPH MOVDPTR,#5800H MOVR3,DPL MOVR4,DPH A4:POPDPH POPDPL MOVXA,@DPTR INC DPTR PUSHDPL PUSHDPH MOVDPL,R3 MOVDPH,R4 MOVX@DPTR,A INCDPTR MOVR3,DPL MOVR4,DPH DJNZR2,A4 MOVR0,#50H MOVDPTR,#5800H MOVR2,#10H A5:MOVXA,@DPTR MOV@R0,A INCR0 INCDPTR DJNZR2,A5POPDPH POPDPL HERE:LJMPHERE END 三.试验电路四.程序清单及流程图程序一ORG 0000H LJMPMAIN ORG000BH LJMPIPTO MAIN:MOV SP, #30H MOV TMOD, #01H CLR 00H SETBEA SETB ET0 MOVTH0, #3CH MOV TL0, #0B0H MOV R1, #14H SETB TR0 MOVA, #0feH MOVP1, ANT: JNB 00 RL A MOV P1, ACLR 00H LJMP NTIPTO:MOV TH0, #3CHMOV TL0, #0B0H DJNZ R1, TIO MOV R1, #14H SETB 00HTIO:RETI END程序二只需将程序一中“RL A”改为“RR A”即可实现其功效。程序三ORG 0000H LJMP MAIN ORG 000BH LJMP IPTO MAIN:MOV SP, #30H MOV TMOD, #01H CLR 00H SETB EA SETBET0 MOV TH0, #3CH MOV TL0, #0B0H MOV R2, #0AH MOV R1, #02H SETBTR0 MOVA, #0feH MOVP1, A NT:SETBP3.0NT0:JNB 01H, NT0 CLR P3.0 CLR 01HNT1:JNB00H, NT1 CLR 01H RL A MOV P1, A CLR 00H LJMP NTIPTO:MOV TH0, #3CH MOV TL0, #0B0H DJNZ R2, TIO MOV R2, #0AH SETB01H DJNZ R1, TIO MOV R1, #02H SETB 00HTIO:RETI END 程序四(思索题程序)ORG 0000H LJMP MAIN ORG 000BH LJMP IPTO MAIN:MOV SP, #30H MOV P1, #0ffH MOV TMOD, #01H CLR 00H SETBEA SETBET0 MOVTH0, #3CH MOV TL0, #0B0H MOV R1, #14H SETB TR0 MOVA, #00H NT:JNB 00 INC A MOV R3, A CPL A MOV P1, A CLR 00H MOV A, R3 LJMP NTIPTO:MOV TH0, #3CH MOV TL0, #0B0H DJNZ R1, TIO MOV R1, #14H SETB 00HTIO:RETI END三.电路原理图四.程序清单及流程图程序一ORG 0000H LJMP MAINMAIN: MOV TMOD, #02H MOV TH0, #9CH MOV TL0, #9CH SETB TR0 SETB P1.0HERE:JNBTF0, HERE CPL P1.0 CLR TF0 LJMP HERE END程序二 ORG 0000H LJMP MAIN ORG 000BH LJMP IPTOMAIN: MOV SP, #60H MOV TMOD, #02H MOV IE, #82H MOV TH0, #88H MOV TL0, #88H SETB TR0 SETB P1.1HERE: LJMP HEREIPTO:CPL P1.1RETI END程序三(思索题)ORG 0000H LJMP MAINMAIN: MOV TMOD, #11H MOV TH0, #0FEH MOV TL0, #0D4H MOV TH1, #0FFH MOV TL1, #38H SETB TR1 SETB P1.0HERE:JNB TF1, HERE CPL P1.0 SETB TR0 CLR TF1 CLR TR1 MOV TH1, #0FFH MOV TL1, #38HHERE1:JNB TF0, HERE1 CPL P1.0 SETB TR1 CLR TF0 CLR TR0 MOV TH0, #0FEH MOV TL0, #0D4H LJMP HERE END五.试验结果周期为200us方波周期为240us方波周期为500us占空比为2:5方波三、电路原理图四、程序清单及流程图程序1:ORG 0000H LJMP MAINMAIN:MOV TMOD, #06H MOV TH0, #9CH MOV TL0, #9CH SETB TR0HERE:JNBTF0, HERE CPL P1.0 CLR TF0 LJMP HERE END程序2:ORG 0000H LJMP MAIN ORG 000BH LJMP ITPOMAIN:MOV SP, #60H MOV TMOD, #06H MOV TH0, #38H MOV TL0, #38H MOV IE, #82H SETB TR0HERE:LJMP HEREITPO:CPL P1.0 RETI END程序3(思索题): ORG 0000H LJMP MAIN ORG 001BH LJMP ITPOMAIN: MOV SP, #60H MOV TMOD, #62H MOV TH0, #9CH MOV TL0, #9CH MOV TH1, #0CEH MOV TL1, #0CEH MOV IE, #88H SETB TR0 SETB TR1 SETB P1.0HERE:JNBTF0, HERE CPL P1.0 CLR TF0 LJMP HEREITPO:CPL P1.1RETI END五、试验结果程序1与程序2从T0接入1000Hz方波,思索题从P1.0口线产生方波从T1接入计100次脉冲计200次脉冲思索题波形三、电路原理图四、程序清单及流程图程序一:ORG 0000H LJMP MAIN ORG 0003H LJMP EXTER0 ORG 000BH LJMP IPTO ORG 00013H LJMP EXTER1MAIN: MOV SP, #60H MOV TMOD, #11H MOV IE, #87H MOV IP, #02H MOV TH0, #9EH MOV TL0, #58H MOV TH1, #0D8H MOV TL1, #0F0HHERE:LJMP HEREDELAY:SETB TR1HEREY:JNB TF1, HEREY CLR TR1 CLR TF1 MOV TH1, #0D8H MOV TL1, #0F0H RETEXTER0:LCALL DELAY JB P1.0, LOOP0HERE0:JNB P1.0, HERE0 SETB TR0LOOP0:RETIEXTER1:LCALL DELAY JB P1.1, LOOP1HERE1:JNB P1.1, HERE1 CLR TR0LOOP1:RETIIPTO:CPL P1.2 MOV TH0, #9EH MOV TL0, #58HRETI END程序二(思索题) ORG 0000H LJMP MAIN ORG 0003H LJMP EXTER0 ORG 000BH LJMP IPTOMAIN: MOV SP, #60H MOV TMOD, #11H MOV IE, #83H MOV IP, #02H MOV TH0, #0B1H MOV TL0, #0E0H MOV TH1, #0D8H MOV TL1, #0F0H MOV R1, #02HHERE:LJMP HEREDELAY:SETB TR1HEREY:JNB TF1, HEREY CLR TR1 CLR TF1 MOV TH1, #0D8H MOV TL1, #0F0H RETEXTER0:LCALL DELAY JB P1.0, LOOP0HERE0:JNB P1.0, HERE0 CPL TR0OOP0:RETIIPTO:DJNZ R1, LOOP CPL P1.2 CPL 00H JNB 00H, LOOP2 MOV R1, #03H LJMP LOOPLOOP2: MOV R1, #02HLOOP:MOV TH0, #0B1H MOV TL0, #0E0HRETI END五、试验结果1、基本要求部分:将程序产生十六进制代码加载到proteus中,运行仿真开始无波形输出,按下K0键输出周期为50mS连续方波,如图5.1所表示,当按下K1键波形消失,重复操作结果一样。2、思索题部分:将程序产生十六进制代码加载到proteus中,运行仿真开始无波形输出,按下K0键输出周期为100mS占空比为2:5连续矩形波,如图5.2所表示,当再次按下K0键波形消失,重复操作结果一样。图5.1图5.2三、电路原理图四、程序清单及流程图程序一:ORG 0000H LJMP MAIN ORG 000BH LJMP INTOMAIN:LCALL DELY MOV SP, #60H MOV TMOD, #02H MOV IE, #82H MOV TH0, #9CH MOV TL0, #9CH MOV DPTR, #7FFFH MOV A, #81H MOVX @DPTR, AMOV R3, #0FFH SETB TR0LOOP0:MOV DPTR, #7FFEH MOVX A, @DPTR SWAP A MOVX @DPTR, A LJMP LOOP0INTO:PUSH DPLPUSH DPH PUSH ACC MOV DPTR, #7FFCH MOV A, R3 MOVX @DPTR, A CPL A MOV R3, A POP ACC POP DPH POP DPL RETIDELY:MOV R4, #0FFHLOOP:NOP NOP DJNZ R4, LOOP RET END程序二(思索题):ORG 0000H LJMP MAINMAIN:LCALL DELY MOV DPTR, #7FFFH MOV A, #80H MOVX @DPTR, A MOV R3, #08H MOV DPTR, #7FFEH MOV A, #0FFH MOVX @DPTR, ALOOP0:MOV DPTR, #7FFFH MOV A, #00HLOOP1:MOVX @DPTR, A LCALL DELY CPL ACC.0 MOVX @DPTR, A LCALL DELY CPL ACC.0 INC ACC INC ACC DJNZ R3, LOOP1MOV R3, #08H LJMP LOOP0DELY:MOV R4,#0FFHLOOP3:MOV R5,#0FFHLOOP:NOP NOP NOP NOP NOP DJNZ R5,LOOP DJNZ R4,LOOP3 RET END五、试验结果1、基本要求部分:将程序产生十六进制代码加载到proteus中,运行仿真能够在示波器中看到如图6.1所表示波形,当按下k0键时能够看到D4点亮,同理按下K1键,D5点亮,按下K2键,D6点亮,按下K3键,D7点亮。2、思索题部分:将程序产生十六进制代码加载到proteus中,运行仿真开始二极管全部熄灭,然后从上倒下依次循环点亮。图6.1三、试验电路四、程序清单及流程图程序一:#include<reg51.h>#defineucharunsignedchar#defineuintunsignedintsbitsmg0=P2^0;sbitsmg1=P2^1;sbitsmg2=P2^2;sbitsmg3=P2^3;unsignedcharcodesmg_we[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};ucharzs,xs,ad_data;voidad(void);voiddelay(uintt);voiddelay_1ms(void);voiddisplay(void);/******************************主函数************************************/voidmain(){while(1){ucharxdata*dr_ad;uintad_data;dr_ad=0xfff7;*dr_ad=0;delay(15);//延时100usad_data=*dr_ad;ad_data=ad_data*1.963125;zs=ad_data/100;xs=ad_data%100;display();}} /*****************************延时1ms函数********************************/voiddelay_1ms(void){ ucharj,t; for(t=100;t>0;t--) { for(j=19;j>0;j--); }}/******************************延时子函数*********************************/voiddelay(uintt){while(t--);}/******************************显示子函数**********************************/voiddisplay(void){P1=smg_we[xs%10];smg0=1;smg1=0;smg2=0;smg3=0;delay_1ms();P1=smg_we[xs/10];smg0=0;smg1=1;smg2=0;smg3=0;delay_1ms();P1=smg_we[zs%10]&0x7f;smg0=0;smg1=0; smg2=1; smg3=0; delay_1ms(); smg0=0; smg1=0; smg2=0; smg3=0; delay_1ms(); }程序二:查询方式只需将主函数中延时改为一个while循环语句,条件为AD中EOC引脚接单片口线为1即可。程序三:主函数中将总中止和外部中止0开启,将取数据部分放到中止服务程序中,中止服务程序以下。/************************中止服务函数************************************/voidad(void)interrupt0using0{ucharxdata*dr_ad;dr_ad=0xfff7;ad_data=ad_data*1.963125;*dr_ad=0;}五、试验结果将程序产生十六进制代码加载到proteus中,运行仿真,调整滑动变阻器改变AD输入电压,能够到如图7.1—7.4所表示试验结果。图7.1图7.2图7.3图7.4三、试验原理电路图四、程序清单及流程图#include<reg51.h>#defineucharunsignedchar#defineuintunsignedintucharjz;unsignedcharcodezxb_daima[]={0x7F,0x85,0x8B,0x92,0x98,0x9E,0xA4,0xAA,0xB0,0xB6,0xBB,0xC1,0xC6,0xCB,0xD0,0xD5,0xD9,0xDD,0xE2,0xE5,0xE9,0xEC,0xEF,0xF2,0xF5,0xF7,0xF9,0xFB,0xFC,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFC,0xFB,0xF9,0xF7,0xF5,0xF2,0xEF,0xEC,0xE9,0xE5,0xE2,0xDD,0xD9,0xD5,0xD0,0xCB,0xC6,0xC1,0xBB,0xB6,0xB0,0xAA,0xA4,0x9E,0x98,0x92,0x8B,0x85,0x7F,0x79,0x73,0x6C,0x66,0x60,0x5A,0x54,0x4E,0x48,0x43,0x3D,0x38,0x33,0x2E,0x29,0x25,0x21,0x1C,0x19,0x15,0x12,0x0F,0x0C,0x09,0x07,0x05,0x03,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x05,0x07,0x09,0x0C,0x0F,0x12,0x15,0x19,0x1C,0x21,0x25,0x29,0x2E,0x33,0x38,0x3D,0x43,0x48,0x4E,0x54,0x5A,0x60,0x66,0x6C,0x73,0x79};//正弦波数据代码/****************************延时10ms函数**********************************/voiddelay_10ms(void){ ucharj,t; for(t=100;t>0;t--) {for(j=190;j>0;j--); }}/********************************延时子函数***********************************/voiddelay(uintt){while(t--);}/*******************************取键值子函数*********************************/ucharkey_data(void){ uchari; i=P1; i=~i; i=i&0x1f; return(i);}/**********************判键子函数*****************************************/ucharkey(void){uchari,d;i=key_data();if(i!=0){delay_10ms();i=key_data();if(i!=0){i=key_data();d=i;while(i!=0){delay_10ms();i=key_data();}delay_10ms();i=key_data();while(i!=0){delay_10ms();i=key_data();}i=d;}}return(i);}/************************方波产生函数*****************************************/voidfangbo(void){ucharxdata*dr_da;uchari,j=0;for(i=63;i>0&&jz!=1;i--){dr_da=0xfffe;*dr_da=j;j=0;jz=key();}for(i=63;i>0&&jz!=1;i--){dr_da=0xfffe;*dr_da=j;j=255;jz=key();}}/********************锯齿波产生函数*******************************************/voidjuchibo(void){ucharxdata*dr_da;uchari,j=0;for(i=63;i>0&&jz!=2;i--){dr_da=0xfffe;*dr_da=j;j=j+4;jz=key();}}/********************三角波产生函数*******************************************/voidsanjiaobo(void){ucharxdata*dr_da;uchari,j=0;for(i=63;i>0&&jz!=4;i--){dr_da=0xfffe;*dr_da=j;j=j+4;jz=key();}for(i=63;i>0&&jz!=4;i--){dr_da=0xfffe;*dr_da=j;j=j-4;jz=key();}}/**************************正弦波产生函数*************************************/voidzhengxianbo(void){ucharxdata*dr_da;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论