Discussion Forum

Servo controlling program

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Henry Lui
Posted
9-Jul-2009 10:13 GMT
Toolset
C51
New! Servo controlling program

I've written this program for AT89S52 to control a servo.The signal pin of the servo is connected to the P1_0 of the chips and a LED is connected to the P2_7 of the chip.When I turned the circuit on the servo had no response and only the LED have lit up.Please help me to check if there is any mistake in my program.

#include<AT89X52.h>
unsigned int PWMHIGH;
sbit PWM=P1^0;
void timer0 () interrupt 1
{
   TL0 = (65536- 20000) & 0xFF;                                       //20ms
   TH0 = ((65536-20000) & 0xFF00) >> 8;
   TL1 = (65536-PWMHIGH) & 0xFF;                              //1.5ms
   TH1 = ((65536-PWMHIGH) & 0xFF00)>>8;
   PWM = 1;
   TR1 = 1;
}
void timer1 () interrupt 3
{
   PWM = 0;  TR1 = 0;
}

void main()
{
P2_7=0;
   IE = 0x8A; // EA, Timer0, Timer 1
   // Timer0 , Timer1 Mode1
   TMOD= 0x11;
   PWMHIGH = 1000; // on time
   //timer turn on
   TR0 = 1;
   TF0 = 1;
   while(1);
}
Read-Only
Author
Ahmad mansoor
Posted
10-Jul-2009 07:40 GMT
Toolset
C51
New! RE: Servo controlling program

Thanks my friend ....and I am sorry for late in replay ( it's my week end ) .
anyway I couldn't stop my self from laugh ..
I have tested ur Project1 file and it work very fine ...and I got the right value .
very good at this point . I start the program load the source code and run it inside ,and Ooops i got the wrong value again ...what happen here !!!???
is there a good logical reason for that pls

My friend the best command in basic was GoTo ....
I used it in many ways ...I like this command ,it is the best .

Read-Only
Author
Tamir Michael
Posted
10-Jul-2009 09:05 GMT
Toolset
C51
New! RE: Servo controlling program

My friend the best command in basic was GoTo ....
I used it in many ways ...I like this command ,it is the best

Go on then. What stops you from rushing back to your stomping gound, BASIC?

Read-Only
Author
Per Westermark
Posted
10-Jul-2009 09:14 GMT
Toolset
C51
New! RE: Servo controlling program

Nothing stops you from only having a main(), and build the program flow with if and goto. Maybe you could inline code for most of the CRTL functions too, to avoid having to make function calls out of main().

Read-Only
Author
erik malund
Posted
10-Jul-2009 11:37 GMT
Toolset
C51
New! Per, be careful

some may not realize you are facetious, (I hope and assume you are)

Erik

Read-Only
Author
Tamir Michael
Posted
10-Jul-2009 12:22 GMT
Toolset
C51
New! RE: Per, be careful

A former (female) lecturer (she was a gorgeous babe by the way, not that it matters here. 50% of the class was drooling during classes, including me :-) ) once told us poor students that she has to give an "F" to two other students that handed in a paper in which they replaced the entire contents of a C++ program with a macro called "I love C much more".

Read-Only
Author
Per Westermark
Posted
10-Jul-2009 12:59 GMT
Toolset
C51
New! RE: Per, be careful

Don't everyone have a policy to use at least one goto/hour ;)

I added the reference to replacing the CRTL with inlined goto designs to give a little bit of a hint that goto may not be the best invention in the world.

I'm of the opinion that any repetition in code must be performed with looping constructs (for, while, do ... while), and that any goto construct may only jump forward. This also agrees with the built-in goto-like keywords "continue", "break" and "case".

Read-Only
Author
stephen phillips
Posted
13-Jul-2009 17:57 GMT
Toolset
C51
New! RE: Per, be careful

This reminds me of a CACM letter hmmm
http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF I think it was maybe?

Stephen

Read-Only
Author
Tamir Michael
Posted
13-Jul-2009 19:08 GMT
Toolset
C51
New! RE: Per, be careful

Prof. Dijkstra was a great computer scientist indeed. See here:

One of his most famous algorithms:
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

and about the man:

http://en.wikipedia.org/wiki/Edsgar_Dijkstra

Next Thread | Thread List | Previous Thread Start a Thread | Settings