- This topic has 7 replies, 4 voices, and was last updated 9 years ago by .
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › HOw to interface servo motor with 8051?
Hi 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°
}
}
Hi,
thank you but the link shows me for stepper motor and not servo motor.
Hi, Here is the link for servo motor interface
http://www.engineersgarage.com/microcontroller/8051projects/servo-motor-project-circuit
you 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
}
No one of the answer is correct, i'm still stuck with my code.
Any help please, thank you
All answers were too complicated for me, i figured out using NE555 with 8051. without any timer and delay.
thank you
Hey 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.