Справочник Пользователя для Microchip Technology DM164130-5

Скачать
Страница из 44
F1 LV Evaluation Platform User’s Guide
DS41614A-page 34
 2011 Microchip Technology Inc.
FIGURE 5-14:
5.8.1.4
time
The standard C libraries require the application to supply the time function. This 
function returns the current time_t value or loads a supplied time_t value. The 
interrupts are saved and restored to make this function safe for use with interrupt driven 
code.
5.9
USING THE MCP9800 DRIVER
The MCP9800 is an I
2
C temperature sensor. The MCP9800 driver provides a simple 
interface to the features in the sensor.
5.9.1
MCP9800 Function Interface
5.9.1.1
mcp9800_init
This function configures the MCP9800 for 12-bit temperature, Continuous Conversion 
mode. In this mode, the temperature is always ready to be read from the I
2
C interface.
FIGURE 5-15:
5.9.1.2
 mcp9800_get_temp
This function reads the current temperature and scales the result to degrees C * 10. 
(24.3C is returned 243)
FIGURE 5-16:
#include <time.h>
Time_set() // set the time & date to 1 second after midnight, July 4, 2009
{
  struct tm time_str;
  time_t unix_time;
  time_str.tm_year = 2009; // the year
  time_str.tm_mon = 7;   // the month
  time_str.tm_mday = 4;  // the day of the month
  time_str.tm_hour = 0;  // the hour (0-23)
  time_str.tm_min = 0;   // the minutes
  time_str.tm_sec = 1;   // the seconds
  time_str.tm_isdst = -1; // daylight savings time modifier
  unix_time = mktime(&time_str);
  rtcc_set(unix_time);
}
System_init()
{
 i2c_init();
 mcp9800_init();
}
Thermostat()
{
 int temperature;
 temperature = mcp9800_get_temp();
 if(temperature > 260)
 {
 turn_on_air_conditioner();
 }
}