Здравствуйте. Много тем встретил на форуме про датчик и работу с ним, но чтото никак не могу разобраться с выводом температуры на LCD.
в CV есть готовые библиотеки для этого датчика, так что остановился на этой программе.
Моделирую работу в Proteus 7.1 sp2
код
#include <mega32.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x15 ;PORTC
.equ __sda_bit=1
.equ __scl_bit=0
#endasm
#include <i2c.h>
// DS1621 Thermometer/Thermostat functions
#include <ds1621.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <stdio.h>
#include <math.h>
// Declare your global variables here
char display_buffer[33];
void main(void)
{
// Declare your local variables here
int t0;
// I2C Bus initialization
i2c_init();
// DS1621 Thermometer/Thermostat initialization
// tlow: 10°C
// thigh: 20°C
// Tout polarity: 1
ds1621_init(0,10,20,1);
// LCD module initialization
lcd_init(16);
while (1)
{
t0=ds1621_temperature_10(0);
// Place your code here
sprintf(display_buffer,"t0=%-i.%-u%cC",
t0/10,abs(t0%10),0xdf);
/* display the temperatures */
lcd_clear();
lcd_puts(display_buffer);
};
Нажмите для просмотра прикрепленного файла