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 timer programing

Status
Not open for further replies.

aliraza786

Full Member level 4
Joined
Nov 10, 2009
Messages
210
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,298
Location
Lahore, Pakistan, Pakistan
Activity points
2,914
hello ...i need some help in gnerating time delay of exact 5 second
does this code is corect..?? but in simulation and in hardware it does not work ...
_______________________________________________________________________
#include<reg51.h>
unsigned char Ali[9]={0,1,2,4,8,16,32,64,128};
sbit led=P1^1; unsigned char k,i;
void delay()
{
TMOD=0x02;
TL0=0x67;
TH0=0xFC;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

void main()
{
led=0;
for(i=0;i<5000;i++)

{ delay(); }
led=1;
for(k=0;k<5000;k++)
{ delay(); }
}
main while loop is missing in this code but after ading the main while loop problem is not solved....!!!
 
Last edited:

What is i???
Is it a char, int, long??? I think you didn't declare it. Dont forget to declare it as int. :) :)
Let me know, if the problem still persist
 
#include<reg51.h>
unsigned char Ali[9]={0,1,2,4,8,16,32,64,128};
sbit led=P1^1; unsigned char k,i;
void delay()
{
TMOD=0x02;
TL0=0x67;
TH0=0xFC;
TR0=1;
...
...

What is i???
Is it a char, int, long??? I think you didn't declare it. Dont forget to declare it as int. :) :)
Let me know, if the problem still persist

Aliraza786 has declared variable 'i' as an unsigned char. And scorrpeio is correct it needs to be declared as an integer (int).

Otherwise the for loop:

Code:
for(i=0;i<5000;i++)

will infinitely loop, due to the fact variable 'i' will constantly roll over from 255 to 0 without reaching 5000.

BigDog
 
Last edited:
thnk you i have solved this problem...the problem is of int exactly ...thnk you for your early reaply....
int is of 16 bits and char is of 8 bits so the maximum number posible with char is 256 which is not in the range of 1000 so we cannot use char we have to use int to count more then 256....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top