Stepper Motor using PIC Microcontroller
This project shows Stepper Motor Control using PIC 16c55 Microcontroller. To simulate this circuit, initially activate Mixed Mode simulator from the Schematic Editor window. Selecting Run Transient analysis from Simulation menu can perform simulation.
This project contains a PIC 16C55/57, a Darlington Transistor Array,
a stepper motor, and a voltage source.
In this project, PIC 16C55 Microcontroller outputs the sequence to rotate the stepper motor. Port B of the microcontroller outputs the sequence to the Darlington Transistor Array. The output from the Darlington Transistor Array is send to the stepper motor.
The source code written in Assembly language can be viewed from the
code editor window.
The program is as shown:
#include p16c5x.inc ;This header file is included for all PIC projects.
;***** VARIABLE DEFINITIONS
temp_var udata
DVAR2 res 1 ;DVAR2 varible declaration
DVAR res 1 ;DVAR variable declaration
;**********************************************************************
reset_vector code 0x1ff ;processor reset vector
goto start
MAIN CODE 0x000
start
movlw 0x00 ;move literal value to accumulator
tris PORTB ;Set PORT B as output
loop movlw 0x01 ;move literal value to accumulator
movwf PORTB ;move accumulator to portB
call Delay ;call Delay subroutine
movlw 0x02 ;move literal value to accumulator
movwf PORTB ;move accumulator to portB
call Delay ;call Delay subroutine
movlw 0x04 ;move literal value to accumulator
movwf PORTB ;move accumulator to portB
call Delay ;call Delay subroutine
movlw 0x08 ;move literal value to accumulator
movwf PORTB ;move accumulator to portB
call Delay ;call Delay subroutine
goto loop
Delay movlw 0x02 ;move literal value to accumulator
movwf DVAR2 ;move 02 to outer maximum loop count
DelayOuter
movlw 0x02 ;move literal value to accumulator
movwf DVAR ;move 02 to inner maximum loop count
DelayInner
decfsz DVAR,1 ;decrement DVAR if result is not zero execute next step otherwise skip next step
goto DelayInner
decfsz DVAR2,1 ;decrement DVAR2 if result is not zero execute next step otherwie skip next step
goto DelayOuter
RETLW 0
end ;directive end of program'
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.