' ********************** ' ADC_Controller ' 13A-ADC-2012xKai.bas ' Ni-MH Chargeas ' By JA8FGA ' 2012/03/07 09:00 '*********************** $regfile = "ATtiny13a.dat" $crystal = 1200000 '*********************** Config Int0 = Low Level Config Adc = Single , Prescaler = Auto Config Portb.1 = Input Config Portb.3 = Input Config Portb.0 = Output Config Portb.2 = Output Config Portb.4 = Output '*********************** Dim A As Word Dim A2 As Word Dim B As Byte Dim B2 As Byte Dim Cnt As Byte Dim Cnt1 As Byte Dim Cnt2 As Byte Dim Pbf As Byte Dim Pbf2 As Byte Dim Intf1 As Bit Dim Intf2 As Bit Dim C1 As Bit Dim Startf As Bit '********************** On Int0 Int0_int Enable Interrupts Enable Int0 Cnt1 = 230 Cnt = Cnt1 Cnt2 = 8 B = Cnt1 B2 = 50 C1 = 1 A2 = 10 Pbf = 3 Pbf2 = 3 Reset Intf1 Reset Intf2 Reset A2 Reset Startf Set Portb.2 '********************** Do If Intf1 = 1 Then If Startf <> 1 Then Set Startf Set Portb.0 Set Portb.2 Reset Intf1 Disable Interrupts Else Reset Portb.2 Cnt2 = 0 Set Intf2 Reset Intf1 Disable Interrupts End If End If If Intf2 = 0 Then If Pbf2 <> 0 Then Decr Pbf2 Else Enable Interrupts End If End If If Intf2 = 1 Then If Pinb.1 = 0 Then If Pbf <> 0 Then Decr Pbf End If End If If Pinb.1 = 1 Then Pbf = 3 End If If Pbf = 0 Then B2 = 0 End If End If '**************************** Lp: '1 If C1 = 0 Then Goto Lp '1 End If '*** 30m Chek *** '2 If Cnt = 0 Then '2-1 If Cnt2 <> 0 Then Decr Cnt2 Cnt = Cnt1 '2-1 End If '2 Else Decr Cnt '2 End If '*** 3h Chk *** '4 If B = 0 Then '4-1 If B2 <> 0 Then Decr B2 B = Cnt1 '4-1 End If '4 Else Decr B '4 End If '*** ADC Input *** Start Adc A = Getadc(3) '*** ADC-OverIN & SaikruTime Set *** Waitms 100 If A > 850 Then Goto Overadc End If '********************** '5 If Startf = 1 Then '5-1 If A2 <= A Then A2 = A Set Portb.4 Waitms 120 Reset Portb.4 Waitms 720 '5-1 Else Set Portb.4 Waitms 720 Reset Portb.4 Waitms 120 '5-1 End If '5 Else Cnt = Cnt1 Cnt2 = 8 B = Cnt1 B2 = 50 '5 End If '********************** '6 If Cnt2 = 0 Then Reset Portb.2 A = A + 4 '6-1 If A2 => A Then Reset Portb.0 Reset C1 '6-1 End If '6 Else A2 = A '6 End If '************************ '7 If B2 = 0 Then Reset Portb.0 Set Portb.4 Reset C1 '7 End If Loop '******* Overadc ******* Overadc: Reset Portb.0 Reset Portb.4 Ovl: Set Portb.2 Waitms 120 Reset Portb.2 Waitms 720 Waitms 160 Goto Ovl '**** Interrupts **** Int0_int: Set Intf1 Return End