(单片机89c52)为什么这个用18b20测温度的程序中有用到串口中断语句

[复制链接]
查看11 | 回复4 | 2010-8-1 21:35:51 | 显示全部楼层 |阅读模式
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
unsigned char j,k;
unsigned char a,b;
sbit DS=P2^2;
//define interface
uint temp;
// variable of temperature
uchar flag1;
// sign of the result positive or negative
sbit beep=P2^3;
void display1(unsigned char);
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
//数码管编码

0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,

0x87,0xff,0xef};
void delay1(uint count)
//delay
{
uint i;
while(count)
{

i=200;

while(i>0)

i--;

count--;
}
}
///////功能:串口初始化,波特率9600,方式1///////
void Init_Com(void)
{

TMOD = 0x20;

PCON = 0x00;

SCON = 0x50;

TH1 = 0xFd;

TL1 = 0xFd;

TR1 = 1;
}
void dsreset(void)
//send reset and initialization command
{
uint i;
DS=0;
i=103;
while(i>0)i--;
DS=1;
i=4;
while(i>0)i--;
}
bit tmpreadbit(void)
//read a bit
{
uint i;
bit dat;
DS=0;i++;
//i++ for delay
DS=1;i++;i++;
dat=DS;
i=8;while(i>0)i--;
return (dat);
}
uchar tmpread(void) //read a byte date
{
uchar i,j,dat;
dat=0;
for(i=1;i>1); //读出的数据最低位在最前面,这样刚好一个字节在DAT里
}
return(dat);
}
void tmpwritebyte(uchar dat) //write a byte to ds18b20
{
uint i;
uchar j;
bit testb;
for(j=1;j>1;

if(testb)
//write 1

{

DS=0;

i++;i++;

DS=1;

i=8;while(i>0)i--;

}

else

{

DS=0;
//write 0

i=8;while(i>0)i--;

DS=1;

i++;i++;

}
}
}
void tmpchange(void)//DS18B20 begin change
{
dsreset();
delay1(1);
tmpwritebyte(0xcc);// address all drivers on bus
tmpwritebyte(0x44);//initiates a single temperature conversion
}
uint tmp()
//get the temperature
{
float tt;
uchar a,b;
dsreset();
delay1(1);
tmpwritebyte(0xcc);
tmpwritebyte(0xbe);
a=tmpread();
b=tmpread();
temp=b;
temp0;a--)

{ display2(tmp());

}
}
只是通过P2^2口进行读取哦,那该怎么理解?
串口初始化如何让理解,波特率起到什么作用?
主程序是 void main()

{while(1)

wendu();

}

回复

使用道具 举报

千问 | 2010-8-1 21:35:51 | 显示全部楼层
那里用到了串口中断?程序里面虽然有“串口初始化”,但是并没有用。 ----------------这程序,是不完整的。程序中,虽然有“七段码表”,也没有用上,也没有把温度数据显示出来。整个程序,都是子程序,缺少主程序main()。
回复

使用道具 举报

千问 | 2010-8-1 21:35:51 | 显示全部楼层
传给别的机器处理数据吧。
回复

使用道具 举报

千问 | 2010-8-1 21:35:51 | 显示全部楼层
单纯读温度的话串口是没用的,有可能是和上位机通讯。
回复

使用道具 举报

千问 | 2010-8-1 21:35:51 | 显示全部楼层
没有读你的 程序,但是编过类似的 ,不写串口中断的话 ,怎么从温度芯片里面读到数据呢??温度芯片提供中断不假,但单片机不去理睬,那温度芯片的数据不就浪费了吗》???
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行