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   8  
9 void main() 9 void main()
10 { 10 {
11   11  
12 setup_adc_ports(NO_ANALOGS|VSS_VDD); 12 setup_adc_ports(NO_ANALOGS|VSS_VDD);
13 setup_adc(ADC_CLOCK_DIV_2); 13 setup_adc(ADC_CLOCK_DIV_2);
14 setup_spi(SPI_SS_DISABLED); 14 setup_spi(SPI_SS_DISABLED);
15 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 15 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
16 setup_timer_1(T1_DISABLED); 16 setup_timer_1(T1_DISABLED);
17 setup_timer_2(T2_DISABLED,0,1); 17 setup_timer_2(T2_DISABLED,0,1);
18 setup_ccp1(CCP_OFF); 18 setup_ccp1(CCP_OFF);
19 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 19 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
20   20  
21 printf("Simple Thermomether \r\n",); 21 printf("Simple Thermomether \r\n",);
-   22 printf("(c) MLAB 2013 JACHO \r\n",);
22   23  
23 signed int8 MSB; 24 signed int8 MSB;
24 byte LSB; 25 byte LSB;
25 float t; 26 float t;
26 27
27 while(TRUE) 28 while(TRUE)
28 { 29 {
29 30
30   31  
31   32  
32 i2c_start(); 33 i2c_start();
33 I2C_Write(0x9E); 34 I2C_Write(0x9E);
34 I2C_write(0x00); 35 I2C_write(0x00);
35 i2c_stop(); 36 i2c_stop();
36 i2c_start(); 37 i2c_start();
37 I2C_Write(0x9F); 38 I2C_Write(0x9F);
38 MSB=i2c_read(1); 39 MSB=i2c_read(1);
39 LSB=i2c_read(0); 40 LSB=i2c_read(0);
40 i2c_stop(); 41 i2c_stop();
41 42
42 t = (float)(LSB)/256.0; 43 t = (float)(LSB)/256.0;
43 t = (float)(MSB+t); 44 t = (float)(MSB+t);
44   45  
45 printf("Teplota: %f (C)\r\n", t); 46 printf("Teplota: %f (C)\r\n", t);
46 delay_ms(500); 47 delay_ms(500);
47 } 48 }
48 } 49 }
49   50