單片機(jī)實(shí)驗(yàn)程序及流程圖_第1頁
單片機(jī)實(shí)驗(yàn)程序及流程圖_第2頁
單片機(jī)實(shí)驗(yàn)程序及流程圖_第3頁
單片機(jī)實(shí)驗(yàn)程序及流程圖_第4頁
單片機(jī)實(shí)驗(yàn)程序及流程圖_第5頁
已閱讀5頁,還剩44頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

三.程序清單及程序流程框圖 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 三.試驗(yàn)電路四.程序清單及流程圖程序一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”即可實(shí)現(xiàn)其功效。程序三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五.試驗(yàn)結(jié)果周期為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五、試驗(yàn)結(jié)果程序1與程序2從T0接入1000Hz方波,思索題從P1.0口線產(chǎn)生方波從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五、試驗(yàn)結(jié)果1、基本要求部分:將程序產(chǎn)生十六進(jìn)制代碼加載到proteus中,運(yùn)行仿真開始無波形輸出,按下K0鍵輸出周期為50mS連續(xù)方波,如圖5.1所表示,當(dāng)按下K1鍵波形消失,重復(fù)操作結(jié)果一樣。2、思索題部分:將程序產(chǎn)生十六進(jìn)制代碼加載到proteus中,運(yùn)行仿真開始無波形輸出,按下K0鍵輸出周期為100mS占空比為2:5連續(xù)矩形波,如圖5.2所表示,當(dāng)再次按下K0鍵波形消失,重復(fù)操作結(jié)果一樣。圖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五、試驗(yàn)結(jié)果1、基本要求部分:將程序產(chǎn)生十六進(jìn)制代碼加載到proteus中,運(yùn)行仿真能夠在示波器中看到如圖6.1所表示波形,當(dāng)按下k0鍵時能夠看到D4點(diǎn)亮,同理按下K1鍵,D5點(diǎn)亮,按下K2鍵,D6點(diǎn)亮,按下K3鍵,D7點(diǎn)亮。2、思索題部分:將程序產(chǎn)生十六進(jìn)制代碼加載到proteus中,運(yùn)行仿真開始二極管全部熄滅,然后從上倒下依次循環(huán)點(diǎn)亮。圖6.1三、試驗(yàn)電路四、程序清單及流程圖程序一:#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);/******************************主函數(shù)************************************/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函數(shù)********************************/voiddelay_1ms(void){ ucharj,t; for(t=100;t>0;t--) { for(j=19;j>0;j--); }}/******************************延時子函數(shù)*********************************/voiddelay(uintt){while(t--);}/******************************顯示子函數(shù)**********************************/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(); }程序二:查詢方式只需將主函數(shù)中延時改為一個while循環(huán)語句,條件為AD中EOC引腳接單片口線為1即可。程序三:主函數(shù)中將總中止和外部中止0開啟,將取數(shù)據(jù)部分放到中止服務(wù)程序中,中止服務(wù)程序以下。/************************中止服務(wù)函數(shù)************************************/voidad(void)interrupt0using0{ucharxdata*dr_ad;dr_ad=0xfff7;ad_data=ad_data*1.963125;*dr_ad=0;}五、試驗(yàn)結(jié)果將程序產(chǎn)生十六進(jìn)制代碼加載到proteus中,運(yùn)行仿真,調(diào)整滑動變阻器改變AD輸入電壓,能夠到如圖7.1—7.4所表示試驗(yàn)結(jié)果。圖7.1圖7.2圖7.3圖7.4三、試驗(yàn)原理電路圖四、程序清單及流程圖#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};//正弦波數(shù)據(jù)代碼/****************************延時10ms函數(shù)**********************************/voiddelay_10ms(void){ ucharj,t; for(t=100;t>0;t--) {for(j=190;j>0;j--); }}/********************************延時子函數(shù)***********************************/voiddelay(uintt){while(t--);}/*******************************取鍵值子函數(shù)*********************************/ucharkey_data(void){ uchari; i=P1; i=~i; i=i&0x1f; return(i);}/**********************判鍵子函數(shù)*****************************************/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);}/************************方波產(chǎn)生函數(shù)*****************************************/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();}}/********************鋸齒波產(chǎn)生函數(shù)*******************************************/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();}}/********************三角波產(chǎn)生函數(shù)*******************************************/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();}}/**************************正弦波產(chǎn)生函數(shù)*************************************/voidzhengxianbo(void){ucharxdata*dr_da;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論