/Designs/Measuring_instruments/GM_counter/SW/counter/main.c
54,13 → 54,18
}
}
 
#define TRESHOLD_setup 1
#define INTERVAL_setup 0
 
 
void main()
{
unsigned int16 integration_time=60;
unsigned int16 time;
unsigned int16 last_timer; // promena pro praskani
unsigned int1 button_press,voltage_setup,time_setup; // semafor pro cteni tlacitek
unsigned int1 button_press,setup_mode=INTERVAL_setup; // semafor pro cteni tlacitek
unsigned int16 measurement_number=0;
unsigned int8 treshold=6;
 
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_32);
82,7 → 87,7
output_low(BEEP);
 
setup_comparator(CP2_A0_VREF|CP2_OUT_ON_A5); // sets two comparators(A1 and VR and A2 as the output)
setup_vref(VREF_HIGH|6); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
enable_interrupts(INT_COMP); //enables the comparator interrupt
enable_interrupts(INT_RTCC);
enable_interrupts(INT_TIMER1);
120,9 → 125,8
}
lcd_gotoxy(1,2);
printf(lcd_putc,"T:%lu ",time);
lcd_gotoxy(9,2);
printf(lcd_putc,"I:%lu ", integration_time);
printf(lcd_putc,"T:%3lu I:%3lu U:%2u ",time,integration_time,treshold);
// printf(lcd_putc,"I:%4lu ", integration_time);
 
if(time == 0) // po uplynuti mereneho intervalu vypis na seriovku
{
143,10 → 147,17
if(!input(S1))
{
button_press=true;
if(time_setup==TRUE)
sound_beep(100,700);
switch (setup_mode)
{
sound_beep(100,700);
if(integration_time < 0xfffa ) integration_time+=5;
case INTERVAL_setup:
if(integration_time < 0xfffa ) integration_time+=5;
break;
case TRESHOLD_setup:
if(treshold < 0x0a ) treshold +=5;
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
break;
}
}
}
157,15 → 168,20
if(!input(S2))
{
button_press=true;
if(time_setup==TRUE)
sound_beep(100,600);
switch (setup_mode)
{
sound_beep(100,600);
if(integration_time > 0x0005 ) integration_time-=5;
 
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
time_overflow_count=0;
set_timer1(0);
overflow_count=0;
case INTERVAL_setup:
if(integration_time > 0x0005 ) integration_time-=5;
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
time_overflow_count=0;
set_timer1(0);
overflow_count=0;
break;
case TRESHOLD_setup:
if(treshold > 0x05 ) treshold +=5;
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
break;
}
}
}
176,10 → 192,17
if(!input(S3))
{
button_press=true;
if(time_setup==TRUE)
sound_beep(100,500);
switch (setup_mode)
{
sound_beep(100,500);
if(integration_time < 0xffff ) integration_time++;
case INTERVAL_setup:
if(integration_time < 0xffff ) integration_time++;
break;
 
case TRESHOLD_setup:
if(treshold < 0x0F ) treshold ++;
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
break;
}
}
}
190,18 → 213,23
if(!input(S4))
{
button_press=true;
if(time_setup==TRUE)
sound_beep(100,400);
switch (setup_mode)
{
sound_beep(100,400);
if(integration_time > 0x0001 ) integration_time--;
case INTERVAL_setup:
if(integration_time > 0x0001 ) integration_time--;
 
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
time_overflow_count=0;
set_timer1(0);
overflow_count=0;
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
time_overflow_count=0;
set_timer1(0);
overflow_count=0;
break;
case TRESHOLD_setup:
if(treshold > 0x01 ) treshold--;
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
break;
}
if(time_setup==TRUE)
{
}
}
212,8 → 240,9
{
button_press=true;
sound_beep(100,800);
voltage_setup=FALSE;
time_setup=TRUE;
setup_mode=INTERVAL_setup;
lcd_gotoxy(16,1); // prepsani dat na displeje
printf(lcd_putc,"I");
}
}
224,8 → 253,9
{
button_press=true;
sound_beep(100,800);
voltage_setup=TRUE;
time_setup=FALSE;
setup_mode=TRESHOLD_setup;
lcd_gotoxy(16,1); // prepsani dat na displeje
printf(lcd_putc,"U");
}
}
}