Rev 2742 Rev 2744
1 #include ".\main.h" 1 #include ".\main.h"
2 //#include <LCD.C> -  
3   2  
4 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 3 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
5 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 4 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
6 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 5 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
7 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 6 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
8   7  
-   8 #define S1 PIN_C2 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
-   9 #define S2 PIN_C3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
-   10 #define S3 PIN_D0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
-   11 #define S4 PIN_D1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
9   12  
-   13 #define BEEP PIN_D2 //piezo beeper
-   14  
-   15 #define LCD_ENABLE_PIN PIN_E0 ////
-   16 #define LCD_RS_PIN PIN_E1 ////
-   17 #define LCD_RW_PIN PIN_E2 ////
-   18 #define LCD_DATA4 PIN_D4 ////
-   19 #define LCD_DATA5 PIN_D5 ////
-   20 #define LCD_DATA6 PIN_D6 ////
-   21 #define LCD_DATA7 PIN_D7
-   22 #include <lcd.c>
-   23  
-   24  
-   25 unsigned int32 pulse_count=0;
-   26 unsigned int16 overflow_count=0;
-   27 unsigned int16 time_overflow_count=0;
-   28  
-   29  
10 #int_EXT 30 #int_RTCC
11 void EXT_isr(void) 31 void RTCC_isr(void)
12 { 32 {
-   33 time_overflow_count++;
-   34 }
-   35  
-   36 #int_TIMER1
-   37 void TIMER1_isr(void)
-   38 {
-   39 overflow_count++;
13 output_toggle(LED3); 40 output_toggle(LED3);
-   41 output_toggle(BEEP);
14 } 42 }
15   43  
16 //#define LCD_TYPE 1 44 void sound_beep( unsigned int lenght, int16 frequency)
17 //#include <lcd.c> -  
18 void main() -  
19 { 45 {
20 unsigned int setpoint; 46 unsigned int i;
21 unsigned int napeti; -  
22 unsigned int16 plneni=0; -  
23   -  
24 /* lcd_init(); -  
25   47
26 lcd_putc("\fReady...\n"); 48 for(i=0;i<=lenght;i++)
27   49 {
28 while (TRUE) { -  
29 k=kbd_getc(); 50 output_toggle(BEEP);
30 if(k!=0) -  
31 if(k=='*') -  
32 lcd_putc('\f'); 51 delay_us(1/frequency);
33 else -  
34 lcd_putc(k); -  
35 } 52 }
-   53 }
-   54  
-   55 void main()
36 */ 56 {
-   57 unsigned int16 integration_time=60;
-   58 unsigned int16 time;
-   59 unsigned int16 last_timer; // promena pro praskani
-   60 unsigned int1 button_press; // semafor pro cteni tlacitek
-   61 unsigned int16 measurement_number=0;
37   62  
38 setup_adc_ports(sAN0|VSS_VDD); 63 setup_adc_ports(sAN0|VSS_VDD);
39 setup_adc(ADC_CLOCK_DIV_32); 64 setup_adc(ADC_CLOCK_DIV_32);
40 setup_spi(SPI_SS_DISABLED); 65 setup_spi(SPI_SS_DISABLED);
41 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); 66 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
42 setup_timer_1(T1_DISABLED); 67 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
43 setup_timer_2(T2_DIV_BY_1,255,1); 68 setup_timer_2(T2_DISABLED,0,1);
44 setup_ccp1(CCP_PWM); 69 setup_ccp1(CCP_PWM);
45 setup_ccp2(CCP_PWM); 70 setup_ccp2(CCP_PWM);
46 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard -  
47 setup_oscillator(OSC_8MHZ); 71 setup_oscillator(OSC_8MHZ);
48   72  
49 set_pwm1_duty(0); 73 set_pwm1_duty(0);
50 set_pwm2_duty(0); 74 set_pwm2_duty(0);
51   75  
52   -  
53 output_high(LED1); 76 output_high(LED1);
54 output_high(LED2); 77 output_high(LED2);
55 output_high(LED3); 78 output_high(LED3);
56 output_high(LED4); 79 output_high(LED4);
-   80 output_low(BEEP);
57   81  
-   82 setup_comparator(CP2_A0_VREF|CP2_OUT_ON_A5); // sets two comparators(A1 and VR and A2 as the output)
-   83 setup_vref(VREF_HIGH|6); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V
58 ext_int_edge( L_TO_H ); // Sets up EXT 84 enable_interrupts(INT_COMP); //enables the comparator interrupt
59 enable_interrupts(INT_EXT); 85 enable_interrupts(INT_RTCC);
-   86 enable_interrupts(INT_TIMER1);
-   87 enable_interrupts(INT_TIMER2);
60 enable_interrupts(GLOBAL); 88 enable_interrupts(GLOBAL);
-   89 lcd_init();
61   90  
-   91 lcd_putc("\fGM counter V1.0 \n 2013 MLAB");
-   92 printf("Geiger-Muller Counter V1.0 \r\n");
-   93 printf("(c) 2013 MLAB and UST.cz \r\n");
62 // lcd_init(); 94 Delay_ms(1000);
63 95
-   96 lcd_putc("\f");
64 setpoint = 43; 97 printf("\r\n");
65 98
-   99 set_timer1(0);
-   100
66 while(true) 101 while(true)
67 { 102 {
68 set_adc_channel(1); 103 pulse_count = get_timer1() + (0xffff * overflow_count);
69 delay_us(100); -  
70 napeti = read_adc(); 104 time = integration_time + 1 - (time_overflow_count * 0.0327) ;
71   105
72 if (napeti <= setpoint) 106 if(get_timer1() != last_timer)
73 { 107 {
74 if (plneni < 300) plneni++; 108 output_toggle(BEEP);
75 output_low(LED2); 109 last_timer=get_timer1();
76 } 110 }
77 else 111
-   112 lcd_gotoxy(1,1);
-   113 printf(lcd_putc,"Count:%lu ",pulse_count);
-   114 lcd_gotoxy(1,2);
-   115 printf(lcd_putc,"T:%lu ",time);
-   116 lcd_gotoxy(9,2);
-   117 printf(lcd_putc,"I:%lu ", integration_time);
-   118  
-   119 if(time == 0)
78 { 120 {
-   121 set_timer0(0);
79 if (plneni > 0) plneni--; 122 time_overflow_count=0;
-   123 sound_beep(1000,700);
-   124 printf("$GMC1.0 %lu %lu %lu \r\n", measurement_number, integration_time, pulse_count);
80 output_high(LED2); 125 set_timer1(0);
-   126 overflow_count=0;
-   127 measurement_number++;
81 } 128 }
82   129  
-   130 if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta.
-   131 {
-   132 if(!input(S1))
-   133 {
-   134 delay_ms(20);
83 set_pwm1_duty(plneni); 135 if(!input(S1))
-   136 {
-   137 button_press=true;
-   138 sound_beep(100,700);
-   139 if(integration_time < 0xfffa ) integration_time+=5;
-   140
-   141 }
-   142 }
-   143  
-   144 if(!input(S2))
-   145 {
-   146 delay_ms(20);
-   147 if(!input(S2))
-   148 {
-   149 button_press=true;
84 set_pwm2_duty(1023-plneni); 150 sound_beep(100,600);
-   151 if(integration_time < 0xfffa ) integration_time-=5;
-   152  
-   153 set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
-   154 time_overflow_count=0;
-   155 set_timer1(0);
-   156 overflow_count=0;
-   157 }
-   158 }
85   159  
-   160 if(!input(S3))
-   161 {
86 output_toggle(LED1); 162 delay_ms(20);
-   163 if(!input(S3))
-   164 {
-   165 button_press=true;
-   166 sound_beep(100,500);
-   167 if(integration_time < 0xffff ) integration_time++;
-   168 }
-   169 }
-   170  
-   171 if(!input(S4))
-   172 {
87 delay_ms(10); 173 delay_ms(20);
-   174 if(!input(S4))
-   175 {
-   176 button_press=true;
-   177 sound_beep(100,400);
-   178 if(integration_time < 0xffff ) integration_time--;
-   179  
-   180 set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka
-   181 time_overflow_count=0;
-   182 set_timer1(0);
-   183 overflow_count=0;
-   184 }
-   185 }
-   186 }
-   187
-   188 if ( input(S1) && input(S2) && input(S3) && input(S4) )
-   189 {
-   190 button_press=false;
-   191 }
88 } 192 }
89   193  
90 } 194 }