/Designs/Data_loggers/GPSRL04C/SW/PIC/Spectrometer/main.c
3,36 → 3,15
 
#define LED PIN_D7
 
#define RECORDS 1000 // length of buffer
#define NOISE 2 // noise treshold
#define RECORDS 100
 
int16 count, count_new;
void main()
{
 
int16 time, time_new;
int16 log[RECORDS];
int16 record;
 
#int_RDA
void RDA_isr(void) // Interrupt from received character
{
int16 n;
if(getc()=='r') // Send records
{
printf("%Lu,", record);
for (n=0; n<record; n++) printf("%Lu,", log[n]);
printf("0\n\r");
}
else
{ // Reset counters
set_timer0(0);
count = 0;
count_new = 0;
record = 0;
}
}
 
 
void main()
{
setup_adc_ports(AN0_TO_AN7|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
46,31 → 25,43
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
output_low(LED);
 
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
record = 0;
output_low(LED);
/*
while(true)
{
output_low(LED);
delay_ms(1);
output_high(LED);
delay_ms(1);
printf("%u\n\r", 0x55);
}
//*/
n=0;
while(true)
{
set_timer0(0);
count = 0;
count_new = 0;
while(count_new == 0) // waiting for a new radiation event
time = 0;
time_new = 0;
while(time_new == 0)
{
count_new=get_timer0();
time_new=get_timer0();
}
output_high(LED);
while(count != count_new) // waiting for the end of radiation event
while(time != time_new)
{
count=count_new;
count_new=get_timer0();
time=time_new;
time_new=get_timer0();
delay_us(5);
}
if ((record<RECORDS)&&(count>NOISE)){ log[record++]=count;} // Record radiation event
 
if (time>3){ log[n++]=time;}
if (n==RECORDS)
{
for (n=0; n<RECORDS; n++) printf("%Lu,", log[n]);
printf("\n\r");
n = 0;
}
output_low(LED);
}
/Designs/Data_loggers/GPSRL04C/SW/PIC/Spectrometer/main.h
32,4 → 32,4
//#FUSES ICPRT //ICPRT enabled
 
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)