Thursday, February 25, 2010

Embedded System Design 2

Components

1 x PIC16F887 Development Kit
4 x Motor Drive Transistor
1 x 2 phase unipolar stepper motor

Description

This circuit will drive the 2 phase unipolar stepper motor once the push button is pressed, to the right and with delay 5 seconds and the motor will turn to the left by 90 degree respectively.

C Source Code

#include<16f887.h>
#device ICD=TRUE
#fuses HS, NOLVP, NOWDT
#use delay(clock = 20000000)
#byte PORTB = 8

#define PUSH_BUTTON PIN_A4

void wait_for_one_press(){
while(input(PUSH_BUTTON));
while(!input(PUSH_BUTTON));
}

void main(){

SET_TRIS_B(0x00); //PORTB all is output
PORTB = 0x05; //SET PORTB initial position to 0 degree

while(TRUE){

wait_for_one_press(); //WAIT FOR ONE PRESS TO START TO TURN THE MOTOR
PORTB = 0x09; // Drive Stepper Motor 90 degree to the right
delay_ms(5000); //delay 5 second before rotate 90 degree to the left
PORTB = 0x05; //Drive Stepper Motor 90 degree to the left
}
}

0 comments: