#include
#include
#define uchar unsigned char
#define uint unsigned int
#define DQ_IN DDRE &= ~(1 << PE6)
#define DQ_OUT DDRE |= (1 << PE6)
#define DQ_CLR PORTE &= ~(1 << PE6)
#define DQ_SET PORTE |= (1 << PE6)
#define DQ_R PINE & (1 << PE6)
uchar TempData[8];
uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
void Delayms(uint MS)
{
}
void Delayus(uint US)
{
}
void smg_init(void)
{
PORTA=0XFF;
DDRC=0XFF;
PORTC=0XFF;
DDRF|=0X0E;
PORTF|=0X0E;
PORTF&=0xF7;
DDRB |=0X10;
PORTB|=0X10;
}
unsigned char ds1820_reset(void)
{
unsigned char i;
DQ_OUT;
DQ_CLR;
Delayus(500);
DQ_SET;
DQ_IN;
Delayus(100);
i = DQ_R;
Delayus(500);
return i;
}
unsigned char ds1820_read_byte(void)
{
unsigned char i;
unsigned char value = 0;
for (i = 0; i < 8; i++)
{
value >>= 1;
DQ_OUT;
DQ_CLR;
Delayus(10);
DQ_SET;
DQ_IN;
if (DQ_R) value|=0x80;
Delayus(60);
}
return value;
}
void ds1820_write_byte(unsigned char value)
{
unsigned char i;
for (i = 0; i < 8; i++)
{
DQ_OUT;
DQ_CLR;
Delayus(10);
if (value & 0x01) DQ_SET;
Delayus(100);
DQ_SET;
value >>= 1;
}
}
void data_pro(uchar data)
{
}
void display(uchar FirstBit,uchar Num)
{
for(i=0;i
{
PORTC=led_discode[10];
Delayms(2);
}
}
void display1(uchar FirstBit,uchar Num)
{
for(i=0;i
{
PORTC=led_discode[10];
Delayms(2);
}
}
void main(void)
{
uchar i,j;
uint temp;
smg_init();
while (1)
ds1820_reset();
ds1820_write_byte(0xCC);
ds1820_write_byte(0x44);
Delayms(2);
ds1820_reset();
ds1820_write_byte(0xCC);
ds1820_write_byte(0xbe);
i=ds1820_read_byte();
j=ds1820_read_byte();
temp=j*256+i;
temp=temp*0.625;
data_pro(temp);
display(5,3);
display1(6,1);
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/262343.html