Rev Author Line No. Line
2962 jacho 1 //Akcelerometr IMU01A
2 //(c) MLAB Jan Chroust 2013
3  
4  
5 #include <main.h>
6  
7 #define PIN_SDA PIN_C4
8 #define PIN_SCL PIN_C3
9 #use i2c(master, sda=PIN_SDA, scl=PIN_SCL) //I2C
10 #use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
11 #include <math.h>
12 #include <MMA8451Q.h>
13  
14  
15 //Akcelerometr
16 #define AK_W 0x38 //adresa akcelerometru zápis
17 #define AK_R 0x39 //adresa akcelerometru ètení
18 #define AK_XH 0x01 //osa X LSB
19 #define AK_XL 0x02 //osa X MSB
20 #define AK_YH 0x03 //osa Y LSB
21 #define AK_YL 0x04 //osa Y MSB
22 #define AK_ZH 0x05 //osa Z LSB
23 #define AK_ZL 0x06 //osa Z MSB
24  
25 signed int16 X, Y, Z; //promenne pro akcelerometr
26  
27 void main()
28 {
29 setup_adc_ports(NO_ANALOGS|VSS_VDD);
30 setup_adc(ADC_CLOCK_DIV_2);
31 setup_spi(SPI_SS_DISABLED);
32 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
33 setup_timer_1(T1_DISABLED);
34 setup_timer_2(T2_DISABLED,0,1);
35 setup_ccp1(CCP_OFF);
36 setup_comparator(NC_NC_NC_NC);
37  
38 setAK(); //nastaveni akcelerometru
39  
40 printf("Akcelerometr IMU01A - MMA8451Q \r\n",);
41 printf("(c) MLAB JACHO 2013 \r\n",);
42  
43 while(TRUE)
44 {
45 X=akX ();
46 Y=akY ();
47 Z=akZ ();
48 printf("Namerene hodnoty: \r\n",);
49 printf("Osa X: %Ld \r\n",X);
50 printf("Osa Y: %Ld \r\n",Y);
51 printf("Osa Z: %Ld \r\n",Z);
52 delay_ms (2000);
53  
54 }
55 }
56