#define uchar unsigned char
#define uint unsigned int
sbit SCL=P3^1
sbit SDA=P3^2
void delay(uint i)
{
uchar j
while(i--)
for(j=0j<100j++)
}
void write_add(uchar r)//r=1 读否则写
{
uchar i
uchar add_rw
if(r)
add_rw=0x91 //读
else
add_rw=0x90 //写蚂码
SCL=1 //START
SDA=1
SDA=0
SCL=0
for(i=0i<8i++) //ADDRESS
{
if(add_rw&0x80)
SDA=1
else SDA=0
SCL=1
SCL=0
add_rw=add_rw<<1
}
SDA=1
SCL=1
while(SDA) //等待应答
SCL=0
}
void write_data(uchar d)
{
uchar i
SCL=0
for(i=0i<8i++) //DATA
{
if(d&0x80)
SDA=1
else SDA=0
SCL=1
SCL=0
d=d<<1
}
SDA=1
SCL=1
while(SDA) //等待应答
SCL=0
}
void stop(void)
{
SCL=1
SDA=1
}
uchar read_data(uchar over)
{
uchar i,d
SCL=0
for(i=0i<8i++) //DATA
{
d=d<<1
SCL=1
if(SDA)
d=d|0x01
SCL=0
}
if(over) SDA=1
else SDA=0
SCL=1 //应答
SCL=0
SDA=0
return d
}
void write_cmd(uchar d)
{
uchar i,w_add=0x90
SCL=1 //START
SDA=1
SDA=0
SCL=0
for(i=0i<8i++) //ADDRESS
{
if(w_add&0x80)
SDA=1
else SDA=0
SCL=1
SCL=0
w_add=w_add<<1
}
SDA=1
SCL=1
while(SDA) //等待应答
SCL=0
SDA=0
for(i=0i<8i++) //DATA
{
if(d&0x80)
SDA=1
else SDA=0
SCL=1
SCL=0
d=d<<1
}
SDA=1
SCL=1
while(SDA) //等待樱物配应答
SCL=0
SDA=0
SCL=1
SDA=1
}
uchar read_tmp(void)
{
uchar h,l
write_add(0)
write_data(0xee)//转换
stop()
delay(1000)
write_add(0)
write_data(0xaa)//读温度脊指
stop()
write_add(1)
h=read_data(0)
l=read_data(1)
stop()
return(h)
}
void main(void)
{
while(1)
P0=read_tmp()
}
#include"歼数雀reg52.h"#define u8 unsigned char
#define u16 unsigned int
sbit fengming_out=P0^0
main()
{
sp=0x5f
T6963_initialize()
eeprom_main()
key_init()
key_in()
while(1)
{
display
}
}
上面那部分氏早太乱了,不好看毕竖
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)