+发表新主题
taiantzwbl 发布于2007-11-3 23:14 17 次浏览 0 位用户参与讨论
跳转到指定楼层
《数字式温度测控芯片DS1620的应用》
DS1620的几个主要子函数如下:
#include "AT89x51.h"
#include "intrins.h"
////////////////////////////////////////
#define DQ             P1_1
#define CLK_CONV     P1_2     
#define RST            P1_3
////采用11.0592MHz晶体
//////////////////////////////////////
//写字节子程序
void write_byte(unsigned char val)
{
    char i;
    unsigned char b;
    b=1;
    for(i=0;i<8;i++)
    {
        CLK_CONV=0;
        DQ=(val&b);
        CLK_CONV=1;
        b<<=1;
    }
}
//////////////////////////////////////
//读字节子程序
unsigned char read_byte(void)
{
    unsigned char i;
    unsigned char value,b;
    value=0;
    b=1;
    for(i=0;i<8;i++)
    {
        DQ=1;
        CLK_CONV=0;
        if (DQ)
            value|=b;
        CLK_CONV=1;
        b<<=1;
    }
    return(value);
}
//DS1620 开始转换
unsigned char DS1620startConv(void)
{
    RST=1;
    write_byte(0xEE);   
    RST=0;
    return 0x00;
}
//DS1620 读配置 返回值为配置寄存器内容
unsigned char DS1620ReadConf(void)
{
    unsigned char tmp;
    RST=1;
    write_byte(0xAC);
    tmp=read_byte();
    RST=0;
    return tmp;
}
//DS1620 写配置,入回参数为配置寄存器新配置内容
unsigned char DS1620SetConf(unsigned char val)
{
    unsigned char tmp;
    RST=1;
    write_byte(0x0C);
    write_byte(val);
    RST=0;
    return tmp;
}
//DS1620 读温度转换数据,在返回值的低9位
unsigned int DS1620read(void)
{
    unsigned char hbyte,lbyte;
    unsigned int temp;
    RST=1;
    write_byte(0xAA);
    lbyte=read_byte();
    hbyte=read_byte();
    RST=0;
    temp=hbyte;
    temp<<=8;
    temp|=lbyte;
    return temp;
}
回复

使用道具 举报

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

本版积分规则

QQ| Archiver|手机版|小黑屋| 碧波制图网 Stonespider

Copyright © 2021-2023 Kangli Wu   All Rights Reserved.

Powered by Discuz! X3.5( 苏ICP备18011607号-1 )

快速
回复
返回
列表
返回
顶部