Rev Author Line No. Line
2763 kaklik 1 #include <16f887.h>
2 #fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
3 #use delay(clock = 20000000)
4 #use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7)
5  
6 #define CSN_SPI PIN_C2
7 int8 address, uiTadc, data ;
8  
9  
10 // SPI mode definitions.
11 #define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
12 #define SPI_MODE_1 (SPI_L_TO_H)
13 #define SPI_MODE_2 (SPI_H_TO_L)
14 #define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
15  
16  
17 void main()
18 {
19 printf("Start\n\r");
20  
21 setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
22  
23 output_high(CSN_SPI);
24  
25 delay_ms(100);
26  
27 while(true)
28 {
29 data = 5; //just to be sure that the value is updated
30  
31 //Start temperature and pressure conversion
32 address = 0x24;
33 address &= 0x7F;
34  
35 output_low(CSN_SPI);
36 delay_ms(1);
37 spi_write(address);
38 delay_ms(1);
39 spi_write(0x00);
40 delay_ms(1);
41 output_high(CSN_SPI);
42 delay_ms(2);
43  
44  
45 // get MSB for Pressure
46 address = 0x00;
47 address |= 0x80;
48  
49 output_low(CSN_SPI);
50 delay_ms(1);
51 spi_write(address);
52 delay_ms(1);
53 data = spi_read(0x00);
54 delay_ms(1);
55 output_high(CSN_SPI);
56  
57 printf("%u\n\r", data);
58  
59 //uiTadc = (unsigned int) data << 8;
60 //printf("%u\n\r", uiTadc);
61  
62  
63 delay_ms(100);
64 }
65  
66 }