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 / Replies / here is the code: // Program

here is the code: // Program

|

Microcontroller › 8051 › interfacing servo motor with 8051 › here is the code: // Program

January 26, 2015 at 3:06 pm #12542
Iqbal Muhammad
Participant

here is the code:

 

// Program to rotate servo by 5 degree from previous position starting from 0 degree
 
// 0 degree = 700us 
// 180 degree = 5500us
// Timer1 pulse after 50us -23
 
#include<reg51.h>
sbit output=P1^0;   //Output to motor
int count;
 
void delay(unsigned int msec)   // Function for delay
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
} 
 
void timer(int msec) // Function for timer
{
int i;
TR1=1;
for(i=0;i<msec;i++)
{
while(TF1==0);
TF1=0;
}
TR1=0;
}
void main()
{
int i;
TMOD=0x20; // Mode2
TH1= -23; // 50usec timer
output=0;
count=14;
while(1)
{
if(count>=100)
count=14;
else
count=count+5;
for(i=0;i<200;i++)
{
output=1;
timer(count);
output=0;
timer(360);
}
delay(100);
}
}

RSS Recent Posts

  • Measuring controller current output with a meter December 13, 2025
  • Oshonsoft MSSP simulation question December 13, 2025
  • What is involved to convert a small town to fiber optic? December 12, 2025
  • Droplet1 December 12, 2025
  • Help to Identify capacitor fault December 12, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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