Rev Author Line No. Line
4617 kakl 1 #include "main.h"
2  
3  
4 #define LED PIN_D7
5  
4633 kakl 6 #define RECORDS 1000 // length of buffer
7 #define NOISE 2 // noise treshold
4617 kakl 8  
4633 kakl 9 int16 count, count_new;
10 int16 log[RECORDS];
11 int16 record;
12  
13 #int_RDA
14 void RDA_isr(void) // Interrupt from received character
4617 kakl 15 {
16 int16 n;
17  
4633 kakl 18 if(getc()=='r') // Send records
19 {
20 printf("%Lu,", record);
21 for (n=0; n<record; n++) printf("%Lu,", log[n]);
22 printf("0\n\r");
23 }
24 else
25 { // Reset counters
26 set_timer0(0);
27 count = 0;
28 count_new = 0;
29 record = 0;
30 }
31 }
32  
33  
34 void main()
35 {
4617 kakl 36 setup_adc_ports(AN0_TO_AN7|VSS_VDD);
37 setup_adc(ADC_CLOCK_DIV_2);
38 setup_psp(PSP_DISABLED);
39 setup_spi(SPI_SS_DISABLED);
40 setup_wdt(WDT_OFF);
41 setup_timer_0(RTCC_EXT_H_TO_L);
42 setup_timer_1(T1_DISABLED);
43 setup_timer_2(T2_DISABLED,0,1);
44 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
45 setup_ccp1(CCP_OFF);
46 setup_comparator(NC_NC_NC_NC);
47 setup_vref(FALSE);
48  
4633 kakl 49 output_low(LED);
50  
51 enable_interrupts(INT_RDA);
52 enable_interrupts(GLOBAL);
53 record = 0;
4617 kakl 54 while(true)
55 {
56 set_timer0(0);
4633 kakl 57 count = 0;
58 count_new = 0;
59 while(count_new == 0) // waiting for a new radiation event
4617 kakl 60 {
4633 kakl 61 count_new=get_timer0();
4617 kakl 62 }
63 output_high(LED);
64  
4633 kakl 65 while(count != count_new) // waiting for the end of radiation event
4617 kakl 66 {
4633 kakl 67 count=count_new;
68 count_new=get_timer0();
4617 kakl 69 delay_us(5);
70 }
71  
4633 kakl 72 if ((record<RECORDS)&&(count>NOISE)){ log[record++]=count;} // Record radiation event
73  
4617 kakl 74 output_low(LED);
75 }
76  
77 }