Rev Author Line No. Line
1744 kakl 1 #include "main.h"
2  
1757 kakl 3 #define VERSION 0.1
4  
1759 kakl 5 #define START PIN_D4
6 #define STOP1 PIN_D5
7 #define STOP2 PIN_D6
1774 kaklik 8 #include "GP2.h"
1759 kakl 9  
1774 kaklik 10 #define ONE_WIRE_PIN PIN_E2
11 #include "ds1820.c"
12  
1744 kakl 13 void main()
14 {
1774 kaklik 15 float temperature;
16  
1744 kakl 17 setup_adc_ports(NO_ANALOGS|VSS_VDD);
18 setup_adc(ADC_CLOCK_DIV_2);
19 setup_psp(PSP_DISABLED);
20 setup_spi(SPI_SS_DISABLED);
21 setup_wdt(WDT_OFF);
22 setup_timer_0(RTCC_INTERNAL);
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);
27 setup_vref(FALSE);
28  
1745 kakl 29 TDC_reset();
1744 kakl 30  
1817 kaklik 31 MRange=TDC_MRANGE2;
1798 kaklik 32 hitin1=TDC_HITIN1_1;
33 hitin2=TDC_HITIN2_0;
1817 kaklik 34 hit1=TDC_MRANGE2_HIT1_START;
35 hit2=TDC_MRANGE2_HIT2_1CH1;
36 en_int=(TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT);
1759 kakl 37 en_err_val=TDC_ERRVAL_EN;
38 delval1=0x0;
39 delval2=0x0;
40 delval3=0x0;
1798 kaklik 41 calibrate=TDC_CALIBRATE_DIS;
1775 kaklik 42 disautocal=TDC_AUTOCAL_EN;
43  
1818 kaklik 44 firenum=TDC_FIRENUM_1;
1798 kaklik 45 div_fire=TDC_DIV_FIRE_2;
46  
47 Tcycle=TDC_TCYSLE_LONG;
48 portnum=TDC_TPORTNUM_2;
49 fakenum=TDC_TFAKENUM_2;
1758 kakl 50  
51 TDC_update_registers();
1817 kaklik 52  
1759 kakl 53 output_low(START);
54 output_low(STOP1);
55 output_low(STOP2);
1815 kaklik 56  
57 delay_ms(50);
58  
59 //write raw register values
1817 kaklik 60 /* output_low(TDC_ENABLE);
1815 kaklik 61 spi_xfer(TDC_stream,0x80338AE8,32);
62 output_high(TDC_ENABLE);
63  
64 output_low(TDC_ENABLE);
65 spi_xfer(TDC_stream,0x81211400,32);
66 output_high(TDC_ENABLE);
67  
68 output_low(TDC_ENABLE);
69 spi_xfer(TDC_stream,0x82E03200,32);
70 output_high(TDC_ENABLE);
71  
72 output_low(TDC_ENABLE);
73 spi_xfer(TDC_stream,0x83083300,32);
74 output_high(TDC_ENABLE);
75  
76 output_low(TDC_ENABLE);
77 spi_xfer(TDC_stream,0x84203400,32);
78 output_high(TDC_ENABLE);
79  
80 output_low(TDC_ENABLE);
81 spi_xfer(TDC_stream,0x85080000,32);
82 output_high(TDC_ENABLE);
1817 kaklik 83 */
1775 kaklik 84 TDC_start_cal_resonator();
85 delay_ms(50);
86 printf("calibrate: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
1815 kaklik 87 // TDC_start_cal();
88 // delay_ms(50);
1759 kakl 89  
1744 kakl 90 while(true)
91 {
1798 kaklik 92 temperature = ds1820_read();
1815 kaklik 93  
1818 kaklik 94 // TDC_init();
1798 kaklik 95  
1759 kakl 96 delay_ms(50);
1774 kaklik 97 printf("Temp: %f \r\n", temperature);
98 delay_ms(50);
99 printf("status: %LX \r\n", TDC_get_status());
1775 kaklik 100  
1818 kaklik 101 // TDC_start_cycle();
1775 kaklik 102  
1815 kaklik 103 // delay_us(10);
1759 kakl 104 output_high(START);
1775 kaklik 105 // delay_us(1);
1798 kaklik 106  
1815 kaklik 107 delay_us(100);
108 // output_low(START);
1759 kakl 109  
1815 kaklik 110 output_high(STOP1);
1775 kaklik 111 // delay_us(10);
112 // delay_us(500);
113 // output_high(STOP1);
114 // delay_us(10);
1815 kaklik 115 output_low(STOP1);
1775 kaklik 116 // delay_us(500);
117 // output_high(STOP1);
1815 kaklik 118 delay_us(10);
1775 kaklik 119 // output_low(STOP1);
1798 kaklik 120 output_low(START);
1759 kakl 121  
1798 kaklik 122 // output_high(STOP2);
1775 kaklik 123 // delay_us(10);
1798 kaklik 124 // output_low(START);
1815 kaklik 125 output_high(STOP1);
1798 kaklik 126 // output_low(STOP2);
1775 kaklik 127 // delay_us(500);
1798 kaklik 128 // output_high(STOP2);
1775 kaklik 129 // delay_us(10);
1817 kaklik 130 output_low(STOP1);
1775 kaklik 131 // delay_us(500);
1798 kaklik 132 // output_high(STOP2);
1775 kaklik 133 // delay_us(10);
1798 kaklik 134 // output_low(STOP2);
1775 kaklik 135  
136  
1798 kaklik 137 // delay_ms(10);
1818 kaklik 138 TDC_start_temp();
1798 kaklik 139  
1775 kaklik 140 delay_ms(10);
1774 kaklik 141 printf("status: %LX \r\n", TDC_get_status());
1759 kakl 142 delay_ms(50);
1774 kaklik 143 printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
1744 kakl 144 delay_ms(500);
1759 kakl 145  
1744 kakl 146 };
147 }