EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / HOw to interface servo motor with 8051?

HOw to interface servo motor with 8051?

|

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.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • August 22, 2015 at 8:10 pm #3925
    Embedded_pic
    Participant

    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°

      }
      }

    August 23, 2015 at 8:31 am #13208
    Prabakaran P M
    Participant

    HRefer this link http://www.engineersgarage.com/microcontroller/8051projects/stepper-motor-interfacing-with-8051-microcontroller-circuit

    August 23, 2015 at 1:13 pm #13210
    Embedded_pic
    Participant

    Hi,

    thank you but the link shows me for stepper motor and not servo motor.

     

    August 23, 2015 at 3:04 pm #13211
    Prabakaran P M
    Participant

    Hi, 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 #13212
    Rahul Tungar
    Participant

    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

    }

     

    August 24, 2015 at 8:07 pm #13214
    Embedded_pic
    Participant

    No 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 #13218
    Embedded_pic
    Participant

    All 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 #13222
    Vara Ashishkumar
    Participant

    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.

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What diode should I use? March 7, 2026
  • LM016L + PCF8574 I2C Backpack Schematic with Backlight Control March 7, 2026
  • Expensive hobby March 7, 2026
  • USING EASYEDA BUT SOMETHING ISN'T RIGHT? March 7, 2026
  • What is this component and what is its function? March 6, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise