Robotics & Electronic

Stepper Motor Controlling with Micro controller (PIC16F) 



PIC16F627/PIC16F628/PIC16F628A/PIC16F84A Simply Connected to Stepper through L298 H-Bridge




Code (Assembly)
;SystemVars
                       status               equ               03h
                       trisa                 equ               85h
                       trisb                 equ               86h
                       porta               equ               05h
                       portb               equ               06h

                     CounterL          equ               20h
                     CounterH          equ               21h

BIOS            bsf                  status,5
                     clrf                  trisa
                     clrf                  trisb
                     bcf                  status,5


main              call   rotate_left
                      call  Delay_second
                      call  rotate_right
                      call  Dealy_second
                      goto  main


rotate_left             movlw     D'10'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'6'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'5'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'9'
                               movf       portb,0
                               call          Dealy_second




                               return
rotate_right           movlw     D'9'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'5'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'6'
                               movf       portb,0
                               call          Dealy_second
                               movlw     D'10'
                               movf       portb,0
                               call          Dealy_second
                               return





Delay_second      decfsz     CounterL,1
                             goto         Delay_second
                             decfsz      CounterH,1
                             goto          Delay_second
                             return


Codes for MicroBasic



program Stepper_Controlling


    dim stepup as byte[5]
    dim i as integer
    dim x as integer
    dim y as integer
    






main:
     trisa=0
     trisa.1=1
     trisb=0
     porta.0=1
     delay_ms(500)
     porta.0=0
     delay_ms(100)
             while true
             stepup[0] = %10100000
             stepup[1] = %01100000
             stepup[2] =%01010000
             stepup[3] = %010010000
              stepup[4]=0
       'for   x=0 to 30000
       for  i=0 to 3
            portb=stepup[i]
              delay_ms(4)
              portb=stepup[4]
         if porta.1=1 then
        porta.2=not porta.2
        end if
       next i
      ' next x
                wend


end.