/Designs/Measuring_instruments/GM_counter/SW/counter/main.c
2,13 → 2,15
 
#define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
#define LED3 PIN_C4 // pulse detect
#define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
 
#define S1 PIN_C2 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define S2 PIN_C3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define S3 PIN_D0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
#define S4 PIN_D1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
#define S1 PIN_C2 // raw up
#define S2 PIN_C3 // raw down
#define S3 PIN_D0 // fine up
#define S4 PIN_D1 // fine down
#define S5 PIN_B1 // time setup
#define S6 PIN_B2 // treshold setup
 
#define BEEP PIN_D2 //piezo beeper
 
57,7 → 59,7
unsigned int16 integration_time=60;
unsigned int16 time;
unsigned int16 last_timer; // promena pro praskani
unsigned int1 button_press; // semafor pro cteni tlacitek
unsigned int1 button_press,voltage_setup,time_setup; // semafor pro cteni tlacitek
unsigned int16 measurement_number=0;
 
setup_adc_ports(sAN0|VSS_VDD);
97,26 → 99,32
printf("\r\n");
set_timer1(0);
 
lcd_gotoxy(1,1); // vypsani hodnoty count, abz byla na LCD hned od zapnuti
printf(lcd_putc,"Count:%lu ",pulse_count);
 
while(true)
{
pulse_count = get_timer1() + (0xffff * overflow_count);
time = integration_time + 1 - (time_overflow_count * 0.0327) ;
pulse_count = get_timer1() + (0xffff * overflow_count); // compute pulse count
time = integration_time + 1 - (time_overflow_count * 0.0327); // compute time interval
if(get_timer1() != last_timer)
if(get_timer1() != last_timer) // timer count increment detection
{
output_toggle(BEEP);
delay_ms(1);
output_toggle(BEEP);
output_toggle(LED3);
last_timer=get_timer1();
lcd_gotoxy(1,1); // prepsani dat na displeje
printf(lcd_putc,"Count:%lu ",pulse_count);
}
lcd_gotoxy(1,1);
printf(lcd_putc,"Count:%lu ",pulse_count);
lcd_gotoxy(1,2);
printf(lcd_putc,"T:%lu ",time);
lcd_gotoxy(9,2);
printf(lcd_putc,"I:%lu ", integration_time);
 
if(time == 0)
if(time == 0) // po uplynuti mereneho intervalu vypis na seriovku
{
set_timer0(0);
time_overflow_count=0;
135,9 → 143,11
if(!input(S1))
{
button_press=true;
sound_beep(100,700);
if(integration_time < 0xfffa ) integration_time+=5;
if(time_setup==TRUE)
{
sound_beep(100,700);
if(integration_time < 0xfffa ) integration_time+=5;
}
}
}
 
147,13 → 157,16
if(!input(S2))
{
button_press=true;
sound_beep(100,600);
if(integration_time < 0xfffa ) integration_time-=5;
if(time_setup==TRUE)
{
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;
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
time_overflow_count=0;
set_timer1(0);
overflow_count=0;
}
}
}
 
163,8 → 176,11
if(!input(S3))
{
button_press=true;
sound_beep(100,500);
if(integration_time < 0xffff ) integration_time++;
if(time_setup==TRUE)
{
sound_beep(100,500);
if(integration_time < 0xffff ) integration_time++;
}
}
}
 
174,21 → 190,49
if(!input(S4))
{
button_press=true;
sound_beep(100,400);
if(integration_time < 0xffff ) integration_time--;
if(time_setup==TRUE)
{
sound_beep(100,400);
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;
}
if(time_setup==TRUE)
{
}
}
if(!input(S5)) // prepnuti na nastavovani casu
{
delay_ms(20);
if(!input(S5))
{
button_press=true;
sound_beep(100,800);
voltage_setup=FALSE;
time_setup=TRUE;
}
}
if(!input(S6)) // prepnuti na nastavovani napeti
{
delay_ms(20);
if(!input(S6))
{
button_press=true;
sound_beep(100,800);
voltage_setup=TRUE;
time_setup=FALSE;
}
}
}
if ( input(S1) && input(S2) && input(S3) && input(S4) )
if ( input(S1) && input(S2) && input(S3) && input(S4) && input(S5) && input(S6)) // detekce pustenych tlacitek
{
button_press=false;
}
}
}
 
}