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