Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\I2C_vlhkost\main.h"
2  
3 #define EEPROM_SDA PIN_B0
4 #define EEPROM_SCL PIN_B1
5 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
6 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
7  
8  
9 void main()
10 {
11  
12 setup_adc_ports(NO_ANALOGS|VSS_VDD);
13 setup_adc(ADC_CLOCK_DIV_2);
14 setup_spi(SPI_SS_DISABLED);
15 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
16 setup_timer_1(T1_DISABLED);
17 setup_timer_2(T2_DISABLED,0,1);
18 setup_ccp1(CCP_OFF);
19 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
20  
21 printf("Simple Thermomether \r\n",);
22  
23 int16 data1, data2, data3;
24  
25 int XL,XH,YL,YH,ZL,ZH;
26  
27 while(TRUE)
28 {
29  
30 data1=0;
31 data2=0 ;
32  
33  
34 //akcelerometr
35 int1 ack;
36 i2c_start(); // If the write command is acknowledged,
37 ack = i2c_write(0x81);//hen the device is ready.
38 i2c_stop();
39 ack=!ack;
40  
41  
42  
43 i2c_stop(); //T
44  
45 i2c_start();
46 I2C_Write(0x80);
47 I2C_write(0xF3);
48 // i2c_stop();
49 i2c_start();
50 I2C_Write(0x81);
51 XH=i2c_read(0);
52 XL=i2c_read(0);
53 i2c_stop();
54  
55  
56 i2c_start(); //RH
57 I2C_Write(0x80);
58 I2C_write(0xF5);
59 // i2c_stop();
60 i2c_start();
61 I2C_Write(0x81);
62 YH=i2c_read(0);
63 YL=i2c_read(0);
64 i2c_stop();
65  
66  
67  
68 data1 = (((unsigned int16) XH << 8) + XL>>2 );
69 data2 = (((unsigned int16) YH << 8) + YL>>2);
70  
71  
72 printf("Stav: %d (procenta)\r\n", ack);
73  
74 printf("Stav: %Ld(procenta)\r\n", data1);
75 printf("Stav: %Ld(procenta)\r\n", data2);
76  
77 delay_ms (2000);
78  
79 }
80 }
81