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

熱點內容
計算器程序員是幹嘛的 瀏覽:362
數控編程里fo是啥鍵 瀏覽:655
javacdataxml 瀏覽:943
本機tcp伺服器地址 瀏覽:426
切換pdf 瀏覽:92
iturns下載的app在哪裡 瀏覽:640
雲起書院App在哪裡 瀏覽:615
怎麼對hex文件進行加密 瀏覽:285
pdf少年時 瀏覽:953
兩個同名文件夾同步 瀏覽:630
拍照文件夾哪個好用 瀏覽:91
文件夾和書包 瀏覽:511
解壓歸檔拿登記證 瀏覽:225
去體驗解壓房 瀏覽:613
單片機一鍵中斷響應 瀏覽:646
唐浩明pdf 瀏覽:845
程序員土木 瀏覽:73
android如何與web伺服器交互 瀏覽:611
蘋果小風扇app怎麼下 瀏覽:958
杭州it程序員對身體好不好 瀏覽:537