free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes :: Forums :: Discuss and Learn :: 8051 Discussion Forum
 
<< Previous thread | Next thread >>
A little bit of a problem with while loop..
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
Judgement
Wed Jul 02 2008, 10:53PM
 User Offline
Registered Member #7820
Joined: Tue May 13 2008, 03:30PM

Posts: 28
Thanked 0 times in 0 posts
How do I use the internal timer in the 8051 for my programs? I need to use it to send a delayed SMS.


edit: I've changed the thread title. Before, I was asking on how to use the internal timer.



[ Edited Sun Jul 06 2008, 05:03AM ]
Back to top


sashijoseph
Thu Jul 03 2008, 05:28AM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 524
Thanked 124 times in 117 posts
You would need to first initialise certain registers.
The TMOD register has to be 1st loaded with a value indicating which(of the 4) modes the timer will use.
If 16 bit mode(mode 1) is used,the TH and TL registers are to be loaded with an initial value from which the up count starts.In 16 bit mode the timer can count from 0x00 to 0xffff.So say you load TH and TH with 0x2B and 0x2C respectively,then the timer will start counting from 0x2B2C to 0xFFFF.
Now each count represents some fixed amount of delay(depending on the xtal),say d.Thus the total delay would be the total no. of counts * d.In the above case ( FFFF-2B2C) * d.
d can be found by dividing the xtal frequency by 12 and dividing 1000000 by the derived value to arrive at 'd' in micro seconds.
For eg. with a 11059200Hz xtal.....
11059200/12= 921600.
1000000/921600 = 1.085 us

Thus after every 1.085us the timer will increment.
Plz read the datasheet for more info.

[ Edited Thu Jul 03 2008, 05:30AM ]

Let there be music........
Back to top



This post has been thanked 1 time
 Judgement 
Judgement
Thu Jul 03 2008, 05:49AM
 User Offline
Registered Member #7820
Joined: Tue May 13 2008, 03:30PM

Posts: 28
Thanked 0 times in 0 posts
Thanks. Uh..about the datasheet..I don't see it.
Back to top


sashijoseph
Thu Jul 03 2008, 08:34AM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 524
Thanked 124 times in 117 posts
Yes you're right... the Atmel datasheet doesn't have it.
Use this tut instead http://www.8052.com/tuttimer.phtml

Let there be music........
Back to top



This post has been thanked 1 time
 Judgement 
Judgement
Sun Jul 06 2008, 05:08AM
 User Offline
Registered Member #7820
Joined: Tue May 13 2008, 03:30PM

Posts: 28
Thanked 0 times in 0 posts
Thanks. But now I have another problem. I can't end my while loop using return(1);
It always gives me an error. Is there any way I can solve this? Or is there any alternative I can take?

void read_sms(void)
{
int r,y;
r=0; y=0;

while(y!=1)
{
int r=0;
for(r=0;r<13;r++)
{
tx0(readsms[r]);
}
}
}


How can I stop the while loop? Thanks..
Back to top


pdi33
Sun Jul 06 2008, 05:25AM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 621
Thanked 135 times in 131 posts
well, u have to set the integer y to 1 to come out of the loop. The condition would be that u do that within the read_sms() function as the variable is local and will not be modified but instead stored and regained if u try setting that variable in the interrupt routine. The best thing would be to define the variable outside the routine (global variable and i think ur problem would be solved.

Ps.
if ur tx0() function is returning a 1 then just modify ur instruction to:
y = tx0(readsms[r]);


[ Edited Sun Jul 06 2008, 05:28AM ]

* inspired to develop,developing to inspire *
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems