导航:首页 > 操作系统 > 单片机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相关的资料

热点内容
在菜鸟裹裹里面怎么取消加密包裹 浏览:784
程序员挣钱的五种方法 浏览:540
七日杀服务器进不去怎么回事 浏览:673
qq游戏迷你世界解压失败怎么办 浏览:766
颜色匹配算法 浏览:259
培训机构学生出勤率算法 浏览:568
波特率算法 浏览:804
单片机为什么要引入补码 浏览:204
javascript权威编程指南 浏览:340
pdf机长 浏览:384
五十音图pdf 浏览:865
什么叫下架服务器 浏览:111
pdf分辨率查看 浏览:15
如何将word转pdf 浏览:186
我的世界ec服务器怎么调配置 浏览:259
单片机换标 浏览:595
语音系统和方舟编译器哪个好 浏览:316
html用什么编译器显示 浏览:185
程序员打印系统 浏览:73
安装系统端口和服务器地址怎么看 浏览:263