'******************************************************************* ' Program Name : pulse motor ' Start Date 18th.Apr.2010 ' Author Yoshio KATO ' Description : Used MCU ATtiny2313 low voltage version ' : Pulse motor control '******************************************************************* $regfile = "attiny2313.dat" $crystal = 8000000 Dim I As Byte Dim J As Byte Dim Speed_para As Byte Dim Data_count As Byte Dim Rotate_mode As Byte Const Reverse_sw = 0 'PD0 Const One_sw = 1 'PD1 Const Two_sw = 2 'PD2 Const One_two_sw = 3 'PD3 Const Stop_sw = 1 'PD1 Const Fast_sw = 2 'PD2 int0 Const Slow_sw = 3 'PB3 int1 Dim One_phase_data(4) As Byte Dim Two_phase_data(4) As Byte Dim One_two_phase_data(8) As Byte Main: Stop Ac 'Analog comparater power off Config Portb = &HFF Config Portd = &HF0 Portd = &H0F ' pullup Config Int0 = Falling 'PD2 hardware interrup falling edge On Int0 Fast Config Int1 = Falling 'PD2 hardware interrup falling edge On Int1 Slow One_phase_data(1) = &H10 One_phase_data(2) = &H20 One_phase_data(3) = &H40 One_phase_data(4) = &H80 Two_phase_data(1) = &H90 Two_phase_data(2) = &H30 Two_phase_data(3) = &H60 Two_phase_data(4) = &HC0 One_two_phase_data(1) = &H90 One_two_phase_data(2) = &H10 One_two_phase_data(3) = &H30 One_two_phase_data(4) = &H20 One_two_phase_data(5) = &H60 One_two_phase_data(6) = &H40 One_two_phase_data(7) = &HC0 One_two_phase_data(8) = &H80 Do Speed_para = 5 Portb = 0 'stop If Pind.one_sw = 0 Then Rotate_mode = 1 Data_count = 4 Gosub Rotate_motor End If If Pind.two_sw = 0 Then Rotate_mode = 2 Data_count = 4 Gosub Rotate_motor End If If Pind.one_two_sw = 0 Then Rotate_mode = 3 Data_count = 8 Gosub Rotate_motor End If Loop End '******************************************************************* ' rotate pulse motor '******************************************************************* Rotate_motor: Enable Int0 Enable Int1 Enable Interrupts Top_rotate: Wait 1 Do For I = 1 To Data_count Select Case Rotate_mode Case 1 : Portb = One_phase_data(i) Case 2 : Portb = Two_phase_data(i) Case 3 : Portb = One_two_phase_data(i) End Select Waitms Speed_para Debounce Pind.stop_sw , 0 , Rtn_rotate Debounce Pind.reverse_sw , 0 , Reverse Next I Loop Reverse: Wait 1 Do For I = Data_count To 1 Step -1 Select Case Rotate_mode Case 1 : Portb = One_phase_data(i) Case 2 : Portb = Two_phase_data(i) Case 3 : Portb = One_two_phase_data(i) End Select Waitms Speed_para Debounce Pind.stop_sw , 0 , Rtn_rotate Debounce Pind.reverse_sw , 0 , Top_rotate Next I Loop Rtn_rotate: Disable Int0 Disable Int1 Disable Interrupts Portb = 0 Wait 2 Return '******************************************************************* ' speed control fast '******************************************************************* Fast: If Speed_para > 2 Then Decr Speed_para End If Return '******************************************************************* ' speed control slow '******************************************************************* Slow: If Speed_para < 200 Then Incr Speed_para End If Return