Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to create 1 second delay in uC using timers

Status
Not open for further replies.

indianhits

New Member
Hello Guys can anyone give me the embedded c code to create 1 second delay in uC using timers.

I am using ATMEL AT89S52 with 11.0592MHZ

Thanks!
 
I cannot give you the code, but I can tell you how to do it. Set up your Timer to give a timeout of x milliseconds. Set up a global variable that stores a counter. Set up the interupts to interrupt on Timer overflow. Inside the interrupt service routine, increment the global variable and setup your main code to look to see when the global variable reaches a certain value.

This is all assuming that your Timer cannot produce a delay of 1 second (and you need several loads of your Timer to produce 1 Second delay).

Also look into prescalers to slow down the incrementing of your Timer.

Sorry I cannot be of more assistance, but I am a PIC person (C and assembler)
 
thanks for the answers.i am really confused in setting the timer and if i get an example like setting an 1 sec it will be of much help
 
Here is the code generated by the Delay Calculator/Generator given above, it is a code for a delay of 50ms, repeat it 20 times(run a counter to repeat the code by using a variable) :

//Configure and Enable timer.
//Timer Clk=12/12*1 = 1.0 MHz

SCON = 0x50; //8-bit,rx enable
TL1 = 0xB0; //Lower Byte
TH1 = 0x3C; //Upper Byte
TR1 = 1; //Run timer
 
hey guyz,i'm trying to write a programm using MPLAB IDE and the pic that i'm using is a 16F690 and my program has a delay on it but when i run it it giv me errors saying "symbol not previous defined" and is refering to the registers like status registers,ports and others. Did i mis something in my program?
 
hey guyz,i'm trying to write a programm using MPLAB IDE and the pic that i'm using is a 16F690 and my program has a delay on it but when i run it it giv me errors saying "symbol not previous defined" and is refering to the registers like status registers,ports and others. Did i mis something in my program?

If you would have given the program then it would have been possible to correct the error. Otherwise you can also use Multicalc for Delays and stuff using PIC's.

Document Details | PICMultiCalc (Great PIC Calculator)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top