#include <c8051f000.h> // SFR declarations
#include <stdio.h>
#include <Intrins.h>
#include <math.h>
#include <stdlib.h>
#include "string.h"
enum {TEMP,HUMI};
#define noACK 0
#define ACK 1
unsigned char error=0;
sbit DATA= P1^6;
sbit SCK = P1^7;
typedef union
{ unsigned int i;
float f;
} value;
float rh_true; // rh_true: Temperature compensated humidity
float t_C; // Temperature_C : Temperature [C]
float Result[2];
float temperature_C,humidity_RH;
//-----------------
//adr command r/w
#define STATUS_REG_W 0x06 //000 0011 0
#define STATUS_REG_R 0x07 //000 0011 1
#define MEASURE_TEMP 0x03 //000 0001 1
#define MEASURE_HUMI 0x05 //000 0010 1
#define RESET 0x1e //000 1111 0
void dmsec (unsigned int count) {
unsigned int i;
while (count--) {
for (i=0;i<125;i++){}
}
}
void OSCILLATOR_Init (void)
{
int i; // Delay counter
OSCXCN = 0x67; // Start external oscillator with
// 22.1184 MHz crystal
for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // Select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
void Port_IO_Init()
{