欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
DS18B20、LCD1602的使用單片機課程設計實驗報告
[打印本頁]
作者:
創建新賬號51黑
時間:
2018-11-12 14:14
標題:
DS18B20、LCD1602的使用單片機課程設計實驗報告
課程設計實驗報告
實驗名稱: 實驗三:溫度測量
班 級: 信息工程
實驗日期: 2018年11月12日
一、 實驗目的
1. 熟練電路設計、焊接操作;
2. 熟悉STC15W408AS芯片;
3. 實現DS18B20溫度測量,并用LCD1602顯示;
4、顯示接收的CRC校驗碼。
二、 實驗環境
1. 焊接工具:烙鐵、焊錫絲、連接線、洞洞板;
2. 元器件:STC15W408AS芯片1片、溫度傳感DS18B20一枚、LCD1602顯示屏一枚、5k電阻一只、10k電位器一只;
3. 軟件開發環境:Keil uVision5。
三、 實驗題目
實驗:顯示一支DS18B20溫度值,并顯示CRC校驗碼。
四、 實驗原理
DS18B20主要由4部分組成:64 位ROM、溫度傳感器、非揮發的溫度報警觸發器TH和TL、配置寄存器。ROM中的64位序列號是出廠前被光刻好的,它可以看作是該DS18B20的地址序列碼,每個DS18B20的64位序列號均不相同。64位ROM的排的循環冗余校驗碼(CRC=X^8+X^5+X^4+1)。 ROM的作用是使每一個DS18B20都各不相同,這樣就可以實現一根總線上掛接多個DS18B20的目的。
LCD1602是一種工業字符型液晶,能夠同時顯示16x02即32個字符。LCD1602液晶顯示原理 LCD1602液晶顯示的原理是利用液晶的物理特性,通過電壓對其顯示區域進行控制,有電就有顯示,這樣即可以顯示出圖形。1602液晶也叫1602字符型液晶,它是一種專門用來顯示字母、數字、符號等的點陣型液晶模塊。
DS18B20的1腳接GND,2腳接5K的上拉電阻、接單片機的數據端,3腳接VCC;LCD的V0口需接入10K的電位器以控制亮與暗。
五、 實驗代碼
六、 實驗總結
在本次實驗中,通過對DS18B20以及LCD1602數據手冊的學習,我學會了STC15W系列單片機的軟件控制LCD1602的讀寫以及DS18B20有關溫度的測量,增強了關于單片機功能實現的理解。
#include"reg51.h"
#include"intrins.h"
#define FOSC 11059200L
#define BAUD 9600
#define NONE_PARITY 0
#define PARITYBIT NONE_PARITY
#define ds P26 // DS18B0、
#define DataPort P1 // LCD1602
#define uchar unsigned char
#define uint unsigned char
typedef unsigned char uint_8;
typedef unsigned int uint_32;
typedef unsigned short int uint_16;
//LCD1602
sbit LCM_RS=P3^7;
sbit LCM_RW=P3^6;
sbit LCM_EN=P3^5;
sbit P22 = P2^2;
sbit P26 = P2^6;
sfr T2H = 0xD6;
sfr T2L = 0xD7;
sfr AUXR = 0x8E;
unsigned char code crc_array[256] = {
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc,
0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62,
0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff,
0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07,
0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a,
0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24,
0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9,
0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd,
0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50,
0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee,
0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73,
0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b,
0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16,
0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8,
0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35,
};
bit ack = 0; //DS18B20
bit busy;
uint_8 dis[4];
void SendData(uint_8 dat)//
{
while(busy);
ACC = dat;
busy = 1;
SBUF = ACC;
}
void Uart() interrupt 4 using 1
{
if (RI)
{
uint_8 a;
RI = 0;
a=SBUF;
P22 = RB8;
}
if (TI)
{
TI = 0;
busy = 0;
}
}
void lcd_printf(uint_8 *s,int temp_data)//
{
*s =temp_data/1000+0x30;
temp_data=temp_data%1000;
*++s =temp_data/100+0x30;
temp_data=temp_data%100;
*++s =temp_data/10+0x30;
temp_data=temp_data%10;
*++s =temp_data+0x30;
}
void Delay30us() //@11.0592MHz
{
unsigned char i;
_nop_();
_nop_();
i = 80;
while (--i);
}
void Delay100us() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 2;
j = 15;
do
{
while (--j);
} while (--i);
}
void Delay200us() //@11.0592MHz
{
unsigned char i, j;
i = 3;
j = 35;
do
{
while (--j);
} while (--i);
}
void ds_reset()//DS18B20
{
ds = 1;
ds = 0;
Delay200us();
Delay200us();
ds = 1;
Delay30us();
if(0 == ds)
{
ack = 1;
}
else
{
ack = 0;
}
Delay200us();
Delay100us();
}
void ds_send_byte(unsigned char byte)
{
unsigned char i;
for(i = 0; i < 8; i++)
{
ds = 0;
_nop_();
_nop_();
ds = byte & 0x01;
byte >>= 1;
Delay30us();
ds = 1;
}
}
bit ds_read_bit()
{
bit tmp;
ds = 1;
ds = 0;
_nop_();
_nop_();
ds = 1;
tmp = ds;
Delay30us();
return tmp;
}
unsigned char ds_read_byte()
{
unsigned char i,j,k;
for(i = 0; i < 8; i++)
{
j = ds_read_bit();
k = (j << 7) | (k >> 1);
}
return k;
}
void Delay200ms()
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 10;
j = 31;
k = 147;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void intsend(int value)
{
uint_8 i;
lcd_printf(dis, value);
for(i=0;i<4;i++)
{
SendData(dis[i]);
}
}
void WaitForEnable(void)
{
DataPort=0xff;
LCM_RS=0;LCM_RW=1;_nop_();
LCM_EN=1;_nop_();_nop_();
while(DataPort&0x80);
LCM_EN=0;
}
void WriteCommandLCM(uchar CMD,uchar A)
{
if(A)WaitForEnable();
LCM_RS=0;LCM_RW=0;_nop_();
DataPort=CMD;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
void InitLcd()
{
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
void WriteDataLCM(uchar dataW)
{
WaitForEnable();
LCM_RS=1; LCM_RW=0;_nop_();
DataPort=dataW;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)X|=0x40;
X|=0x80;
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
void DisplayListChar(uchar X,uchar Y,uchar *DData,L)//
{
uchar ListLength=0;
Y&=0x1;
X&=0xF;
while(L--)
{
DisplayOneChar(X,Y,DData[ListLength]);
ListLength++;
X++;
}
}
void Display10BitData(int value,uchar x,uchar y,uchar wei)
{
lcd_printf(dis, value);
DisplayListChar(x,y,dis,wei);
}
unsigned char CRC8_Table(unsigned char *p, char counter)//
{
unsigned char crc8 = 0;
for(; counter>0; counter--)
{
crc8 = crc_array[crc8^*p];
p++;
}
return crc8;
}
void main(void)
{
uint_8 T_low; //
uint_8 DU[9]; //DS16B20
uint_8 CRCC; //
uint_16 T_high; //
uint_16 tmp; //
uint_8 ii;
float temperature; //
//LCD1602
Delay200ms();
Delay200ms();
InitLcd();
Delay200ms();
SCON = 0x50;
T2L = (65536 - (FOSC/4/BAUD));
T2H = (65536 - (FOSC/4/BAUD))>>8;
AUXR = 0x14;
AUXR |= 0x01;
ES = 1;
EA=1;
ACC=AUXR;
while (1)
{
ds_reset();
ds_send_byte(0xcc);
ds_send_byte(0x44);
ds_reset();
ds_send_byte(0xcc);
ds_send_byte(0xbe);
DU[0] = ds_read_byte();
DU[1] = ds_read_byte();
DU[2] = ds_read_byte(); //0075
DU[3] = ds_read_byte(); //0070
DU[4] = ds_read_byte(); //0127
DU[5] = ds_read_byte(); //0255
DU[6] = ds_read_byte();
DU[7] = ds_read_byte();
DU[8] = ds_read_byte();
CRCC=CRC8_Table(DU,8);
T_low = DU[0];
T_high = DU[1];
tmp = (T_high << 8) | T_low;
temperature = (float)tmp * 0.0625;
intsend((int)(temperature)); DisplayListChar(0,0,"Temp:",5); Display10BitData((int)(temperature*100),5,0,2);
DisplayOneChar(0,0,'.');
temperature=temperature-(int)temperature;
temperature*=100;
Display10BitData((int)(temperature*100),8,0,2);
DisplayOneChar(0,0,'C');
Display10BitData(CRCC*10,7,1,3);
Display10BitData(DU[8]*10,12,1,3);
Delay200ms();
}
}
復制代碼
完整的Word格式文檔51黑下載地址:
溫度測量實驗.docx
(33.63 KB, 下載次數: 19)
2018-11-12 14:14 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1