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 :: AVR Discussion Forum
 
<< Previous thread | Next thread >>
HELP...problems in c code........... atmega 8
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
pravin_35
Mon Dec 22 2008, 11:12PM

 User Offline
Registered Member #13089
Joined: Sat Dec 13 2008, 10:20PM

Posts: 39
Thanked 0 times in 0 posts
hi...... i am new to atmega avr family......... i hav written a code in avr studio to generate somme microsecond delay........... but while debugging its works only one time... its not responding the flag set...... plz help me.............? i also tried via interrupt also same problem............


// generate a us delay //

#include<avr\io.h>


void delay();

int main()
{

SPL=0X00;
SPH=0X04;
while(1)
{

DDRB=0XFF;
PORTB=~PORTB;
delay();
}

return 0;
}




void delay (void)
{
TCNT0=0x00;
TCCR0=0x01;
while (TIFR==0X00);
TIFR =0X01;
}




pravin

Back to top


pdi33
Tue Dec 23 2008, 10:31AM

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

Posts: 773
Thanked 186 times in 181 posts
just change ur overflow flag checking from this:
while (TIFR == 0x00);
to
while ((TIFR & 0x01) == 0x00);

i have checked it on proteus and works well with the mega8.
Also u need to define the data direction of PORTB as output only once during startup so preferably keep it outside the infinite loop . Another point is u need not define the stack pointer in c-programs as the compiler will take care of it much efficiently .




[ Edited Tue Dec 23 2008, 10:34AM ]

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



This post has been thanked 1 time
 pravin_35 
 

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