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