#include "C:\Users\Honza\Documents\pic\I2C_magnetometr\main.h"
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
printf("Simple Thermomether \r\n",);
unsigned int8 INTEP,INTEP1, NAP,NAP1, PROUD,PROUD1,KAPZ,KAPZ1,KAPC,KAPC1, STAV,STAV1;
int16 data4;
int16 data5;
int16 data6;
int16 data7;
int16 data8;
int16 data9;
while(TRUE)
{
i2c_start();
I2C_Write(0xAA);
I2C_write(0x0c);
i2c_start();
I2C_Write(0xAB);
INTEP=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x0d);
i2c_start();
I2C_Write(0xAB);
INTEP1=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x08);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
NAP=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x09);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
NAP1=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x0a);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
PROUD=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x0b);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
PROUD1=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x04);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
KAPZ=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x05);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
KAPZ1=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x06);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
KAPC=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x07);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
KAPC1=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x02);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
STAV=i2c_read(0);
i2c_stop();
i2c_start();
I2C_Write(0xAA);
I2C_write(0x03);
i2c_stop();
i2c_start();
I2C_Write(0xAB);
STAV1=i2c_read(0);
i2c_stop();
data4 = (((unsigned int16) INTEP1 << 8) + INTEP );
data4 = (data4/10)-273;
data5 = (((unsigned int16) NAP1 << 8) + NAP );
data6 = (((unsigned int16) PROUD1 << 8) + PROUD );
data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ );
data8 = (((unsigned int16) KAPC1 << 8) + KAPC );
data9 = (((unsigned int16) STAV1 << 8) + STAV );
printf("Teplota uvnitr io: %Ld C\r\n", data4);
printf("Napeti clanku: %Ld mV \r\n", data5);
printf("Proud: %Ld mA \r\n", data6);
printf("Kapacita zbytek: %Ld mAh\r\n", data7);
printf("Kapacita max: %Ld mAh\r\n", data8);
printf("Stav: %Ld (procenta)\r\n", data9);
delay_ms (2000);
}
}