Stepper Motor Interfacing with PIC16F877A - PIC Programming - Proteus Simulation - MPLAB C Coding



Problem - Stepper Motor Interfacing with PIC PIC16F877A micro-controller.

Software Support - MPLAB IDE for C programming,Proteus for simulation purpose.

Components - PIC 16F877A- Micro controller,Stepper motor,ULN2003 driver IC..

Theory :-
  
Some theory regarding stepper motor.It is an electric motor which can be controlled by pulse trains.As in the figure,a permanent magnet rotates based on field generated by four stators.One of the major feature of stepper motor is the degree of rotation can be defined by step angle.

    Full sequence method is used here giving step angle of ninety degrees.An driver IC is always needed because the micro controller alone can't provide necessary power.While interfacing with micro controller a sequence of shifted binary numbers are fed into the motor.
           In this case,we have ninety degree step angle hence four shifted values has to be generated.So in sequence nine,twelve,six,three are given for right rotation and in reverse order for left rotation.The direction  is controlled by the switch.

Circuit Setup :-


Program:-

#include<pic.h> //PIC header file
#define _XTAL_FREQ 1000000 //Frequency selection
void main()
{
TRISC=0; //Port C as output
TRISB=0XFF; //Port B as input
while(1)
{
if(RB0==1) //Checking switch status
{
PORTC=0b1001; //Left shift
__delay_ms(50);
PORTC=0b1100;
__delay_ms(50);
PORTC=0b0110;
__delay_ms(50);
PORTC=0b0011;
__delay_ms(50);
}
else
{
PORTC=0b0011; //Right shift
__delay_ms(50);
PORTC=0b0110;
__delay_ms(50);
PORTC=0b1100;
__delay_ms(50);
PORTC=0b1001;
__delay_ms(50);
}
}
}

For more PIC 16F877A programs - click here

Popular posts from this blog

8051 Assembly Program Code for Sorting in Descending Order - Keil - AT89C51