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