導航:首頁 > 操作系統 > 單片機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相關的資料

熱點內容
解壓機壓什麼不爛 瀏覽:361
大牛盒子插件文件夾 瀏覽:5
用友t3如何遠程連接伺服器 瀏覽:734
保時捷行車記錄儀需要什麼app 瀏覽:708
文件伺服器中的DFS全名是什麼 瀏覽:453
365小說app現在叫什麼 瀏覽:46
海貝音樂app的獨佔usb輸出是什麼 瀏覽:395
宏觀經濟學高鴻業pdf 瀏覽:288
我的榮耀9x有方舟編譯器嗎 瀏覽:967
linux父子進程通信 瀏覽:882
程序員為什麼總是用手機 瀏覽:302
安卓9程序怎麼用 瀏覽:841
如何恢復編譯 瀏覽:846
mybatispdf 瀏覽:876
plc使用的是單片機嗎 瀏覽:811
如何讓安卓平板音量上限 瀏覽:235
代理伺服器請求超時如何設置 瀏覽:114
pdf批量蓋章 瀏覽:778
珠江寬頻網關伺服器地址 瀏覽:710
程序員練打字網站 瀏覽:575