Maker Pro
Maker Pro

Sensor interface with motor and PIC16F877A.

ishah

Jun 28, 2013
2
Joined
Jun 28, 2013
Messages
2
Hi everyone,

I want to apply the soft stop technology in my project by using PWM, and PIC16F877A.
It mean I want to control the closing door box to a smooth impact.
But I am lack of C but I am trying to learn it.

Here is the model of my project.

image.jpg
[/url][/IMG]

Here is my MicroC code. Still under construction,only have a basic movement.
Code:
//define motor1 ports
sbit motor1a at RD0_bit;
sbit motor1b at RD1_bit;


//define motor2 ports
sbit motor2a at RD2_bit;
sbit motor2b at RD3_bit;

//define sensor ports
#define SENSOR PORTA


//define switches ports
#define PB1 PORTB.F0
#define PB2 PORTB.F1
#define PB3 PORTB.F2
#define PB4 PORTB.F3

unsigned short toggle = 0;

void main(){

    TRISA = 0XFF; //Configure all bit of PORTA as input
    TRISB = 0XFF; //Configure all bit of PORTB as input
    TRISD = 0X00; //Configure all bit of PORTD as output
    PORTA = 0X00; //Clear bits to zero
    PORTB = 0X00; //Clear bits to zero
    PORTD = 0X00; //Clear bits to zero

    CMCON=0X07;   //or CMCON register = 0X00000111
    ADCON1=0X07;  //Configure ADCON1, or ADCON1=0X06;

    while(1){

        if((SENSOR & 0x07) == 0x00)
        {

            if(PB1 == 1)   //If the push button 1 is pressed
            {
             Delay_ms(50);         // Delay 100 ms
             if(PB1 == 1)
                 {
                    motor1a = 1;   // Motor 1 clockwise
                    motor1b = 0;
                    motor2a = 1;   // Motor 2 clockwise
                    motor2b = 0;
                 }
             }
            else
            if (PB2 == 1)   //If the push button 2 is pressed
            {
              Delay_ms(50);         // Delay 100 ms
              if(PB2 == 1)
                 {
                    if(PB2 == 1)

                    motor1a = 0;   // Motor 1 counter clockwise
                    motor1b = 1;
                    motor2a = 0;   // Motor 2  counter clockwise
                    motor2b = 1;
                 }
             }
            else
            if (PB3 == 1)   //If the push button 3 is pressed
            {
              Delay_ms(50);         // Delay 100 ms
              if(PB3 == 1)
                 {
                    motor1a = 1;   // Motor 1 clockwise
                    motor1b = 0;
                    motor2a = 1;   // Motor 2 clockwise
                    motor2b = 0;
                 }
            }
            else
            if (PB4 == 1)   //If the push button 4 is pressed
            {
              Delay_ms(50);         // Delay 100 ms
              if(PB4 == 1)
                 {
                    motor1a = 0;   // Motor 1 counter clockwise
                    motor1b = 1;
                    motor2a = 0;   // Motor 2 counter clockwise
                    motor2b = 1;
                 }
             }
        }
        else if(((SENSOR & 0x07) == 0x01) || ((SENSOR & 0x07) == 0x02) || ((SENSOR & 0x07) == 0x04))
        {
                motor1a = 0;   // Motor 1 stop
                motor1b = 0;
                motor2a = 0;   // Motor 2 stop
                motor2b = 0;
        }
      }
}

My problem is when i simulate using ISIS proteus, the motor run without selected any button.
 
Top