Sathiesh Kumar
New Member
Hi...
I would like to rotate the motor in forward and backward direction.Motor is connected to portD .By sending a Numbers(eg..1) from PC Hyperterminal it should activate the motor .. I have attached six motors in PORTD and PORTC.. I am attaching the sample code which i tested but it doesnt seem to work...
Check this code and kindly suggest any changes...
Sathiesh Kumar.V
I would like to rotate the motor in forward and backward direction.Motor is connected to portD .By sending a Numbers(eg..1) from PC Hyperterminal it should activate the motor .. I have attached six motors in PORTD and PORTC.. I am attaching the sample code which i tested but it doesnt seem to work...
Check this code and kindly suggest any changes...
Code:
void door_open(unsigned char);
void door_close(unsigned char);
char gate_sel;
void main() {
TRISD=0;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
gate_sel = UART1_Read(); // read the received data,
delay_ms(500);
switch (gate_sel) //Input from PC Hyperterminal o select Gate
{
case 1: door_open(1); //Funcion to Open the door1
delay_ms(5000);
door_close(1); //Function to close the door1
delay_ms(5000);
break;
case 2: door_open(2); //Funcion to Open the door1
delay_ms(5000);
door_close(2); //Function to close the door2
delay_ms(5000);
break;
case 3: door_open(3); //Funcion to Open the door3
delay_ms(5000);
door_close(3); //Function to close the door3
delay_ms(5000);
break;
case 4: door_open(4); //Funcion to Open the door4
delay_ms(5000);
door_close(4); //Function to close the door4
delay_ms(5000);
break;
case 5: door_open(5); //Funcion to Open the door5
delay_ms(5000);
door_close(5); //Function to close the door5
delay_ms(5000);
break;
case 6: door_open(6); //Funcion to Open the door6
delay_ms(50000);
door_close(6); //Function to close the door6
delay_ms(50000);
break;
}
}
}
}
void door_open(unsigned char sel)
{
switch (sel)
{
case 1: PORTD=0x02; //Motor 1 Pos-D1 , Neg-D0
break;
case 2: PORTD=0x08; //Motor 2 Pos-D3 , Neg-D2
break;
case 3: PORTD=0x20; //Motor 3 Pos-D5 , Neg-D4
break;
case 4: PORTD=0x80; //Motor 4 Pos-D7 , Neg-D6
break;
case 5: PORTC=0x02; //Motor 5 Pos-C1 , Neg-C0
break;
case 6: PORTC=0x08; //Motor 6 Pos-C3 , Neg-C2
break;
}
}
void door_close(unsigned char sel)
{
switch (sel)
{
case 1: PORTD=0x01; //Motor 1 Pos-D0 , Neg-D1
break;
case 2: PORTD=0x04; //Motor 2 Pos-D2 , Neg-D3
break;
case 3: PORTD=0x10; //Motor 3 Pos-D4 , Neg-D5
break;
case 4: PORTD=0x40; //Motor 4 Pos-D6 , Neg-D7
break;
case 5: PORTC=0x01; //Motor 5 Pos-C0 , Neg-C1
break;
case 6: PORTC=0x04; //Motor 6 Pos-C2 , Neg-C3
break;
}
}
Sathiesh Kumar.V