版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、成都理工大學(xué)智能儀器設(shè)計(jì)基礎(chǔ)實(shí)驗(yàn)指導(dǎo)書成都理工大學(xué)核技術(shù)與自動(dòng)化工程學(xué)院電氣工程系2012-9-10目 錄實(shí)驗(yàn)1 單片機(jī) 8255并行I/O擴(kuò)展1實(shí)驗(yàn)2 單片機(jī)的 LCD 驅(qū)動(dòng)實(shí)驗(yàn)3實(shí)驗(yàn)3 SPI接口實(shí)驗(yàn)DS1302時(shí)鐘9實(shí)驗(yàn)4 1-Wire接口實(shí)驗(yàn)DS18b20溫度11實(shí)驗(yàn)5 A/D轉(zhuǎn)換實(shí)驗(yàn)15實(shí)驗(yàn)6 綜合實(shí)驗(yàn)基于51的電子計(jì)算器18實(shí)驗(yàn)1 單片機(jī) 8255并行I/O擴(kuò)展一、實(shí)驗(yàn)?zāi)康模?通過學(xué)生在Proteus7軟件平臺(tái)實(shí)現(xiàn)電路圖設(shè)計(jì),使學(xué)生充分掌握Proteus7軟件的使用、單片機(jī)的并行I/O擴(kuò)展原理及8255芯片的工作原理。二、實(shí)驗(yàn)環(huán)境:計(jì)算機(jī)、Proteus7軟件、Keil C三、實(shí)驗(yàn)
2、步驟:1、電路原理圖設(shè)計(jì)參考原理圖:2、在Keil C 軟件平臺(tái)下編寫程序代碼,參考如下:#include#include#define COM8255 XBYTE0x007F#define PA8255 XBYTE0x007C#define PB8255 XBYTE0x007D#define PC8255 XBYTE0x007E#define uchar unsigned charvoid main()COM8255=0x8E;while(1)PA8255=0xFF;3、Proteus7軟件平臺(tái)下實(shí)現(xiàn)軟硬件仿真,效果如下:實(shí)驗(yàn)2 單片機(jī)的 LCD 驅(qū)動(dòng)實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康模?通過學(xué)生在Prote
3、us7軟件平臺(tái)實(shí)現(xiàn)電路圖設(shè)計(jì),使學(xué)生充分掌握51內(nèi)核單片機(jī)的LCD驅(qū)動(dòng)接口設(shè)計(jì)及驅(qū)動(dòng)程序的編寫原則。二、實(shí)驗(yàn)環(huán)境:計(jì)算機(jī)、Proteus7軟件、Keil C三、實(shí)驗(yàn)步驟:1、電路原理圖設(shè)計(jì)參考原理圖:2、在Keil C 軟件平臺(tái)下編寫程序代碼,參考如下:; LCD Display Driver Demo.; Timing code assumes 1.2MHz Clock;LCD Registers addressesLCD_CMD_WRequ 0LCD_DATA_WRequ1LCD_BUSY_RDequ2LCD_DATA_RDequ3;LCD CommandsLCD_CLSequ1LCD_H
4、OMEequ2LCD_SETMODEequ4LCD_SETVISIBLEequ8LCD_SHIFTequ16LCD_SETFUNCTIONequ32LCD_SETCGADDRequ64LCD_SETDDADDRequ128;Reset vectororg 0000hjmp start;Start of the programorg 0100hstring1a:db ! A M A Z I N G ! db 0string1b:db ! A M A Z I N G ! db 0string2:db A virtual LM032L. db 0string3:db driven by a virt
5、ual db 0string4:db 8051 processor!db 0start:mov A,#038hcall wrcmdloop:mov A,#LCD_SETVISIBLE+6 ;Make the display & blink visible:call wrcmdmov R7,#2loop2: mov DPTR,#string1acall wrstr mov DPTR,#200 call wtmsmov A,#LCD_CLS;Clear screencall wrcmdmov DPTR,#string1bcall wrstr mov DPTR,#200 call wtmsmov A
6、,#LCD_CLS;Clear screencall wrcmddjnz R7,loop2mov DPTR,#string1acall wrstr mov DPTR,#400 call wtmsmov A,#LCD_SETDDADDR+64call wrcmdmov DPTR,#string2call wrslow mov DPTR,#200 call wtmsmov A,#LCD_CLS;Clear screencall wrcmdmov DPTR,#string3call wrslow mov A,#LCD_SETDDADDR+64call wrcmdmov DPTR,#string4ca
7、ll wrslowmov A,#LCD_SETVISIBLE+7;Show the blink cursor as well.call wrcmd mov DPTR,#2000 call wtmsmov A,#LCD_CLS;Clear screencall wrcmdjmp loop;Sub routine to write null terminated string at DPTR in program ram.wrstr:mov R0,#LCD_DATA_WRwrstr1:clr Amovc A,A+DPTRjz wrstr2movx R0,Acall wtbusyinc DPTRpu
8、sh DPLpush DPHpop DPHpop DPLjmp wrstr1wrstr2:ret;Sub routine to write null terminated string at DPTR in program ram. Slowlywrslow:mov R0,#LCD_DATA_WRwrslw1:clr Amovc A,A+DPTRjz wrslw2movx R0,Acall wtbusyinc DPTRpush DPLpush DPH mov DPTR,#100 call wtmspop DPHpop DPLjmp wrslw1wrslw2:ret;Sub routine to
9、 write command:wrcmd:mov R0,#LCD_CMD_WRmovx R0,Ajmp wtbusy;Sub routine to write character:wrchar:mov R0,#LCD_DATA_WRmovx R0,A;Subroutine to wait for busy clearwtbusy: mov R1,#LCD_BUSY_RDmovx A,r1jb ACC.7,wtbusyret;Wait for number of seconds in Awtsec:push ACCcall wtmspop ACCdec Ajnz wtsecret;Wait fo
10、r number of milliseconds in DPTRwtms: xrl DPL,#0FFh;Cant do DEC DPTR, so do the loop by forming 2s complementxrl DPH,#0FFh;and incrementing instead.inc DPTRwtms1:mov TL0,#09Ch;100 ticks before overflow = 1ms at 1.2MHz Clockmov TH0,#0FFhmov TMOD,#1;Timer 0 mode 1setb TCON.4;Timer 0 runswtms2:jnb TCON
11、.5,wtms2clr TCON.4;Timer 0 stopsclr TCON.5inc DPTRmov A,DPLorl A,DPHjnz wtms1retEND 3、Proteus7軟件平臺(tái)下實(shí)現(xiàn)軟硬件仿真,效果如下:實(shí)驗(yàn)3 SPI接口實(shí)驗(yàn)DS1302時(shí)鐘一、實(shí)驗(yàn)?zāi)康模?通過學(xué)生在Proteus7軟件平臺(tái)實(shí)現(xiàn)電路圖設(shè)計(jì),使學(xué)生充分掌握SPI工作原理,并掌握DS1302時(shí)鐘的軟硬件實(shí)現(xiàn)方法。二、實(shí)驗(yàn)環(huán)境:計(jì)算機(jī)、Proteus7軟件、Keil C三、實(shí)驗(yàn)步驟:1、電路原理圖設(shè)計(jì)參考原理圖:2、在Keil C 軟件平臺(tái)下編寫程序代碼,參考如下:#include #include LCD160
12、2.h#include DS1302.hvoid Delay1ms(unsigned int count)unsigned int i,j;for(i=0;icount;i+)for(j=0;j120;j+);main()SYSTEMTIME CurrentTime;LCD_Initial();Initial_DS1302();GotoXY(0,0);Print(Date: );GotoXY(0,1);Print(Time: );while(1)DS1302_GetTime(&CurrentTime);DateToStr(&CurrentTime);TimeToStr(&CurrentTime
13、);GotoXY(6,0);Print(CurrentTime.DateString);GotoXY(6,1);Print(CurrentTime.TimeString);Delay1ms(300);3、Proteus7軟件平臺(tái)下實(shí)現(xiàn)軟硬件仿真,效果如下:實(shí)驗(yàn)4 1-Wire接口實(shí)驗(yàn)DS18b20溫度一、實(shí)驗(yàn)?zāi)康模?通過學(xué)生在Proteus7軟件平臺(tái)實(shí)現(xiàn)電路圖設(shè)計(jì),使學(xué)生充分掌握1-Wire工作原理,并掌握DS18b20溫度的軟硬件實(shí)現(xiàn)方法。二、實(shí)驗(yàn)環(huán)境:計(jì)算機(jī)、Proteus7軟件、Keil C三、實(shí)驗(yàn)步驟:1、電路原理圖設(shè)計(jì)參考原理圖:2、在Keil C 軟件平臺(tái)下編寫程序代碼,參考如下:
14、#include /用AT89C51時(shí)就用這個(gè)頭文件/#include /用華邦W78E58B時(shí)必須用這個(gè)頭文件#include #include #include #include #include #include #include LCD1602.h/液晶顯示頭文件/sbit DQ = P34;/定義DQ引腳為P3.4unsigned char t2,*pt;/用來存放溫度值,測溫程序就是通過這個(gè)數(shù)組與主函數(shù)通信的unsigned char TempBuffer19=0x2b,0x31,0x32,0x32,0x2e,0x30,0x30,0x43,0;/顯示實(shí)時(shí)溫度,上電時(shí)顯示+125.0
15、0Cunsigned char TempBuffer017=0x54,0x48,0x3a,0x2b,0x31,0x32,0x35,0x20,0x54,0x4c,0x3a,0x2b,0x31,0x32,0x34,0x43,0;/顯示溫度上下限,上電時(shí)顯示TH:+125 TL:+124Cunsigned char code dotcode4=0,25,50,75;/*因顯示分辨率為0.25,但小數(shù)運(yùn)算比較麻煩,故采用查表的方法*再將表值分離出十位和個(gè)位后送到十分位和百分位*/void covert0( unsigned char TH, unsigned char TL)/將溫度上下限轉(zhuǎn)換為LCD
16、顯示的數(shù)據(jù) if(TH0x7F) /判斷正負(fù),如果為負(fù)溫,將其轉(zhuǎn)化為其絕對值 TempBuffer03=0x2d; /0x2d為-的ASCII碼TH=TH;TH+; else TempBuffer03=0x2b;/0x2B為+的ASCII碼 if(TL0x7f) TempBuffer011=0x2d; /0x2d為-的ASCII碼 TL=TL+1; else TempBuffer011=0x2b;/0x2B為+的ASCII碼 TempBuffer04=TH/100+0x30; /分離出TH的百十個(gè)位 if( TempBuffer04=0x30) TempBuffer04=0xfe; /百位數(shù)消
17、隱 TempBuffer05=(TH%100)/10+0x30;/分離出十位 TempBuffer06=(TH%100)%10+0x30; /分離出個(gè)位 TempBuffer012=TL/100+0x30; /分離出TL的百十個(gè)位 if( TempBuffer012=0x30) TempBuffer012=0xfe; /百位數(shù)消隱 TempBuffer013=(TL%100)/10+0x30;/分離出十位 TempBuffer014=(TL%100)%10+0x30; /分離出個(gè)位void covert1(void)/將溫度轉(zhuǎn)換為LCD顯示的數(shù)據(jù) unsigned char x=0x00,y=
18、0x00; t0=*pt; pt+; t1=*pt; if(t10x07) /判斷正負(fù)溫度 TempBuffer10=0x2d; /0x2d為-的ASCII碼t1=t1; /*下面幾句把負(fù)數(shù)的補(bǔ)碼*/t0=t0; /* 換算成絕對值*/x=t0+1; /*/t0=x; /*/if(x255) /*/t1+; /*/ else TempBuffer10=0x2b;/0xfe為變+的ASCII碼 t1=4;/右移4位 x=x&0x0f;/和前面兩句就是取出t0的高四位 t1=t1|x;/將高低字節(jié)的有效值的整數(shù)部分拼成一個(gè)字節(jié) TempBuffer11=t1/100+0x30; /+0x30 為變
19、 09 ASCII碼 if( TempBuffer11=0x30) TempBuffer11=0xfe; /百位數(shù)消隱 TempBuffer12=(t1%100)/10+0x30;/分離出十位 TempBuffer13=(t1%100)%10+0x30; /分離出個(gè)位 t0=t0&0x0c;/取有效的兩位小數(shù) t0=2;/左移兩位,以便查表 x=t0; y=dotcodex;/查表換算成實(shí)際的小數(shù) TempBuffer15=y/10+0x30;/分離出十分位 TempBuffer16=y%10+0x30;/分離出百分位void delay(unsigned char i)while(i-);m
20、ain() unsigned char TH=110,TL=-20; /下一步擴(kuò)展時(shí)可能通過這兩個(gè)變量,調(diào)節(jié)上下限 /測溫函數(shù)返回這個(gè)數(shù)組的頭地址 while(1) pt=ReadTemperature(TH,TL,0x3f); /上限溫度-22,下限-24,分辨率10位,也就是0.25C /讀取溫度,溫度值存放在一個(gè)兩個(gè)字節(jié)的數(shù)組中,delay(100); covert1();covert0(TH,TL);LCD_Initial();/第一個(gè)參數(shù)列號(hào),第二個(gè)為行號(hào),為0表示第一行/為1表示第二行,第三個(gè)參數(shù)為顯示數(shù)據(jù)的首地址LCD_Print(0,0,TempBuffer0);LCD_Pri
21、nt(0,1,TempBuffer1); 3、Proteus7軟件平臺(tái)下實(shí)現(xiàn)軟硬件仿真,效果如下:實(shí)驗(yàn)5 A/D轉(zhuǎn)換實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康模?通過學(xué)生在Proteus7軟件平臺(tái)實(shí)現(xiàn)電路圖設(shè)計(jì),使學(xué)生充分掌握A/D工作原理,并掌握AD0808的軟硬件實(shí)現(xiàn)方法。二、實(shí)驗(yàn)環(huán)境:計(jì)算機(jī)、Proteus7軟件、Keil C三、實(shí)驗(yàn)步驟:1、電路原理圖設(shè)計(jì)參考原理圖:2、在Keil C 軟件平臺(tái)下編寫程序代碼,參考如下:#include #include 1602.h#define uchar unsigned char#define uint unsigned intuchar *p,a3;void ucha
22、r2string(uchar);void LCD_disp_string(uchar x,uchar y,uchar *Date);sbit EOC=P30;sbit ST=P36;sbit OE=P37;void main()uchar convertnum;uint temp;P2=0xff;P3=0xff;p=a;LCD_init(0x38,0x0c,0x04,LCD_CLEAR_SCREEN);delay_ms(10);LCD_disp_string(0,0,AD0808 Show:);LCD_disp_string(0,1,Value:);while(1)ST=0;ST=1;ST=0
23、;while(EOC=0) OE=1;convertnum=P2;OE=0;temp=convertnum*5; temp=temp/256;convertnum=temp;uchar2string(convertnum);LCD_disp_string(7,1,p);delay_ms(1);/*顯示函數(shù)*/void LCD_disp_string(uchar x,uchar y,uchar *Data)if (y=LINE1)LCD_send_command(LINE1_HEAD+x);for(;xLINE_LENGTH&*Data!=0;x+)LCD_send_data(*(Data+);
24、if(y=LINE2)LCD_send_command(LINE2_HEAD+x);for(;x .jz eos_foundmovx R0,Acall wtbusyinc R5mov A,R5djnz R6,loop1; R6 *holds* the string to 20 characters or on 1 line.eos_found:mov R5,#0mov R2,stroffset cjne R2,#0,loop2; Check for case with no wrap.retloop2: mov A,R5; Loop2 wraps from the first characte
25、r to the offset.movc A,A+DPTRmovx R0,Acall wtbusy inc R5djnz B,loop2 push DPL; Pause after writing the string.push DPHmov DPTR,#2call wtmspop DPHpop DPLret;*;* Keypad Routines *;*XSEG ; External Data Memeory - Access through DPTR.;* BUFFERS *; Buffers are set up with byte 0 as the sign - the releven
26、t number of digits - and the final bit for the terminator.; The exception to this is the Hundredbuffer which is *hardcoded* at 100. In practice this means that a ten byte; buffer holds an 8 digit number (sign&number&terminator = 10 ). KEYBUFFER: ds 10; General I/O buffer. OLDNUMBUFFER: ds 10; Holds
27、the previous number ( used for repeat operations)MEMORYBUFFER: ds 10; Holds the number in memoryHUNDREDBUFF : ds 5; Holds the constant number 100BOUNDBUFFER: ds 10; Holds 99999999 and is signed so both upper and lower bounds can be checked.TEMPBUFFER: ds 25; Holds the operation result until compared
28、 with boundsbuffer.DSEG AT 060h; Data memory.;* FLAGS *; Flags are used mainly because most of the operators have different functionality when consecutively pressed more than once.; Status returns 1 after an operator press and 0 after a digit key press.equalsflag: ds 1; Flag for the equals operator.
29、memopflag: ds 1; Flag for memory operations.arithopflag: ds 1; Flag for arithmetic operations.pctopflag: ds 1; Flag for the percentage operator.memocc: ds 1; Flag whether there is a value in the memory buffererrorflag: ds 1; Flag an error.signflag: ds 1; Boolean for the sign of the number ( default
30、to +ve ) status: ds 1; Flag the type of key pressed ( operator or digit ).;* VARIABLES *opcodehex:ds 1; Store the operation type.oldopcode :ds 1; As above - must be able to store the last operation as well as the current; one for cancel command and consecutive operator presses.opcodeflag: ds 1buffer
31、ctr: ds 1; A counter ( incremented along the buffer on storing a digit ).opcounter: ds 1; Count the number of operations since a ( total ) Cancel.digitcode: ds 1; Holds the ascii value of the key pressed.mode: ds 1; Determines at which buffer the DTPR addresses. memcounter: ds 1; Stores the length of the number currently in the memorybuffercopyfrom: ds 1; Used to copy the contents of one buffer into another buffercopyto:ds 1; As above.localvar: ds 1; L
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二級(jí)水電站建設(shè)工程施工合同(2024版)
- 媒介朝覲:“哈爾濱出圈”背后的數(shù)字營銷策略分析
- 2025年人教版(2024)九年級(jí)科學(xué)下冊階段測試試卷含答案
- 2025年中圖版八年級(jí)科學(xué)下冊月考試卷含答案
- 2025-2030年中國化纖漿粕市場發(fā)展現(xiàn)狀及前景趨勢分析報(bào)告
- 2025-2030年中國冷飲(水冰)市場發(fā)展現(xiàn)狀及前景趨勢分析報(bào)告
- 2025-2030年中國不銹鋼復(fù)合板行業(yè)市場發(fā)展現(xiàn)狀及前景趨勢分析報(bào)告
- 2025-2030年中國L谷氨酰胺行業(yè)競爭格局及前景趨勢預(yù)測報(bào)告
- 2024年食品生產(chǎn)加工設(shè)備租賃合同
- 臨時(shí)教師2024年度聘任合同版B版
- 大學(xué)生職業(yè)生涯規(guī)劃-自我認(rèn)知-課件
- 硬件研發(fā)產(chǎn)品規(guī)格書mbox103gs
- 直升機(jī)結(jié)構(gòu)與系統(tǒng)版
- 青春期教育-女生版青春期性教育-青春期性教育自慰課件
- 新生兒疾病診療規(guī)范診療指南診療常規(guī)2022版
- 兒科學(xué) 新生兒顱內(nèi)出血
- YY/T 0065-2016眼科儀器裂隙燈顯微鏡
- 喜報(bào)可編輯11張
- 食管癌護(hù)理查房20352
- 餐飲服務(wù)投標(biāo)文件
- 城投公司的債務(wù)風(fēng)險(xiǎn)及化解方式
評論
0/150
提交評論