• 博客(0)
  • 资源 (1)

空空如也

SHT11温湿度Proteus仿真

基于Proteus的温湿度仿真系统. char read() //读一个字节 返回应答信号 //---------------------------------------------------------------------------------- // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1" { unsigned char i,val=0; temp_LL=0; temp_h=0; DATA=1; //释放数据总线 for (i=0x80;i>0;i/=2) //位移8位 { SCK=1; //上升沿读入 if (DATA) val=(val | i); //确定值 SCK=0; } DATA=0; //读应答信号,有应答为1,为应答为0 通过CPU下拉为应答 SCK=1; //第9个脉冲 _nop_(); _nop_(); _nop_(); //pulswith approx. 5 us SCK=0; DATA=1; //释放数据总线 temp_h=val; val=0; ////低8位///////////////////////////// DATA=1; //释放数据总线 for (i=0x80;i>0;i/=2) //位移8位 { SCK=1; //上升沿读入 if (DATA) val=(val | i); //确定值 SCK=0; } DATA=1;//0; //不需要应答 通过CPU下拉为应答 SCK=1; //第9个脉冲 _nop_(); _nop_(); _nop_(); //pulswith approx. 5 us SCK=0; DATA=1; //释放数据总线 temp_LL=val; } //////////// char write(unsigned char value) //写一个字节 返回应答信号 //--------------------------------------------------------- { unsigned char i ; ack=0; for (i=0x80;i>0;i/=2) //释放数据总线 { if (i & value) DATA=1; //写入值 else DATA=0; SCK=1; //上升沿写入 _nop_(); _nop_(); _nop_(); //延时 SCK=0; } DATA=1; //释放数据总线 SCK=1; //第9个脉冲 if (DATA==1) ack=1; //读应答信号 SCK=0; return ack; //error=1 表示没有应答 } //////// void start_sht11(void) //启动 //-------------------------------------------------------- { DATA=1; SCK=0; //数据为1,SCK=0 _nop_(); SCK=1; //第一个脉冲 _nop_(); DATA=0; //数据跌落 _nop_ (); SCK=0; //完成一个脉冲 _nop_(); _nop_(); _nop_(); SCK=1; //再一个脉冲 _nop_(); DATA=1; //数据变为1 _nop_(); SCK=0; //完成该脉冲 } ////////////////////////////////// void sht_rest(void) //复位 { unsigned char i; DATA=1; SCK=0; //数据为1 时钟为0 for(i=0;i<9;i++) //9 个脉冲为 复位 { SCK=1; SCK=0; } start_sht11(); //启动 }

2013-04-16

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除