Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 c programmin Codes For Delay generating

Status
Not open for further replies.
//*program for generate toogle condition in between 950 microsec and 50 microseconds in two pins*//
#include<reg52.h>

void T0M2Delay(void);
P1=0xff;
sbit mybit=P1^7;

void main(void)
{

while(1)
{
P1=0xff; //*making port p1 high*//
T0M2Delay(); //keep it for 1 millisec//
mybit=~mybit; //make 7th bit low//
T0M2Delay2();//keep it for 50 us//

}
}
//*for generating 950us delay*//
void T0M1Delay(void)
{
/Replace x with timer no.
//Configure and Enable timer.
//Timer Clk=12/12*1 = 1.0 MHz
SCON = 0x50; //8-bit,rx enable
TLx = 0x0; //Lower Byte
THx = 0x0; //Upper Byte
TRx = 1; //Run timer
}
//* for generating 50ms delay
void T0M2Delay2(void)
{
//Replace x with timer no.
//Configure and Enable timer.
//Timer Clk=12/12*1 = 1.0 MHz
SCON = 0x50; //8-bit,rx enable
TLx = 0x0; //Lower Byte
THx = 0x0; //Upper Byte
TRx = 1; //Run timer
}


I write this program for generate delay in 950 microseconds(hig pulse) and generate 50 Us(low pulse) using AT89c52. is this correct?
 

No .. It is wrong. The two functions you wrote there for the two time delays will produce only one delay for certain amount of time which depends on your oscillator frequency. what is your oscillator frequency?
 

Xtal Frequency is 12 MHz

---------- Post added at 17:48 ---------- Previous post was at 17:41 ----------

Can you send me the correct code??
 

You are running a 8 bit timer according to the code . so it means that the timer will run upto FF(ie 255) ant a roll over(I hope you know what is roll over!) ie 256 cycles. At 12 Mhz , it creates a time delay of 1.085uS . so 1.085*256=277uS.Youtr timer will run for this time only. Moreover you don need to use TL in 8 bit mode. Please refer the book mazidi . Its a perfect book for begineers.

---------- Post added at 17:55 ---------- Previous post was at 17:53 ----------

You do it.. Making mistake and learning will make you stronger in that concept. I will not write the code .
 

thanks..i wil try my best to write it....Thank u for spend time for me..
 

I use to write in assembly so my reply may not help you completely.

If you like that one timer does the job:

(1) First, the output pin is initialized as 1 for example
(2) The timer THx and TLx are initialized as -950 (since the cycle time is 1us)
Note: -950 = 65536 - 950 (which is 2 bytes, high and low)
Note: for precise timing an offset should be added to -950 (to decrease its value, see below)
(3) ETx and TRx are finally set to 1

(4) In the interrupt subroutine of TimerX:
(4a) At its entry, the output pin is toggled
(4b) TRx=0, to halt the counter
(4c) The output pin is checked
(4c1) if 0, THx and TLx are set to -50 (also 2 bytes + its offset, see below)
(4c2) if 1, THx and TLx are set to -950 (+ its offset, see below)
(4d) TRx=1, to reactivate the counter
(4e) RETI

The time offset to be added is the time after TRx=0 up to TRx=1 in each path which may differ a bit for case 0 and case 1.

Hope it helps in a way.

Kerim

Edited: I forgot to say that the timerX mode should also be set in TMOD; M1x=0 and M0x=1 (Mode 1)
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top