Hello everyone, new to this site and coding (moved from stack overflow due to too many sarcastic people).
I am writing a code to control a stepper motor to act as a barrier for a car park;
the motor has to rotate 90* to open and close the gate - via a button (manual operation) and sensors (auto operation)
Although what i have at the moment does not appear to work. What i need at the moment is for someone to tell me how to get it turning 90 degrees both ways by clicking a button for each direction.
Code so far;
void main() {
ANSEL = 0;
ANSELH = 0;
TRISC = 0; // these two essentially enable PORTC to be used
PORTC = 0; // ^
PORTD = 0; // this is to allow for PORTD to be used as control buttons
TRISD.B0 = 1; // setting up PORTD bit 0 as a control button
TRISD.B1 = 1; // setting up PORTD bit 1 as a control button
if (PORTD.B0 == 1); // this should only do this line of code if PORTD bit 0 is pressed
do {
PORTC = 0x09;
Delay_ms(100);
PORTC = 0x0c;
Delay_ms(100);
PORTC = 0x06;
Delay_ms(100);
PORTC = 0x03;
Delay_ms(100);
} while (0);
if (PORTD.B1 == 1); // for some reason it only rotates one way and stops when bit 1 is pressed
do {
PORTC = 0x03;
Delay_ms (100);
PORTC = 0x06;
Delay_ms (100);
PORTC = 0x0c;
Delay_ms (100);
PORTC = 0x09;
Delay_ms (100);
} while (0);
Please be patient with me as i am new to coding but i could really do with the help.
Thank you
I am writing a code to control a stepper motor to act as a barrier for a car park;
the motor has to rotate 90* to open and close the gate - via a button (manual operation) and sensors (auto operation)
Although what i have at the moment does not appear to work. What i need at the moment is for someone to tell me how to get it turning 90 degrees both ways by clicking a button for each direction.
Code so far;
void main() {
ANSEL = 0;
ANSELH = 0;
TRISC = 0; // these two essentially enable PORTC to be used
PORTC = 0; // ^
PORTD = 0; // this is to allow for PORTD to be used as control buttons
TRISD.B0 = 1; // setting up PORTD bit 0 as a control button
TRISD.B1 = 1; // setting up PORTD bit 1 as a control button
if (PORTD.B0 == 1); // this should only do this line of code if PORTD bit 0 is pressed
do {
PORTC = 0x09;
Delay_ms(100);
PORTC = 0x0c;
Delay_ms(100);
PORTC = 0x06;
Delay_ms(100);
PORTC = 0x03;
Delay_ms(100);
} while (0);
if (PORTD.B1 == 1); // for some reason it only rotates one way and stops when bit 1 is pressed
do {
PORTC = 0x03;
Delay_ms (100);
PORTC = 0x06;
Delay_ms (100);
PORTC = 0x0c;
Delay_ms (100);
PORTC = 0x09;
Delay_ms (100);
} while (0);
Please be patient with me as i am new to coding but i could really do with the help.
Thank you