http://www.ti.com/lit/ds/symlink/lm75a.pdf
https://item.szlcsc.com/8440.html
三根地址全部接了GND



器件地址

寄存器列表



cpp展开代码//P1.2 (TX)  -----> RX (USB<->UART)
//P1.6 (SCL) <----> SCL (LM75, pulled up to Vcc)
//P1.7 (SDA) <----> SDA (LM75, pulled up to Vcc)
//VCC        ------ VS  (LM75)
//GND        ------ GND (LM75)
//[NC]       <----- OS  (LM75)
//GND/VCC    ------ A0  (LM75)
//GND/VCC    ------ A1  (LM75)
//GND/VCC    ------ A2  (LM75)
void timer_interrupt(void) __attribute__((interrupt(TIMER0_A0_VECTOR)));
static volatile uint32_t ticks;
enum
{
    NO_SENSOR = 0, SENSOR = 1
};
int main()
{
    uint32_t start;
    uint8_t i, sensors[8];
    int16_t temp;
    WDTCTL = WDTPW | WDTHOLD; //关闭开门狗
    //初始化时钟
    if (CALBC1_1MHZ == 0xff || CALDCO_1MHZ == 0xff)
    {
        for (;;)
            ;
    }
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
    /*初始化波特率 9600, N, 8, 1 */
    init_uart();
    //打开总中断
    __bis_SR_register(GIE);
    /* 设置IIC工作模式  I2C master mode, 100 kHz, 7 bit slave addresses */
    init_i2c();
    /* LM75A的IIC地址 (bits 2:0): 0x0-0x7 */
    for (i = 0; i < 0x8; ++i)
    {
        if (lm75_power_up(LM75_ADDR | i))
        {
            printf_uart("have    0x%x\r\n", LM75_ADDR | i);
            sensors[i] = SENSOR;
        }
        else
        {
            sensors[i] = NO_SENSOR;
        }
    }
    while (1)
    {
        for (i = 0; i < 0x8; ++i)
        {
            if (sensors[i] == SENSOR)
            {
                temp = lm75_get_temp(LM75_ADDR | i); //获取温度
                printf_uart("传感器地址 0x%x  的温度是", LM75_ADDR | i);
                if (temp != -1)
                {
                    printf_uart("%i.%c C \r\n", temp / 2,
                                (temp % 2) ? '5' : '0');
                }
                else
                {
                    printf_uart("-0.5  C\r\n");
                }
            }
        }
        //等待定时器的数字 延时1s
        start = ticks;
        while ((ticks - start) < 12 * 1)
            ;
    }
}
void timer_interrupt(void)
{
    ++ticks;
}
csharp展开代码https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2


本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!