導航:首頁 > 操作系統 > 單片機162

單片機162

發布時間:2024-08-04 13:48:51

單片機初始化的一般步驟

一般分四個步驟:
1)將相應的引腳配羨答吵置成UART模式
2)配置和使能UART,包括配置波特率,是否使用FIF0,數據幀格式(數據長度,停止位,奇偶校驗,收發數據緩沖區大小等)
3)配置舉梁中斷兄侍(一般分3大類,共7種)
4)讀寫數據

㈡ 51單片機系列溫度採集LCD162顯示溫度系統C程序

這是我自己用過的DS18B20的程序,有什麼問題可以網路HI我,我這個是把溫度顯示到電腦上了,如果你要顯示到LCD上的話可以在裡面加一些子程序。
#include<reg52.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
sbit ds=P1^0;
bit flag;
uchar count_t0;
float f_temp;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=122;y>0;y--);
}
void init() // 串口初始化
{
TMOD=0x21;
SCON=0x50;
TH0=0x4c;
TL0=0x00;
TH1=0xf3;
TL1=0xf3;
EA=1;
ET0=1;
TR0=1;
TR1=1;
}
void timer0() interrupt 1
{
TH0=0x4c;
TL0=0x00;
if(++count_t0>=20)
{
count_t0=0;
flag=1;
}
}
void dsreset()
{
uint i;
ds=0;
i=103;
while(i>0)
i--;
ds=1;
i=4;
while(i>0)
i--;
}
bit read_bit()
{
uint i;
bit dat;
ds=0;i++;
ds=1;i++;i++;
dat=ds;
i=8;
while(i>0)
i--;
return dat;
}
uchar read_byte()
{
uchar i,j,dat;
dat=0;
for(i=1;i<=8;i++)
{
j=read_bit();
dat=(j<<7)|(dat>>1);
}
return dat;
}
void write_byte(uchar dat)
{
uint i;
uchar j;
bit testb;
for(j=1;j<=8;j++)
{
testb=dat&0x01;
dat=dat>>1;
if(testb)
{
ds=0;
i++;i++;
ds=1;
i=8;
while(i>0)
i--;
}
else
{
ds=0;
i=8;
while(i>0)
i--;
ds=1;
i++;i++;
}
}
}
void begin_change()
{
dsreset();
delay(1);
write_byte(0xcc);
write_byte(0x44);
}
float get_temp()
{
uchar a,b;
uint temp;
float f_temp;
dsreset();
delay(1);
write_byte(0xcc);
write_byte(0xbe);
a=read_byte();
b=read_byte();
temp=b;
temp<<=8;
temp=temp|a;
f_temp=temp*0.0625;
temp=f_temp*10+0.5;
f_temp=f_temp+0.05;
return f_temp;
}
void main()
{
init();
while(1)
{
if(flag==1)
{
flag=0;
begin_change();
TI=1;
printf("The tempeature is %f\n",get_temp());
while(!TI);
TI=0;
}
}
}

㈢ atmega162鍗曠墖鏈烘庝箞涓嬭澆紼嬪簭錛屾渶灝忕郴緇熺數璺錛燂紵榪樻湁杞浠

鍙闇瑕6涓鑴氬氨鍙浠ヤ笅杞界▼搴忎簡錛屽嵆VCC ,GND,MOSI ,MISO,SCK錛孯ST錛屽叡6涓寮曡剼鍗沖彲銆傞噰鐢ㄥ苟鍙f垨鑰匲SB鍙i兘鍙浠ヤ笅杞斤紝鐪嬩綘鐨勪笅杞藉櫒鑰屽凡瀹氬摝銆

閱讀全文

與單片機162相關的資料

熱點內容
程序員被拜金女騙1萬 瀏覽:982
安卓手機拍照為什麼總是抖動 瀏覽:250
汽車車載app如何下載 瀏覽:24
python復合型數據類型 瀏覽:375
登錄伺服器發生錯誤怎麼回事 瀏覽:272
松下空氣能壓縮機 瀏覽:938
萬能源碼播放器 瀏覽:968
串口伺服器如何轉發 瀏覽:359
如何下載Ck電影部app 瀏覽:744
解壓文具筆袋簡單 瀏覽:288
android百度坐標轉換 瀏覽:367
文件公私鑰加密傳輸 瀏覽:665
python矩陣維度 瀏覽:927
華佗舌診源碼 瀏覽:898
解壓壓縮包有一個錯誤怎麼辦 瀏覽:966
怎麼在手機上設立文件夾 瀏覽:232
雲幫手伺服器搭建教程 瀏覽:785
惠普默認存在哪個文件夾 瀏覽:493
建立桌面圖標文件夾 瀏覽:86
python怎麼跳過異常繼續執行 瀏覽:315