版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
實(shí)驗(yàn)用硬件平臺(tái)(含USB接口寫(xiě)入線)蜂鳴器驅(qū)動(dòng)器ADEEPROM232電平轉(zhuǎn)換晶振繼電器實(shí)驗(yàn)用硬件平臺(tái)(含USB接口寫(xiě)入線)蜂鳴器驅(qū)動(dòng)器ADEEPR1實(shí)驗(yàn)用硬件平臺(tái)(含并口寫(xiě)入線和電源)實(shí)驗(yàn)用硬件平臺(tái)(含并口寫(xiě)入線和電源)2單片機(jī)在線系統(tǒng)AY-MPU89S51EAT89S52單片機(jī)(跳線接上排針時(shí))6位數(shù)碼管動(dòng)態(tài)顯示(P0輸出字形、P2.0~5選擇位)8位LED顯示(P1)6位按鍵輸入(P2.7~2,P3.3)EEPROM:256字節(jié)(IIC接口,P3.2P3.4)8位AD(串行接口)P3.5~7蜂鳴器(P1.7)、繼電器RS232接口(P3.1、P3.2)溫度傳感器單片機(jī)在線系統(tǒng)AY-MPU89S51EAT89S52單片機(jī)(3顯示部分232接口驅(qū)動(dòng)+繼電器顯示部分232接口驅(qū)動(dòng)+繼電器4單片機(jī)在線系統(tǒng)AY-MPU89S51E課件5單片機(jī)在線系統(tǒng)AY-MPU89S51E課件6單片機(jī)在線系統(tǒng)AY-MPU89S51E課件7流水燈實(shí)驗(yàn)(實(shí)驗(yàn)1、2)1、掌握51單片機(jī)如何控制信號(hào)輸出。2、掌握KeilC集成開(kāi)發(fā)環(huán)境的使用。3、掌握51開(kāi)發(fā)平臺(tái)的使用。4、8個(gè)發(fā)光管(L1~L8)接在P1的0~7,為0時(shí)點(diǎn)亮。5、功能:首先點(diǎn)亮L1、然后L2…、最后是L8接著點(diǎn)亮L8、然后是L7L6…L1如此循環(huán),間隔0.1~1.0秒流水燈實(shí)驗(yàn)(實(shí)驗(yàn)1、2)1、掌握51單片機(jī)如何控制信號(hào)輸出8實(shí)驗(yàn)1:流水燈實(shí)驗(yàn)(匯編程序)ORG000HSTART: MOVA,#0FFH CLRC MOVR2,#08HLOOP: RLCA MOVP1,A;輸出至P1口 LCALLDELAY;調(diào)用延遲子程序(延遲100毫秒) DJNZR2,LOOP MOVR2,#07H;設(shè)右移7次LOOP1:RRCA MOVP1,A;輸出至P1口 LCALLDELAY DJNZR2,LOOP1 JMPSTART;跳回到START,再一次循環(huán)。DELAY:MOVR4,#200;延遲子程序(100毫秒)250*2*200=500*200us D1:MOVR5,#248 ;=50*2ms=100ms DJNZR5,$ ;2us DJNZR4,D1 ;2us RETEND實(shí)驗(yàn)1:流水燈實(shí)驗(yàn)(匯編程序)ORG000H9流水燈實(shí)驗(yàn)(C程序)#include"reg52.h"voidDelay(){ unsignedchari,j; for(i=0;i<255;i++) for(j=0;j<255;j++);}voidmain(){ unsignedchari,dat; while(1) { dat=0x01; for(i=0;i<8;i++) {P1=~dat; //L1isfirstlight,thenL2L3…L8 dat=dat<<1; Delay(); } dat=0x80; for(i=0;i<8;i++) {P1=~dat; //L8isfirstlight,thenL7L6…L1 dat=dat>>1; Delay(); } }}流水燈實(shí)驗(yàn)(C程序)#include"reg52.h" d10查表法點(diǎn)亮LED給定表格(33個(gè)8位數(shù))為1則點(diǎn)亮相應(yīng)的發(fā)光二極管間隔0.3~0.9秒查表法點(diǎn)亮LED給定表格(33個(gè)8位數(shù))11實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)BEEPBITP2.0BUFF_LED_LPEQU21H;亮燈循環(huán)寄存器org000hJMPSTARTORG100H;----------------------------------------start:movP1,#0ffh;初始化MCU端口MOVA,#00H;初始化寄存器MOVPSW,#00HMOVIE,#00HMOVSP,#30HMOVBUFF_LED_LP,#00HLOOP:MOVDPTR,#TAB_A_LAMP;設(shè)置亮燈花型列表地址(32種)MOVA,BUFF_LED_LP;查詢(xún)方式讀取花型MOVCA,@A+DPTRCPLAMOVP1,A ;LED小燈控制口LCALLDEL1SINCBUFF_LED_LPMOVA,BUFF_LED_LPCJNEA,#32,LOOPMOVBUFF_LED_LP,#00HJMPLOOP實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)BEEPBIT12實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)續(xù)TAB_A_LAMP:DB00111100B,10000001B,11000011B,11100111B,11111111B,11100111B,11000011B,10000001B,00000000BDB00011000B,00111100B,01111110B,11111111B,00000000B,10101010B,10101010B,11001100BDB10000000B,11000000B,11100000B,11110000B,11111000B,11111100B,11111110B,11111111BDB11111110B,11111100B,11111000B,11110000B,11100000B,11000000B,10000000B,00000000BdeL1S:MOVR5,#03H;延時(shí)子程序(約0.5秒)DEL1S0:movR6,#0ffhDEL1S1:movR7,#0ffhdjnzR7,$djnzR6,del1S1DJNZR5,DEL1S0;CPLBEEPretEND實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)續(xù)13實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(C程序)#include"reg52.h"codeunsignedchartab[]={0x3c,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00, 0x18,0x3c,0x7e,0xff,0x00,0xaa,0xaa,0xcc, 0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff, 0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};voiddelay(){ unsignedchari,j,k; for(i=0;i<2;i++) for(j=0;j<255;j++) for(k=0;k<255;k++);}voidmain(){ unsignedchari; while(1) { for(i=0;i<33;i++) { P1=~tab[i]; delay(); } }}實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(C程序)#include"reg52.14實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(匯編)
KEYBITP3.3SW1BITP2.7 ;P2.2 byhtqORG000HSTART:movsp,#40hmovp2,#0ffhmovp3,#0ffhMOVP1,#0ffh;clrkeyWAIT:;JBKEY,$;等候按鍵! byhtqJBSW1,$lcalldelaycplP1.0JNBSW1,$ ;waitkeyisreleasedlcalldelay ;byhtqJMPwaitDELAY:MOVR3,#200D1:MOVR4,#200DJNZR4,$DJNZR3,D1RETEND功能:按下SW1一次,發(fā)光管L1點(diǎn)亮或熄滅實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(匯編)KEYBITP3.15實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(C)//keySW1isdown,LED1isswap(onoroff)#include"reg52.h"#defineucharunsignedcharsbitKEY=P3^3;sbitSW1=P2^7;sbitLED1=P1^0;voidDelay(){ uchari,j; for(i=0;i<200;i++) for(j=0;j<200;j++);}voidmain(){ KEY=0; while(1) { while(SW1); Delay(); LED1=!LED1; while(!SW1); Delay(); }}實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(C)//keySW1isdown16;checkall6key ,lightcorrespondLEDs,editbyhtq2009.9.4keydat equ22hKEYBITP3.3 ORG000HSTART:movsp,#40hmovp2,#0ffhmovp3,#0ffhMOVP1,#0ffh;clrkeyWAIT:;JBKEY,$;等候按鍵! byhtq mova,P2 cpl a ;ifsomekeyisdown,thenthebitis0 anl a,#0fch mov keydat,a ; movP0,a jz nokey ;thedownkeyis1;somekeyisdown jb keydat.7,sw1 ;sw1isdown jb keydat.6,sw2 ;sw2isdown jb keydat.5,sw3 ;sw3isdown jb keydat.4,sw4 ;sw4isdown jb keydat.3,sw5 ;sw5isdown jb keydat.2,sw6 ;sw6isdown sjmp nokey實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.asm);checkall6key ,lightcorre17sw1: cpl p1.0 sjmp nokey1sw2: cpl p1.1 sjmp nokey1sw3: cpl p1.2 sjmp nokey1sw4: cpl p1.3 sjmp nokey1sw5: cpl p1.4 sjmp nokey1sw6: cpl p1.5nokey1:calldelay ;byhtqnokey:JMPwaitDELAY: mov R2,#5d2: MOVR3,#200D1:MOVR4,#200DJNZR4,$DJNZR3,D1 djnz r2,d2RETENDsw1:18實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.c)//checkall6key ,lightcorrespondLEDs,editbyhtq2009.9.18#include"reg52.h"#defineucharunsignedcharsbitKEY=P3^3;sbitSW1=P2^7;sbitLED1=P1^0;sbitLED2=P1^1;sbitLED3=P1^2;sbitLED4=P1^3;sbitLED5=P1^4;sbitLED6=P1^5;bdataucharKeyDat;voidDelay(){ uchari,j; for(i=0;i<200;i++) for(j=0;j<200;j++);}voidmain(){ KEY=0; while(1) { KeyDat=P2; P0=KeyDat; //ifsomekeyisdown,thenthebitis0 KeyDat=(~KeyDat)&0xfc; //ifsomekeyisdown,thenthebitis1 Delay(); if(KeyDat!=0)//somekeyisdown { if(KeyDat==0x80) //sw1// if(KeyDat^7==1) //sw1 LED1=!LED1; elseif(KeyDat==0x40) //sw2 LED2=!LED2; elseif(KeyDat==0x20) //sw3 LED3=!LED3; elseif(KeyDat==0x10) //sw4 LED4=!LED4; elseif(KeyDat==0x08) //sw5 LED5=!LED5; elseif(KeyDat==0x04) //sw6 LED6=!LED6; else P1=0xff; Delay(); } }}實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.c)//check19實(shí)驗(yàn)13八段數(shù)碼管動(dòng)態(tài)顯示(1)99倒計(jì)時(shí):99、98…0、99P0.0~7分別對(duì)應(yīng)數(shù)碼管的a~f、dpP2.7~2分別對(duì)應(yīng)6個(gè)數(shù)碼管:LED1~LED66個(gè)數(shù)碼管的a~f、dp相連共陽(yáng)P2.7為0,點(diǎn)亮P0口為0的字段(如要顯示0,則P0輸出為:11000000B=0xc0實(shí)驗(yàn)13八段數(shù)碼管動(dòng)態(tài)顯示(1)99倒計(jì)時(shí):99、98…02099倒計(jì)時(shí):主程序部分 MIAOEQU21HGEWEIEQU22HSHIWEIEQU23HSCANLEDBIT01HORG000H;ORG偽指令使用于程序定位JMPSTARTORG0BHJMPTIMER0;定時(shí)0中斷入口地址START:MOVSP,#40H;設(shè)定堆棧指針MOVTMOD,#01H;設(shè)定定時(shí)器1為工作方式1MOVTH0,#HIGH(65536-5000)MOVTL0,#LOW(65536-5000)SETBTR0MOVIE,#10000010BMOVR7,#200MOVMIAO,#99AJMP$99倒計(jì)時(shí):主程序部分 MIAOEQU2199倒計(jì)時(shí):中斷程序部分TIMER0:PUSHACC;定時(shí)器1中斷服務(wù)子程序PUSHPSWMOVTH0,#HIGH(65536-5000)MOVTL0,#LOW(65536-5000)DJNZR7,TIM0_LP;not1sMOVR7,#200 DJNZMIAO,TIM0_LPMOVMIAO,#99;TIM0_LP:MOVA,MIAOLCALLBIN_BCDMOVSHIWEI,AMOVGEWEI,BCPLSCANLEDJBSCANLED,SCAN_L1JMPSCAN_L2SCAN_L1:MOVP2,#01111111B;顯示十位MOVA,SHIWEIJMPEND_SCANSCAN_L2:MOVP2,#10111111B;顯示個(gè)位MOVA,GEWEIEND_SCAN:MOVDPTR,#TABLEMOVCA,@A+DPTRMOVP0,APOPPSWPOPACCRETIBIN_BCD:MOVB,#10DIVABRETTABLE:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90HEND99倒計(jì)時(shí):中斷程序部分TIMER0:PUSHACC2299倒計(jì)時(shí)(實(shí)驗(yàn)13)C程序#include"reg52.h"bitSecFlag;unsignedcharCount4ms;unsignedchardisp_buff[2];unsignedchardisp_cnt; //0..1unsignedcharsec;codeunsignedcharTab1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E};//;數(shù)碼管顯示字型表codeunsignedcharTab[2]={0x7f,0xbf};voidT0_service(void)interrupt1{ TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); Count4ms=Count4ms+1; if(Count4ms==250) { Count4ms=0; SecFlag=1; } P2=Tab[disp_cnt];//disp P0=Tab1[disp_buff[disp_cnt]]; disp_cnt=disp_cnt+1; if(disp_cnt==2) disp_cnt=0;}voidFillDispBuffer(void){ disp_buff[0]=sec/10; disp_buff[1]=sec%10; }voidChangeTime(void){ SecFlag=0; sec=sec-1; if(sec==255) sec=99; FillDispBuffer();}voidmain(){ //initial TMOD=0x01; TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); TR0=1; ET0=1; EA=1; sec=99; FillDispBuffer(); while(1) { if(SecFlag) ChangeTime(); }}99倒計(jì)時(shí)(實(shí)驗(yàn)13)C程序#include"reg52.23}voidChangeTime(void){ SecFlag=0; sec=sec-1; if(sec==255) sec=99; FillDispBuffer();}voidmain(){ //initial TMOD=0x01; TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); TR0=1; ET0=1; EA=1; // sec=99; FillDispBuffer(); while(1) { if(SecFlag) ChangeTime(); }}}24實(shí)驗(yàn)14電子時(shí)鐘設(shè)計(jì)6個(gè)數(shù)碼管顯示時(shí)、分、秒6個(gè)按鍵分別對(duì)時(shí)、分、秒進(jìn)行加1、減1設(shè)定6按鍵SW1、SW6分別對(duì)應(yīng)于P2.7~P2.2蜂鳴器:P2.0,為0時(shí)鳴響;問(wèn)題:C程序中,是如何控制蜂鳴器的按鍵時(shí)鳴響的?實(shí)驗(yàn)14電子時(shí)鐘設(shè)計(jì)6個(gè)數(shù)碼管顯示時(shí)、分、秒25C程序:變量定義部分#include"reg52.h"sbitKey=P3^3;bitKeyDownFlg;bitSecFlag;unsignedcharCount4ms;unsignedchardisp_buff[6];unsignedchardisp_cnt; //0..5unsignedcharhour,min,sec;unsignedcharBeep_cnt;unsignedcharP2_buff;unsignedcharKeyBuff;codeunsignedcharTab1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E};//;數(shù)碼管顯示字型表codeunsignedcharTab[6]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb};C程序:變量定義部分#include"reg52.h"26C程序:定時(shí)器0中斷服務(wù)子程序voidT0_service(void)interrupt1{ TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); Count4ms=Count4ms+1; if(Count4ms==250) { Count4ms=0; SecFlag=1; } P2_buff=Tab[disp_cnt]; if(KeyDownFlg) { P2_buff=P2_buff&0xfe; //Buzzerison Beep_cnt=Beep_cnt+1; if(Beep_cnt==100) //Buzzerisoff KeyDownFlg=0; } //disp P2=P2_buff; P0=Tab1[disp_buff[disp_cnt]]; disp_cnt=disp_cnt+1; if(disp_cnt==6) disp_cnt=0;}C程序:定時(shí)器0中斷服務(wù)子程序voidT0_service27C程序:主程序部分voidmain(){ //initial disp_cnt=0; Count4ms=0; hour=0; min=0; sec=0; // TMOD=0x01; TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); TR0=1; ET0=1; EA=1; while(1) { if(SecFlag) ChangeTime(); if(!Key) DealKey(); }}C程序:主程序部分voidmain()28按鍵檢測(cè)及處理voidDealKey(void){ KeyBuff=P2; if(KeyDownFlg) return; if((KeyBuff&0x80)!=0x80) // hour=hour+1; if((KeyBuff&0x40)!=0x40) // hour=hour-1; if((KeyBuff&0x20)!=0x20) // min=min+1; if((KeyBuff&0x10)!=0x10) // min=min-1; if((KeyBuff&0x08)!=0x08) // sec=sec+1; if((KeyBuff&0x04)!=0x04) // sec=sec-1; //checkdata hour=CheckData(hour,24); min=CheckData(min,60); sec=CheckData(sec,60); FillDispBuffer(); Beep_cnt=0; KeyDownFlg=1;}按鍵檢測(cè)及處理voidDealKey(void)29實(shí)驗(yàn)14電子時(shí)鐘設(shè)計(jì)(shizhong1.asm)BUFF_KEYEQU21H;鍵盤(pán)鍵BUFF_LED1EQU22H;數(shù)碼管顯示緩存BUFF_LED2EQU23HBUFF_LED3EQU24HBUFF_LED4EQU25HBUFF_LED5EQU26HBUFF_LED6EQU27HBUFF_LED_LPEQU28H;T0鍵盤(pán)顯示掃描緩存HOREQU30H;小時(shí)值緩存MINEQU31H;分鐘值緩存SECEQU32H;秒值緩存 MS equ33hF_BEEPBIT01HLED_PORTEQUP0DIG_PORTEQUP2KEY_PORTEQUP2SW1BITP2.7SW2BITP2.6SW3BITP2.5SW4BITP2.4SW5BITP2.3SW6BITP2.2BEEPBITP2.0KEYBITP3.3實(shí)驗(yàn)14電子時(shí)鐘設(shè)計(jì)(shizhong1.asm)BUFF30主程序:初始化部分ORG000HJMPMAINORG00BHJMPT0_INTORG100HMAIN:MOVSP,#40HMOVPSW,#00HMOVR0,#7FH;初始化RAM區(qū),CLR_RAM:MOVA,#00HMOV@R0,ADJNZR0,CLR_RAMMOVP1,0FFH;INITMOVP2,0FFHMOVP0,0FFHMOVP3,0FFHMOVTMOD,#21hMOVTH0,#240;T0=4MSMOVTL0,#96SETBTR0SETBET0SETBEA主程序:初始化部分ORG000H31主程序:按鍵檢測(cè)與處理(1)WAIT_KEY:JBKEY,$;等候按鍵!JNBSW1,SW1_OKJNBSW2,SW2_OKJNBSW3,SW3_OKJNBSW4,SW4_OKJNBSW5,SW5_OKAJNBSW6,SW6_OKAJMPWAIT_KEYSW5_OKA:JMPSW5_OKSW6_OKA:JMPSW6_OKSW1_OK:MOVA,HORCJNEA,#24,SW1_OVERMOVHOR,#00HSETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW1_OVER:INCHOR;時(shí)加1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW2_OK:MOVA,HORCJNEA,#00,SW2_OVERMOVHOR,#23SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW2_OVER:DECHOR;時(shí)減1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW3_OK:MOVA,MINCJNEA,#59,SW3_OVERMOVMIN,#00HSETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEY主程序:按鍵檢測(cè)與處理(1)WAIT_KEY:JBK32SW3_OVER:INCMIN;分加1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW4_OK:MOVA,MINCJNEA,#00,SW4_OVERMOVMIN,#59SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW4_OVER:DECMIN;分減1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW5_OK:MOVA,SECCJNEA,#59,SW5_OVERMOVSEC,#00HSETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW5_OVER:INCSEC;秒加1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW6_OK:MOVA,SECCJNEA,#00,SW6_OVERMOVHOR,#59SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYSW6_OVER:DECSEC;時(shí)減1SETBF_BEEPCLRBEEPLCALLDELSETBBEEPCLRF_BEEPJMPWAIT_KEYDEL:MOVR5,#02;為演示方便,人為插入的延時(shí)DEL01:MOVR6,#200DEL02:MOVR7,#200DJNZR7,$DJNZR6,DEL02DJNZR5,DEL01RETSW3_OVER:INCMIN;分加33中斷程序:修改時(shí)間部分T0_INT:PUSHACCPUSHPSWMOVTH0,#240;T0=4MSMOVTL0,#96INCBUFF_LED_LPMOVA,BUFF_LED_LPCJNEA,#250,CONT_SCAN;250*4MS=1SMOVBUFF_LED_LP,#00HINCSECMOVA,SECCJNEA,#60,CONT_SCANMOVSEC,#00HINCMINMOVA,MINCJNEA,#60,CONT_SCANMOVMIN,#00HINCHORMOVA,HORCJNEA,#24,CONT_SCANMOVHOR,#00H中斷程序:修改時(shí)間部分T0_INT:PUSHACC34中斷程序:填充顯示緩沖區(qū)CONT_SCAN:MOVA,SECLCALLBIN_BCDMOVBUFF_LED6,BMOVBUFF_LED5,AMOVA,MINLCALLBIN_BCDMOVBUFF_LED4,BMOVBUFF_LED3,AMOVA,HORLCALLBIN_BCDMOVBUFF_LED2,BMOVBUFF_LED1,AMOVA,BUFF_LED_LPMOVB,#06DIVABMOVA,BRLAMOVDPTR,#TAB_SCANJMP@A+DPTR中斷程序:填充顯示緩沖區(qū)CONT_SCAN:MOVA,35中斷程序:動(dòng)態(tài)顯示TAB_SCAN:AJMPSCAN_L1AJMPSCAN_L2AJMPSCAN_L3AJMPSCAN_L4AJMPSCAN_L5AJMPSCAN_L6SCAN_L1:MOVDIG_PORT,#01111111BMOVA,BUFF_LED1JMPEND_SCANSCAN_L2:MOVDIG_PORT,#10111111BMOVA,BUFF_LED2JMPEND_SCANSCAN_L3:MOVDIG_PORT,#11011111BMOVA,BUFF_LED3JMPEND_SCANSCAN_L4:MOVDIG_PORT,#11101111BMOVA,BUFF_LED4JMPEND_SCANSCAN_L5:MOVDIG_PORT,#11110111BMOVA,BUFF_LED5JMPEND_SCANSCAN_L6:MOVDIG_PORT,#11111011BMOVA,BUFF_LED6END_SCAN:MOVDPTR,#TAB_LEDMOVCA,@A+DPTRMOVLED_PORT,AJNBF_BEEP,EXIT_T0CLRBEEPEXIT_T0:POPPSWPOPACCRETITAB_LED: DB0C0H,0F9H,0A4H,0B0H,99H,92H;數(shù)碼管顯示字型表 DB82H,0F8H,80H,90H,88H,83H,0A7H DB0A1H,86H,8EH
中斷程序:動(dòng)態(tài)顯示TAB_SCAN:AJMPSCAN_36實(shí)驗(yàn)19AD轉(zhuǎn)換器的使用功能:對(duì)輸入的電壓進(jìn)行AD轉(zhuǎn)換,并將結(jié)果(0~255)用數(shù)碼管進(jìn)行顯示使用ADC0832雙通道,8位AD轉(zhuǎn)換器,單+5V供電,Vref=5VAD輸入模擬電壓范圍:0~5V5V對(duì)應(yīng):255串行接口(4線)CS(P3.5)CLK(P2.1)DI(P3.6)DO(P3.7)實(shí)驗(yàn)19AD轉(zhuǎn)換器的使用功能:對(duì)輸入的電壓進(jìn)行AD轉(zhuǎn)換,37ADC0832接口時(shí)序ADC0832接口時(shí)序38最大的問(wèn)題動(dòng)態(tài)顯示資源與AD轉(zhuǎn)換器沖突AD轉(zhuǎn)換器與單片機(jī)接口的實(shí)現(xiàn)最大的問(wèn)題動(dòng)態(tài)顯示資源與AD轉(zhuǎn)換器沖突39實(shí)驗(yàn)19AD轉(zhuǎn)換器的使用(ad.c)#include"reg52.h"sbitADC_CS=P3^5;sbitADC_CLK=P2^1;sbitADC_DI=P3^6;sbitADC_DO=P3^7;bitSecFlag;bitF_ADC_CLK;unsignedcharCount4ms;unsignedchardisp_buff[6];unsignedchardisp_cnt; //0..5unsignedcharhour,min,sec;unsignedcharBeep_cnt;unsignedcharP2_buff;unsignedcharADData;codeunsignedcharTab1[17]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E,0xff};//;數(shù)碼管顯示字型表codeunsignedcharTab[6]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb};實(shí)驗(yàn)19AD轉(zhuǎn)換器的使用(ad.c)#include"40定時(shí)器0中斷服務(wù)函數(shù)voidT0_service(void)interrupt1{ TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); Count4ms=Count4ms+1; if(Count4ms==50) { Count4ms=0; SecFlag=1; } P2_buff=Tab[disp_cnt];
if(!F_ADC_CLK) P2_buff=P2_buff&0xfd; //disp P2=P2_buff; P0=Tab1[disp_buff[disp_cnt]]; disp_cnt=disp_cnt+1; if(disp_cnt==6) disp_cnt=0;}完成定時(shí)(生成1s時(shí)間,主函數(shù)中每秒進(jìn)行一次AD轉(zhuǎn)換)掃描數(shù)碼管定時(shí)器0中斷服務(wù)函數(shù)voidT0_service(void41主函數(shù)與其他函數(shù)voidmain(){ //initial disp_cnt=0; Count4ms=0; hour=0; min=0; sec=0; // TMOD=0x01; TH0=(65536-4000)>>8; TL0=(unsignedchar)(65536-4000); TR0=1; ET0=1; EA=1; while(1) { if(SecFlag) { SecFlag=0; AD(); FillDispBuffer(); } }}voidFillDispBuffer(void){ disp_buff[0]=16; //blank disp_buff[1]=16; disp_buff[2]=16; disp_buff[3]=ADData/100; disp_buff[4]=(ADData%100)/10; disp_buff[5]=ADData%10;}voidpulse(void){ unsignedchari; F_ADC_CLK=1; ADC_CLK=1; i=2; while(i-->0); F_ADC_CLK=0; ADC_CLK=0; i=2; while(i-->0);}主函數(shù)與其他函數(shù)voidmain()voidFillDi42AD轉(zhuǎn)換函數(shù)voidAD(void){ unsignedcharret_dat; unsignedchari; ret_dat=0; ADC_CS=0; i=5; ADC_CS=1; while(i-->0); ADC_CS=0; ADC_DI=1; pulse(); pulse(); pulse(); for(i=0;i<8;i++) { ret_dat=ret_dat<<1; pulse(); if(ADC_DO) ret_dat=ret_dat|0x01; } ADData=ret_dat; if((ret_dat&0x01)==0x01) ret_dat=0x80; else ret_dat=0x00; for(i=0;i<7;i++) { ret_dat=ret_dat>>1; pulse(); if(ADC_DO) ret_dat=ret_dat|0x80; } ADC_CS=1; ADC_CLK=0; ADC_DO=1; ADC_DI=1;}AD轉(zhuǎn)換函數(shù)voidAD(void) ADData=ret43實(shí)驗(yàn)用硬件平臺(tái)(含USB接口寫(xiě)入線)蜂鳴器驅(qū)動(dòng)器ADEEPROM232電平轉(zhuǎn)換晶振繼電器實(shí)驗(yàn)用硬件平臺(tái)(含USB接口寫(xiě)入線)蜂鳴器驅(qū)動(dòng)器ADEEPR44實(shí)驗(yàn)用硬件平臺(tái)(含并口寫(xiě)入線和電源)實(shí)驗(yàn)用硬件平臺(tái)(含并口寫(xiě)入線和電源)45單片機(jī)在線系統(tǒng)AY-MPU89S51EAT89S52單片機(jī)(跳線接上排針時(shí))6位數(shù)碼管動(dòng)態(tài)顯示(P0輸出字形、P2.0~5選擇位)8位LED顯示(P1)6位按鍵輸入(P2.7~2,P3.3)EEPROM:256字節(jié)(IIC接口,P3.2P3.4)8位AD(串行接口)P3.5~7蜂鳴器(P1.7)、繼電器RS232接口(P3.1、P3.2)溫度傳感器單片機(jī)在線系統(tǒng)AY-MPU89S51EAT89S52單片機(jī)(46顯示部分232接口驅(qū)動(dòng)+繼電器顯示部分232接口驅(qū)動(dòng)+繼電器47單片機(jī)在線系統(tǒng)AY-MPU89S51E課件48單片機(jī)在線系統(tǒng)AY-MPU89S51E課件49單片機(jī)在線系統(tǒng)AY-MPU89S51E課件50流水燈實(shí)驗(yàn)(實(shí)驗(yàn)1、2)1、掌握51單片機(jī)如何控制信號(hào)輸出。2、掌握KeilC集成開(kāi)發(fā)環(huán)境的使用。3、掌握51開(kāi)發(fā)平臺(tái)的使用。4、8個(gè)發(fā)光管(L1~L8)接在P1的0~7,為0時(shí)點(diǎn)亮。5、功能:首先點(diǎn)亮L1、然后L2…、最后是L8接著點(diǎn)亮L8、然后是L7L6…L1如此循環(huán),間隔0.1~1.0秒流水燈實(shí)驗(yàn)(實(shí)驗(yàn)1、2)1、掌握51單片機(jī)如何控制信號(hào)輸出51實(shí)驗(yàn)1:流水燈實(shí)驗(yàn)(匯編程序)ORG000HSTART: MOVA,#0FFH CLRC MOVR2,#08HLOOP: RLCA MOVP1,A;輸出至P1口 LCALLDELAY;調(diào)用延遲子程序(延遲100毫秒) DJNZR2,LOOP MOVR2,#07H;設(shè)右移7次LOOP1:RRCA MOVP1,A;輸出至P1口 LCALLDELAY DJNZR2,LOOP1 JMPSTART;跳回到START,再一次循環(huán)。DELAY:MOVR4,#200;延遲子程序(100毫秒)250*2*200=500*200us D1:MOVR5,#248 ;=50*2ms=100ms DJNZR5,$ ;2us DJNZR4,D1 ;2us RETEND實(shí)驗(yàn)1:流水燈實(shí)驗(yàn)(匯編程序)ORG000H52流水燈實(shí)驗(yàn)(C程序)#include"reg52.h"voidDelay(){ unsignedchari,j; for(i=0;i<255;i++) for(j=0;j<255;j++);}voidmain(){ unsignedchari,dat; while(1) { dat=0x01; for(i=0;i<8;i++) {P1=~dat; //L1isfirstlight,thenL2L3…L8 dat=dat<<1; Delay(); } dat=0x80; for(i=0;i<8;i++) {P1=~dat; //L8isfirstlight,thenL7L6…L1 dat=dat>>1; Delay(); } }}流水燈實(shí)驗(yàn)(C程序)#include"reg52.h" d53查表法點(diǎn)亮LED給定表格(33個(gè)8位數(shù))為1則點(diǎn)亮相應(yīng)的發(fā)光二極管間隔0.3~0.9秒查表法點(diǎn)亮LED給定表格(33個(gè)8位數(shù))54實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)BEEPBITP2.0BUFF_LED_LPEQU21H;亮燈循環(huán)寄存器org000hJMPSTARTORG100H;----------------------------------------start:movP1,#0ffh;初始化MCU端口MOVA,#00H;初始化寄存器MOVPSW,#00HMOVIE,#00HMOVSP,#30HMOVBUFF_LED_LP,#00HLOOP:MOVDPTR,#TAB_A_LAMP;設(shè)置亮燈花型列表地址(32種)MOVA,BUFF_LED_LP;查詢(xún)方式讀取花型MOVCA,@A+DPTRCPLAMOVP1,A ;LED小燈控制口LCALLDEL1SINCBUFF_LED_LPMOVA,BUFF_LED_LPCJNEA,#32,LOOPMOVBUFF_LED_LP,#00HJMPLOOP實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)BEEPBIT55實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)續(xù)TAB_A_LAMP:DB00111100B,10000001B,11000011B,11100111B,11111111B,11100111B,11000011B,10000001B,00000000BDB00011000B,00111100B,01111110B,11111111B,00000000B,10101010B,10101010B,11001100BDB10000000B,11000000B,11100000B,11110000B,11111000B,11111100B,11111110B,11111111BDB11111110B,11111100B,11111000B,11110000B,11100000B,11000000B,10000000B,00000000BdeL1S:MOVR5,#03H;延時(shí)子程序(約0.5秒)DEL1S0:movR6,#0ffhDEL1S1:movR7,#0ffhdjnzR7,$djnzR6,del1S1DJNZR5,DEL1S0;CPLBEEPretEND實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(匯編程序)續(xù)56實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(C程序)#include"reg52.h"codeunsignedchartab[]={0x3c,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00, 0x18,0x3c,0x7e,0xff,0x00,0xaa,0xaa,0xcc, 0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff, 0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};voiddelay(){ unsignedchari,j,k; for(i=0;i<2;i++) for(j=0;j<255;j++) for(k=0;k<255;k++);}voidmain(){ unsignedchari; while(1) { for(i=0;i<33;i++) { P1=~tab[i]; delay(); } }}實(shí)驗(yàn)2:流水燈實(shí)驗(yàn)(C程序)#include"reg52.57實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(匯編)
KEYBITP3.3SW1BITP2.7 ;P2.2 byhtqORG000HSTART:movsp,#40hmovp2,#0ffhmovp3,#0ffhMOVP1,#0ffh;clrkeyWAIT:;JBKEY,$;等候按鍵! byhtqJBSW1,$lcalldelaycplP1.0JNBSW1,$ ;waitkeyisreleasedlcalldelay ;byhtqJMPwaitDELAY:MOVR3,#200D1:MOVR4,#200DJNZR4,$DJNZR3,D1RETEND功能:按下SW1一次,發(fā)光管L1點(diǎn)亮或熄滅實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(匯編)KEYBITP3.58實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(C)//keySW1isdown,LED1isswap(onoroff)#include"reg52.h"#defineucharunsignedcharsbitKEY=P3^3;sbitSW1=P2^7;sbitLED1=P1^0;voidDelay(){ uchari,j; for(i=0;i<200;i++) for(j=0;j<200;j++);}voidmain(){ KEY=0; while(1) { while(SW1); Delay(); LED1=!LED1; while(!SW1); Delay(); }}實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(C)//keySW1isdown59;checkall6key ,lightcorrespondLEDs,editbyhtq2009.9.4keydat equ22hKEYBITP3.3 ORG000HSTART:movsp,#40hmovp2,#0ffhmovp3,#0ffhMOVP1,#0ffh;clrkeyWAIT:;JBKEY,$;等候按鍵! byhtq mova,P2 cpl a ;ifsomekeyisdown,thenthebitis0 anl a,#0fch mov keydat,a ; movP0,a jz nokey ;thedownkeyis1;somekeyisdown jb keydat.7,sw1 ;sw1isdown jb keydat.6,sw2 ;sw2isdown jb keydat.5,sw3 ;sw3isdown jb keydat.4,sw4 ;sw4isdown jb keydat.3,sw5 ;sw5isdown jb keydat.2,sw6 ;sw6isdown sjmp nokey實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.asm);checkall6key ,lightcorre60sw1: cpl p1.0 sjmp nokey1sw2: cpl p1.1 sjmp nokey1sw3: cpl p1.2 sjmp nokey1sw4: cpl p1.3 sjmp nokey1sw5: cpl p1.4 sjmp nokey1sw6: cpl p1.5nokey1:calldelay ;byhtqnokey:JMPwaitDELAY: mov R2,#5d2: MOVR3,#200D1:MOVR4,#200DJNZR4,$DJNZR3,D1 djnz r2,d2RETENDsw1:61實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.c)//checkall6key ,lightcorrespondLEDs,editbyhtq2009.9.18#include"reg52.h"#defineucharunsignedcharsbitKEY=P3^3;sbitSW1=P2^7;sbitLED1=P1^0;sbitLED2=P1^1;sbitLED3=P1^2;sbitLED4=P1^3;sbitLED5=P1^4;sbitLED6=P1^5;bdataucharKeyDat;voidDelay(){ uchari,j; for(i=0;i<200;i++) for(j=0;j<200;j++);}voidmain(){ KEY=0; while(1) { KeyDat=P2; P0=KeyDat; //ifsomekeyisdown,thenthebitis0 KeyDat=(~KeyDat)&0xfc; //ifsomekeyisdown,thenthebitis1 Delay(); if(KeyDat!=0)//somekeyisdown { if(KeyDat==0x80) //sw1// if(KeyDat^7==1) //sw1 LED1=!LED1; elseif(KeyDat==0x40) //sw2 LED2=!LED2; elseif(KeyDat==0x20) //sw3 LED3=!LED3; elseif(KeyDat==0x10) //sw4 LED4=!LED4; elseif(KeyDat==0x08) //sw5 LED5=!LED5; elseif(KeyDat==0x04) //sw6 LED6=!LED6; else P1=0xff; Delay(); } }}實(shí)驗(yàn)5:按鍵應(yīng)用實(shí)驗(yàn)(keylight1.c)//check62實(shí)驗(yàn)13八段數(shù)碼管動(dòng)態(tài)顯示(1)99倒計(jì)時(shí):99、98…0、99P0.0~7分別對(duì)應(yīng)數(shù)碼管的a~f、dpP2.7~2分別對(duì)應(yīng)6個(gè)數(shù)碼管:LED1~LED66個(gè)數(shù)碼管的a~f、dp相連共陽(yáng)P2.7為0,點(diǎn)亮P0口為0的字段(如要顯示0,則P0輸出為:11000000B=0xc0實(shí)驗(yàn)13八段數(shù)碼管動(dòng)態(tài)顯示(1)99倒計(jì)時(shí):99、98…06399倒計(jì)時(shí):主程序部分 MIAOEQU21HGEWEIEQU22HSHIWEIEQU23HSCANLEDBIT01HORG000H;ORG偽指令使用于程序定位JMPSTARTORG0BHJMPTIMER0;定時(shí)0中斷入口地址START:MOVSP,#40H;設(shè)定堆棧指針MOVTMOD,#01H;設(shè)定定時(shí)器1為工作方式1MOVTH0,#HIGH(65536-5000)MOVTL0,#LOW(65536-5000)SETBTR0MOVIE,#10000010BMOVR7,#200MOVMIAO,#99AJMP$99倒計(jì)時(shí):主程序部分 MIAOEQU6499倒計(jì)時(shí):中斷程序部分TIMER0:PUSHACC;定時(shí)器1中斷服
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024網(wǎng)絡(luò)安全防護(hù)與監(jiān)測(cè)服務(wù)合同
- 2024離婚雙方的特殊財(cái)產(chǎn)(如古董、藝術(shù)品)分配合同
- 2025年度住宅小區(qū)蟲(chóng)鼠害預(yù)防與治理專(zhuān)項(xiàng)服務(wù)合同模板4篇
- 2025年度安全生產(chǎn)應(yīng)急預(yù)案編制合同規(guī)范3篇
- 2025年度新能源汽車(chē)銷(xiāo)售代理及售后服務(wù)合同3篇
- 2025年度智慧停車(chē)系統(tǒng)車(chē)位租賃管理合同樣本4篇
- 2025年度出租車(chē)公司車(chē)輛更新改造升級(jí)合同3篇
- 2025年度現(xiàn)代農(nóng)業(yè)示范區(qū)場(chǎng)地平整與灌溉系統(tǒng)建設(shè)合同3篇
- 2025年度特色菜肴研發(fā)及廚師團(tuán)隊(duì)聘用協(xié)議4篇
- 2025年度數(shù)據(jù)中心專(zhuān)用電纜供應(yīng)與安裝服務(wù)合同范本4篇
- 雞鴨屠宰生產(chǎn)企業(yè)安全風(fēng)險(xiǎn)分級(jí)管控資料
- 高中物理必修一第六節(jié)共點(diǎn)力的平衡條件及其應(yīng)用課件
- 2020版曼昆版宏觀經(jīng)濟(jì)學(xué)(第十版)課件第3章
- 醫(yī)院感染管理組織架構(gòu)圖
- 《工程招投標(biāo)與合同管理》題庫(kù)試題及答案 共5套試卷
- 離子色譜法分析氯化物原始記錄 (1)
- 高等數(shù)學(xué)說(shuō)課稿PPT課件(PPT 49頁(yè))
- 造影劑腎病概述和性質(zhì)
- 單片機(jī)交通燈系統(tǒng)設(shè)計(jì)報(bào)告
- 標(biāo)桿房企人力資源體系研究之龍湖
- 招商部人員績(jī)效考核辦法最全方案
評(píng)論
0/150
提交評(píng)論