1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Connecting Sensors to 8051 with stepper motors

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by dragonpoet, May 17, 2011.

  1. dragonpoet

    dragonpoet New Member

    Likes Received:
    0
    Trophy Points:
    0
    Hi I'm trying to piece together a project that allows me to read from a sensor and at a certain distance slows down/stops a stepper motor using an 8051. I've seen some code here and on other sites to help me get started but I can't even get those to function properly. Can someone help me?
  2. dragonpoet

    dragonpoet New Member

    Likes Received:
    0
    Trophy Points:
    0
    These are two of the codes I'm referencing:

    #include <REGX51.h>
    #include <math.h>

    unsigned char ir; // to store the final result
    bit ir1,ir2; // the 2 recording point required for our algorithm

    delay(y){ // simple delay function unsigned int i;
    for(i=0;i<y;i++){;}
    }
    void main(){
    //P2.0 IR control pin going to the sensor
    //P2.1 IR output pin coming from the sensor

    while(1){
    P2_0 = 1; //send IR
    delay(20);
    ir1 = P2_1;
    P2_0 = 0; //stop IR
    delay(98);
    ir2 = P2_1;

    if ((ir1 == 1)&(ir2 == 0)){
    ir = 1; // Obstacle detected
    P2_3 = 1; // Pin 3 of PORT 2 will go HIGH turning ON a LED.
    if ((ir1 == 1)&(ir2 == 1)){
    ir = 2; // Sensor is saturated by ambient light
    }else{
    ir = 0; // The way is clear in front of the sensor.
    }
    }
    }



    and this one is for the stepper motor:

    #include <REG2051.H>.
    #define stepper P1
    void delay();

    void main(){
    while(1){
    stepper = 0x0C;
    delay();
    stepper = 0x06;
    delay();
    stepper = 0x03;
    delay();
    stepper = 0x09;
    delay();
    }
    }

    void delay(){
    unsigned char i,j,k;
    for(i=0;i<6;i++)
    for(j=0;j<255;j++)
    for(k=0;k<255;k++);
    }
Loading...

Share This Page