Hi, Can someone help me on the code push button. I'm doing the DC motor interface with PIC16f877A. I want the button to control all the movement (forward, reverse and stop). Current situation for my code,when I push the forward button, 2 motor will run forward and vice verse for the reverse button.
But I want is, when I keep pushing the forward button,the motor will move. and when i release the button .. the motor will stop.. so i dont need the stop button to control.
Thanks and here is the current code
But I want is, when I keep pushing the forward button,the motor will move. and when i release the button .. the motor will stop.. so i dont need the stop button to control.
Thanks and here is the current code
Code:
/*
This source code is use to control the 2 motor movement by select
the appropriate state button (Forward and Reverse).
*/
//define motor1 ports
#define motor1a PORTD.F0
#define motor1b PORTD.F1
//define motor2 ports
#define motor2a PORTD.F2
#define motor2b PORTD.F3
//define controller 1 ports
#define switch_frwd PORTB.F1
#define switch_stop PORTB.F2
#define switch_rvs PORTB.F0
void main()
{
//set I/O port
TRISB = 0XFF;
TRISD = 0X00;
CMCON=0X07; // or CMCON register = 0X00000111
ADCON1=0X07; // Configure ADCON1, or ADCON1=0X06;
switch_frwd = 0X00; //set initial port = 0
switch_frwd = 0X00; //set initial port = 0
switch_frwd = 0X00; //set initial port = 0
while (1)
{
if(switch_frwd == 1) //If the switch is pressed
{
motor1a = 0;
motor1b = 1; //Motor Forward
Delay_ms(30); //1 Second Delay
}
else
if (switch_rvs == 1) //If the switch is pressed
{
motor1a = 1;
motor1b = 0; //Motor Reverse
Delay_ms(30); //1 Second Delay
}
else
if (switch_stop == 1) //If the switch is pressed
{
motor1a = 0;
motor1b = 0; //Motor Stop
Delay_ms(30); //1 Second Delay
}
if(switch_frwd == 1) //If the switch is pressed
{
motor2a = 0;
motor2b = 1; //Motor Forward
Delay_ms(30); //1 Second Delay
}
else
if (switch_rvs == 1) //If the switch is pressed
{
motor2a = 1;
motor2b = 0; //Motor Reverse
Delay_ms(30); //1 Second Delay
}
else
if (switch_stop == 1) //If the switch is pressed
{
motor2a = 0;
motor2b = 0; //Motor Stop
Delay_ms(30); //1 Second Delay
}
}
}