Microcontroller › 8051 › HOw to interface servo motor with 8051?
- This topic has 7 replies, 4 voices, and was last updated 10 years, 6 months ago by
Vara Ashishkumar.
-
AuthorPosts
-
August 22, 2015 at 8:10 pm #3925
Embedded_pic
ParticipantHi all,
i'm trying to interface a servo motor with a 8051 mcu.
so i tried this code, when i compile i have an errot at line:
void extr0(void) interrupt 0
the error message is: INT.C(33): error C141: syntax error near 'void'
Here is the code:
#include<regx51.h>
sbit servomotor_pin=P1^0;
void delay(unsigned int);
void servo_delay(unsigned int);//Timer
void timer(int msec) // Function for timer
{
int i;
for(i=0;i<msec;i++){
TMOD=0x20; // Mode2
TH1=0xFF;
TL1=0xD1;
//TH1= -23; // 50usec timer
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
}void main()
{
int i;
IE=0x85;
servomotor_pin=0x00;
// Activating both the interrupts EX0 and EX1//Subroutine EX0 with interrupt number '0'
void extr0(void) interrupt 0
{
P0=0xff;
//Your command goes here
while(1)
{
//anticlockwise direction
for(i=0;i<500;i++)
{
servomotor_pin=1;
timer(20);
servomotor_pin=0;
timer(360);
}
}
}void extr1(void) interrupt 2 //Subroutine EX1 with Interrupt Number '1'
{
P0=0x00;
// turn to 0°}
}August 23, 2015 at 8:31 am #13208Prabakaran P M
ParticipantAugust 23, 2015 at 1:13 pm #13210Embedded_pic
ParticipantHi,
thank you but the link shows me for stepper motor and not servo motor.
August 23, 2015 at 3:04 pm #13211Prabakaran P M
ParticipantHi, Here is the link for servo motor interface
http://www.engineersgarage.com/microcontroller/8051projects/servo-motor-project-circuit
August 23, 2015 at 3:22 pm #13212Rahul Tungar
Participantyou can not write ISR inside main.. isr code should be outside of your main function.
flow should be lyk this
void main()
{
//basic initialisation as per your hardware
//configure and enable interrupts
while(1);
}
void extr1(void) interrupt 0
{
//your ISR CODE
}
void extr0(void) interrupt 2
{
//your another ISR CODE
}
August 24, 2015 at 8:07 pm #13214Embedded_pic
ParticipantNo one of the answer is correct, i'm still stuck with my code.
Any help please, thank you
August 25, 2015 at 8:23 pm #13218Embedded_pic
ParticipantAll answers were too complicated for me, i figured out using NE555 with 8051. without any timer and delay.
thank you
August 27, 2015 at 12:15 pm #13222Vara Ashishkumar
ParticipantHey Embedded_pic,
Closed void main loop by curly bracket ( ' } ' ) before line void extr0(void) interrupt 0 and remove the last curly breaket at end of the code.Then compile it.
-
AuthorPosts
- You must be logged in to reply to this topic.