【正文】
]許超, 吳新杰, 張丹. 基于Proteus和Keil的單片機課程教學改革. 遼寧大學學報(自然科學版), 2011, 28(12): 1926[14]張越, 張炎, 趙延軍. 基于DS18B20溫度傳感器的數(shù)字溫度計, 2011[15]陳海宴. 51單片機原理及應用. 北京航空航天大學出版社, 2010 [16]Li Weidi, GuoQiang. Application technology of LCD displays. China Publishing House of Electronics Industry, 2000.[17]Su Kai, Liu Qingguo, Chen Guoping. Principle and design of MCS51 Singlechip microprocessor. Metallurgical Industry Press, 2003.[18]G Jiang M Zhang, X Xie, S Li. Application on temperature control of DS18B2. Control Engineering of China, 2003附 錄系統(tǒng)原理圖系統(tǒng)源程序includedefine uint unsigned intdefine uchar unsigned charuchar code table[]=temperature:。uint temp[7],wendu。 //存放分解的7個ASCII碼溫度數(shù)據(jù)uint temperature[2]。 //存放溫度數(shù)據(jù)sbit DS1820_DQ=P1^4。sbit lcdrw=P2^5。sbit lcdrs=P2^4。sbit lcden=P2^6。sbit buzzer=P1^0。uchar num。void init_chuankou(){ TMOD=0x20。//設置定時器1為工作方式2 TH1=0xfd。//設置波特率為9600 TL1=0xfd。 TR1=1。//打開定時器1 REN=1。//允許串口接收 SM0=0。 SM1=1。//串口方式1}void PC_get(){ ES=0。 SBUF=wendu。 while(!TI)。 //是否接收完數(shù)據(jù) TI=0。 ES=1。}void delay(uint z){ uint x,y。 for(x=z。x0。x) for(y=110。y0。y)。}void write_(uint ){ lcdrs=0。 P0=。 delay(5)。 lcden=1。 delay(5)。 lcden=0。}void write_data(uint date){ lcdrs=1。 P0=date。 delay(5)。 lcden=1。 delay(5)。 lcden=0。}void lcd_init(){ lcdrw=0。 lcden=0。 write_(0x38)。//設置16X2顯示,5X7點陣,8位數(shù)據(jù)接口 write_(0x0e)。//開顯示,顯示光標,光標閃爍 write_(0x06)。//指針加一且光標加一,不移屏 write_(0x01)。//清屏}void delay_18B20(unsigned int i){ while(i)。}uint DS1820_Reset(){bit flag。DS1820_DQ=1。delay_18B20(8)。 DS1820_DQ = 0。 //拉低總線 delay_18B20(48)。 //延時480微秒,產(chǎn)生復位脈沖 DS1820_DQ = 1。 //釋放總線 delay_18B20(8)。 //延時80微秒對總線采樣 flag = DS1820_DQ。 //對數(shù)據(jù)腳采樣delay_18B20(40)。 //延時400微秒等待總線恢復 return (flag)。 //根據(jù)flag的值可知DS1820是否存在或損壞,可加聲音報警提示DS1820故障}void DS1820_WriteData(uint wData){ uint i。 for (i=8。i0。i) { DS1820_DQ = 0。 //拉低總線,產(chǎn)生寫信號 //delay(1)。 //延時4us DS1820_DQ = wDataamp。0x01。 //發(fā)送1位 delay_18B20(6)。 //延時60us,寫時序至少要60us DS1820_DQ = 1。 //釋放總線,等待總線恢復 delay_18B20(1)。 wData=1。 //準備下一位數(shù)據(jù)的傳送 }}uint DS1820_ReadData(){ uint i,TmepData。 for (i=8。i0。i) { DS1820_DQ = 0。 //拉低總線,產(chǎn)生讀信號 TmepData=1。 //delay_18B20(1)。 //延時4us DS1820_DQ = 1。 //釋放總線,準備讀數(shù)據(jù) delay_18B20(1)。 //延時8微秒讀數(shù)據(jù) if (DS1820_DQ == 1) TmepData |= 0x80。 delay_18B20(6)。 //延時60us DS1820_DQ = 1。 //拉高總線,準備下一位數(shù)據(jù)的讀取 } return (TmepData)。//返回讀到的數(shù)據(jù)}void DS18B20_Init(){ DS1820_Reset()。 DS1820_WriteData(0xCC)。 // 跳過ROM DS1820_WriteData(0x4E)。 // 寫暫存器// DS1820_WriteData(0x20)。 // 往暫存器的第三字節(jié)中寫上限值// DS1820_WriteData(0x00)。 // 往暫存器的第四字節(jié)中寫下限值 DS1820_WriteData(0x7F)。 // 將配置寄存器配置為12位精度 DS1820_Reset()。}void display()。void main(){ uchar i。 init_chuankou()。 lcd_init()。 DS18B20_Init()。 write_(0x80)。//開始地址 for(num=0。num12。num++) { write_data(table[num])。 } delay(50)。 while(1) { DS1820_Reset()。 //復位 DS1820_WriteData(0xcc)。 //跳過ROM命令 DS1820_WriteData(0x44)。 //溫度轉(zhuǎn)換命令 delay_18B20(100)。 DS1820_Reset()。 //復位 DS1820_WriteData(0xcc)。 //跳過ROM命令 DS1820_WriteData(0xbe)。 //讀DS1820溫度暫存器命令 delay_18B20(100)。 for (i=0。i2。i++) temperature[i]=DS1820_ReadData()。 //采集溫度 DS1820_Reset()。 display()。 if(wendu=0x20)//當大于32度報警時 { write_data(0x48)。 buzzer=0。delay(100)。 } if(wendu=0x14)//或小于20度報警 { write_data(0x4c)。 buzzer=0。delay(100)。 } if(wendu0x20||wendu0x14) { write_data(0x20)。 buzzer=1。 } PC_get()。 }}void display(){ uint temp_data1,temp_data2,m。 uint XiaoShu。 //用來存放4位小數(shù) temp_data1=temperature[1]。 temp_data1amp。=0xf0。 //取高4位 m=temp_data1。 if (temp_data1==0xf0) //判斷是正溫度還是負溫度讀數(shù) { temp_data1=0x00。 //負溫度讀數(shù)求補,取反加1,判斷低8位是否有進位 if (temperature[0]==0)//有進位,高8位取反加1 { temperature[0]=~temperature[0]+1。 temperature[1]=~temperature[1]+1。 } else//沒進位,高8位不加1 { temperature[0]=~temperature[0]+1。 temperature[1]=~temperature[1]。 }` } temp_data1=temperature[1]4。 temp_data2=temperature[0]4。 temp_data1=temp_data1|temp_data2。 temp[0]=temp_data1/100+0x30。//加0x30是把轉(zhuǎn)換成字符庫代碼 temp[1]=temp_data1%100/10+0x30。 temp[2]=temp_data1%100%10+0x30。//整數(shù)部分 temperature[0]amp。=0x0f。//小數(shù)部分 XiaoShu=temperature[0]*625。 temp[3]=XiaoShu/1000+0x30。 temp[4]=(XiaoShu%1000)/100+0x30。 temp[5]=((XiaoShu%1000)%100)/10+0x30。 temp[6]=((XiaoShu%1000)%100)%10+0x30。 wendu=(temp[1]0x30)*10+(temp[2]0x30)。 if(m==0xf0) { m=0。 write_(0x80+0x44)。 write_data(0xb0)。 write_data(temp[1]2)。 write_data(temp[2])。 write_data(0x2e)。 write_data(temp[3])。 write_data(temp[4])。 write_data(temp[5])。 write_data(temp[6])。 write_data(0xdf)。 write_data(0x43)。 } else { write_(0x80+0x43)。 if(temp[0]==0X30) { write_data(0x20)。 } else { write data(temp[0])。 } write_data(temp[1])。 write_data(temp[2])。 write_data(0x2e)。 write_data(temp[3])。 write_data(temp[4])。 write_data(temp[5])。 write_data(temp[6])。 write_data(0xdf)。 write_data(0x43)。 } }外文資料翻譯1. Principle of SCMSinglechip is an integrated on a single chip a plete puter system. Even though most of his features in a small chip, but it has a need to plete the majority of puter ponents: CPU, memory, internal and external bus system, most will have the Core. At the same time, such as integrated munication interfaces, timers, realtime clock and other peripheral equipment. And now the most powerful singlechip microputer system can even voice, image, networking, input and output plex system integration on a single chip. Also known as singlechip SCM(Microcontroller), because it was first used in the field of industrial control. Only by the singlechip CPU chip developed from the dedicated processor. The design concept is the f