' ' Geiger Counter ATTINY2313 ' by JA1DSP/JA3WZT Y.Tanabe ' ' Rev.B0 20.Jun.2011 1st coding ' Rev.B1 19.Jul.2011 add uSv/hr ' ' FUSE Bit EXTENDED 0xFF ' HIGH 0xDF ' LOW 0xDF ' $regfile = "attiny2313.dat" $crystal = 8000000 '8MHz 'Baud rate 38400 $baud = 38400 Config Portb.6 = Output 'Set the portb.6 to output Config Portd.3 = Input 'Set the portd.3 to input Config Lcdpin = Pin , Db7 = Portb.3 , Db6 = Portb.2 Config Lcdpin = Pin , Db5 = Portb.1 , Db4 = Portb.0 Config Lcdpin = Pin , E = Portb.7 , Rs = Portb.5 Config Lcd = 16 * 2 Config Timer0 = Counter , Edge = Rising '8 bit counter Config Timer1 = Timer , Prescale = 1 '16 bit Timer Dim Flag As Bit 'Excecution Flag Dim Mode_flag As Bit '0:CPM 1:ACCUM Dim Tint As Byte 'Interval timer Dim Cps As Byte 'Count per Sec Dim Cpm As Word 'Count per Min. Dim Cpm2usv_div_10 As Byte ' 1/10 of Cpm2usv value Dim I As Byte 'Temparary counter Dim J As Byte 'Temporary counter Dim Ndata(10) As Byte '10 array of cps Dim Usvh As Word 'upper uSv Dim Usvl As Word Dim Usvll As Long 'Lower uSv Dim Accum As Long 'Accumulated count Dim T_sec As Word 'Total elapsed time(sec) Const Cpm2usv = 150 'CPM to uSV/hr Const Kaisu = 118 'Count number of Tint for 1sec Declare Sub Cal_cpm Declare Sub Mode_switch ' ' Start Geiger Counter Program here ' Portb.6 = 0 '0=> R/~W of LCD Portd.3 = 1 'Pull Up MODE_SW Cls Lcd "Geiger Counter " Lowerline Lcd " for SBM-20 B.1" Wait 1 Stop Timer1 Stop Timer0 On Timer1 Timer1_int Enable Interrupts Enable Timer1 Cls : Cursor Off Start Timer0 Start Timer1 Mode_flag = 0 J = 1 Accum = 0 T_sec = 0 Cpm2usv_div_10 = Cpm2usv \ 10 'Const:Cpm2usv divide by_10 'EXample. Cpm2usv=150 then 15 Do Debounce Pind.3 , 0 , Mode_switch , Sub If Flag = 1 Then Cps = Timer0 If Cps >= 200 Then Cls Lcd "CPM>12000" ' Display Overflow! Cps = 200 End If Ndata(j) = Cps Incr T_sec Print T_sec ; Spc(1) ; Cps 'output T_sec & Cps to RS232C port Accum = Accum + Cps Incr J If J > 10 Then J = 1 Cpm = 0 Call Cal_cpm Flag = 0 Tint = 0 Timer0 = 0 Start Timer1 Start Timer0 End If Loop ' ' Sub Cal_cpm : Calcurate moving average for 10sec ' Sub Cal_cpm For I = 1 To 10 Cpm = Cpm + Ndata(i) Next I Cpm = Cpm * 6 ' multiply 6 (10sec x 6 = 60sec) Cls If Mode_flag = 0 Then 'Mode_flag 0: Disp CPM and uSv/fr ! Lcd "CPM=" ; Cpm Usvh = Cpm \ Cpm2usv Usvl = Cpm Mod Cpm2usv Usvll = Usvl * 100 Usvl = Usvll \ Cpm2usv_div_10 Lowerline Lcd "uSv/hr=" ; Usvh; Select Case Usvl Case Is < 9 : Lcd ".00" ; Usvl Case Is < 99 : Lcd ".0" ; Usvl Case Is < 999 : Lcd "." ; Usvl Case Else : Lcd "0.000" End Select Else Lcd "T.sec=" ; T_sec 'Disp Elapped time(sec) Lowerline Lcd "Accm.=" ; Accum 'Disp Accumlated Count End If End Sub ' ' Detect Mode_SW and set Mode_flag ' Sub Mode_switch Mode_flag = Not Mode_flag End Sub End ' ' Tomer1 Routine : Make 1 sec ' Timer1_int: Incr Tint If Tint = Kaisu Then ' 125~125 for 8MHz clock. Adjust optimized value. Stop Timer1 Stop Timer0 Flag = 1 End If Return