Hello everbody i have a proyect with the at898s52, i need a 1 useg delay to generate a square wave
im using keil uvison 3
this is my code:
#include <REGX52.h>
#include <stdio.h>
#include <intrins.h>
void T0Delay(void);
short int a=0;
void uartInit(void);
void main(void){
T0Delay();
uartInit();
Smaller timmings requirements at C compilers must be calibrated empirically.
That´s because optimization levels may affect the way code is implemented at assembly.
However, if I remember correctly, KEIL IDE allow take time measurement during simulations, and you could perform a fine tunning.
since you are using 89S52 with 24MHz
It has its internal clock divier with factor 12
so your system clock will be 2MHz & your machine cycle will be 0.5usec
if try to make any function, its going to take more than 2 machine cycles, so avoid calling fuction
however you van use
_nop_(); (include INTRINS.H in your project file)
whicj will give delay of 0.5usec
use two _nop_() for two time
I agree with andre_teprom... in many previous discussion i have told that you dont get accuracy in C program... but instead you go for asm program to get excat delay....
the reason is also stated clearly as the number of machine cycles taken by processor differs when C is broken down to asm program... and the delay is calculated at assembly level... as it is very easy to get the opcode and machine cycles consumed by the processor for each instruction,,,,
Thats the reason I said nearly accurate not completely accurate, also it depends on the application, for example one can generate a 50 milli sec delay with descent accuracy.
Hey guys I think Hareesh is talking about 1uSec delay..
why are you talking about mSec..
It also depends upon your application, how accurate you want
You can write timer interrupt for 1mSec.. & count it for your application
Just read my post again, I am not misguiding.
Perceptions differ, and I am not responsible for that, if you read my post carefully, you will get the point.
What I am conveying is upto some extent (for example if an application needs only 50 milli sec delay) you can also get somewhat accurate delay even while using C, by using timers.
Just read my post again, I am not misguiding.
Perceptions differ, and I am not responsible for that, if you read my post carefully, you will get the point.
What I am conveying is upto some extent (for example if an application needs only 50 milli sec delay) you can also get somewhat accurate delay even while using C, by using timers.
you could use nop function 1usecond is not possible if you are using 11.0592MHz crystal.. if you use a 12Mhz then if you use nop function you can get 1usec delay and if you use 10 nop function then you get 10usec delay... without interrupt..... but use 12MHz crystal and _nop funtion in keil...........