【正文】
nology 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個(gè)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。//設(shè)置定時(shí)器1為工作方式2 TH1=0xfd。//設(shè)置波特率為9600 TL1=0xfd。 TR1=1。//打開定時(shí)器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)。//設(shè)置16X2顯示,5X7點(diǎn)陣,8位數(shù)據(jù)接口 write_(0x0e)。//開顯示,顯示光標(biāo),光標(biāo)閃爍 write_(0x06)。//指針加一且光標(biāo)加一,不移屏 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)。 //延時(shí)480微秒,產(chǎn)生復(fù)位脈沖 DS1820_DQ = 1。 //釋放總線 delay_18B20(8)。 //延時(shí)80微秒對(duì)總線采樣 flag = DS1820_DQ。 //對(duì)數(shù)據(jù)腳采樣delay_18B20(40)。 //延時(shí)400微秒等待總線恢復(fù) return (flag)。 //根據(jù)flag的值可知DS1820是否存在或損壞,可加聲音報(bào)警提示DS1820故障}void DS1820_WriteData(uint wData){ uint i。 for (i=8。i0。i) { DS1820_DQ = 0。 //拉低總線,產(chǎn)生寫信號(hào) //delay(1)。 //延時(shí)4us DS1820_DQ = wDataamp。0x01。 //發(fā)送1位 delay_18B20(6)。 //延時(shí)60us,寫時(shí)序至少要60us DS1820_DQ = 1。 //釋放總線,等待總線恢復(fù) delay_18B20(1)。 wData=1。 //準(zhǔn)備下一位數(shù)據(jù)的傳送 }}uint DS1820_ReadData(){ uint i,TmepData。 for (i=8。i0。i) { DS1820_DQ = 0。 //拉低總線,產(chǎn)生讀信號(hào) TmepData=1。 //delay_18B20(1)。 //延時(shí)4us DS1820_DQ = 1。 //釋放總線,準(zhǔn)備讀數(shù)據(jù) delay_18B20(1)。 //延時(shí)8微秒讀數(shù)據(jù) if (DS1820_DQ == 1) TmepData |= 0x80。 delay_18B20(6)。 //延時(shí)60us DS1820_DQ = 1。 //拉高總線,準(zhǔn)備下一位數(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()。 //復(fù)位 DS1820_WriteData(0xcc)。 //跳過ROM命令 DS1820_WriteData(0x44)。 //溫度轉(zhuǎn)換命令 delay_18B20(100)。 DS1820_Reset()。 //復(fù)位 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)//當(dāng)大于32度報(bào)警時(shí) { write_data(0x48)。 buzzer=0。delay(100)。 } if(wendu=0x14)//或小于20度報(bào)警 { 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) //判斷是正溫度還是負(fù)溫度讀數(shù) { temp_data1=0x00。 //負(fù)溫度讀數(shù)求補(bǔ),取反加1,判斷低8位是否有進(jìn)位 if (temperature[0]==0)//有進(jìn)位,高8位取反加1 { temperature[0]=~temperature[0]+1。 temperature[1]=~temperature[1]+1。 } else//沒進(jìn)位,高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 first by a large number of peripherals and CPU in a single chip, the puter system so that smaller, more easily integrated into the plex and demanding on the volume control devices. INTEL the Z80 is one