📄 ds1920.c
字号:
/**********************************************
* File: DS1620.C
* Description: Tri-Angle
* Created Date: 2007-10-01
* Last Modified: 2007-10-01
* Author: Jeffrey - Schicksal@126.com
* Notes: None
**********************************************/
//#include "Atmel/AT89X51.h"
#include "SST/SST89x5x4.H"
#include "INTRINS.H"
#include "DS1620.h"
/**********************************************
* Function: WR_byte(unsigned char val)
* Input Variables: unsigned char val
* Return Variables: None
* Usage: Write Byte to DS1920
**********************************************/
void WR_byte(unsigned char val)
{
char i; // 临时变量
unsigned char b; // 移位变量
b=1; // 赋初值
for(i=0;i<8;i++) // 循环发送
{
CLK_CONV=0; // CLK_CONV 低
DQ=(val&b); // 输出数据
CLK_CONV=1; // CLK_CONV 高
b<<=1; // 移位
}
}
/**********************************************
* Function: RD_byte(void)
* Input Variables: void
* Return Variables: unsigned char
* Usage:Read a Byte from DS1920
**********************************************/
unsigned char RD_byte(void)
{
unsigned char i; // 临时变量
unsigned char b; // 移位变量
unsigned char value; // 返回变量值
value=0; // 赋初值
b=1; // 赋初值
for(i=0;i<8;i++)
{
DQ=1; // 置高,准备读取
CLK_CONV=0; // CLK_CONV 低
if (DQ) // 读取
value|=b; // 读取一位
CLK_CONV=1; // CLK_CONV 高
b<<=1; // 移位
}
return(value); // 返回读取值
}
/**********************************************
* Function: unsigned char DS1620startConv(void)
* Input Variables: void
* Return Variables: unsigned char
* Usage:start conversion
**********************************************/
unsigned char DS1620startConv(void)
{
RST=1; // RST 高
WR_byte(0xEE); // 写命令字
RST=0; // RST低
return 0x00; // 返回值
}
/**********************************************
* Function:DS1620ReadConf(void)
* Input Variables:
* Return Variables: unsigned char
* Usage:Read Config Register of DS1620
**********************************************/
unsigned char DS1620ReadConf(void)
{
unsigned char tmp; // 返回值临时变量
RST=1; // RST高
WR_byte(0xAC); // 写命令字
tmp=RD_byte(); // 读控制寄存器值
RST=0; // RST低
return tmp; // 返回值
}
/**********************************************
* Function: DS1620SetConf(unsigned char val)
* Input Variables: unsigned char va
* Return Variables: unsigned char
* Usage:Setting Config Register of DS1620
**********************************************/
unsigned char DS1620SetConf(unsigned char val)
{
RST=1; // RST高
WR_byte(0x0C); // 写命令字
WR_byte(val); // 写控制寄存器参数
RST=0; // RST低
return 1;
}
/**********************************************
* Function: unsigned int DS1620read(void)
* Input Variables: void
* Return Variables: unsigned int
* Usage:Read temp of DS1620
**********************************************/
unsigned int DS1620read(void)
{
unsigned char hbyte,lbyte; // 温度值高低字节
unsigned int temp; // 临时变量
RST=1; // RST高
WR_byte(0xAA); // 写命令字
lbyte=RD_byte(); // 读取温度低字节
hbyte=RD_byte(); // 读取温度高字节
RST=0; // RST低
temp=hbyte; // 合成温度值
temp<<=8;
temp|=lbyte;
return temp; // 返回值
}
/**********************************************
* Function: void InitDS1620(void)
* Input Variables: void
* Return Variables: void
* Usage:InitDS1620
**********************************************/
void InitDS1620(void)
{
DS1620SetConf(0x8A); // 设置初始化值为0x8A
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -