Rev 3095 Rev 3180
1 #include "D:\Honza\MLAB\Modules\Sensors\LTS01A\SW\PIC16F887\main.h" 1 #include "D:\Honza\MLAB\Modules\Sensors\LTS01A\SW\PIC16F887\main.h"
2   2  
3 #define S_SDA PIN_C3 3 #define S_SDA PIN_C3
4 #define S_SCL PIN_C4 4 #define S_SCL PIN_C4
5 #use i2c(master, sda=S_SDA, scl=S_SCL) 5 #use i2c(master, sda=S_SDA, scl=S_SCL)
6 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD 6 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
7   7  
-   8 //Adresa pro VDD, VDD, VDD W 0x9E R 0x9F
-   9 //Adresa pro GND GND GND W 0x90 R 0x91
8   10  
9 void main() 11 void main()
10 { 12 {
11   13  
12 setup_adc_ports(NO_ANALOGS|VSS_VDD); 14 setup_adc_ports(NO_ANALOGS|VSS_VDD);
13 setup_adc(ADC_CLOCK_DIV_2); 15 setup_adc(ADC_CLOCK_DIV_2);
14 setup_spi(SPI_SS_DISABLED); 16 setup_spi(SPI_SS_DISABLED);
15 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 17 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
16 setup_timer_1(T1_DISABLED); 18 setup_timer_1(T1_DISABLED);
17 setup_timer_2(T2_DISABLED,0,1); 19 setup_timer_2(T2_DISABLED,0,1);
18 setup_ccp1(CCP_OFF); 20 setup_ccp1(CCP_OFF);
19 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 21 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
20   22  
21 printf("Simple Thermomether \r\n",); 23 printf("Simple Thermomether \r\n",);
22 printf("(c) MLAB 2013 JACHO \r\n",); 24 printf("(c) MLAB 2013 JACHO \r\n",);
23   25  
24 signed int8 MSB; 26 signed int8 MSB;
25 byte LSB; 27 byte LSB;
26 float t; 28 float t;
27 29
28 while(TRUE) 30 while(TRUE)
29 { 31 {
30 32
31   33  
32   34  
33 i2c_start(); 35 i2c_start();
34 I2C_Write(0x9E); 36 I2C_Write(0x90);
35 I2C_write(0x00); 37 I2C_write(0x00);
36 i2c_stop(); 38 i2c_stop();
37 i2c_start(); 39 i2c_start();
38 I2C_Write(0x9F); 40 I2C_Write(0x91);
39 MSB=i2c_read(1); 41 MSB=i2c_read(1);
40 LSB=i2c_read(0); 42 LSB=i2c_read(0);
41 i2c_stop(); 43 i2c_stop();
42 44
43 t = (float)(LSB)/256.0; 45 t = (float)(LSB)/256.0;
44 t = (float)(MSB+t); 46 t = (float)(MSB+t);
45   47  
46 printf("Teplota: %f (C)\r\n", t); 48 printf("Teplota: %f (C)\r\n", t);
47 delay_ms(500); 49 delay_ms(500);
48 } 50 }
49 } 51 }
50   52