dsk2858
Member level 2

- Joined
- Aug 17, 2011
- Messages
- 47
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Chennai,India
- Activity points
- 1,683
#include<avr/io.h>
#include<util/delay.h>
void delay_ms(unsigned int d)
{
_delay_ms(d);
}
int main(void)
{
DDRB=0x00;
DDRC=0xFF;
while(1)
{
if(PINB==0x01)
{
PORTC=0x03;
delay_ms(10000);
PORTC=0x00;
}
if(PINB==0x02)
{
PORTC=0x01;
}
}
return 0;
}
for that purpose i am using #include<util/delay.h> header file.
the program is being compiled and hex file was genereted . i am simulating this by using PROTUS ISIS profetional.
but when i am pressing the button the led is not blinking more than 1second even less.
could you please help me regarding this problem
#define F_CPU 20000000UL // Specifies a system clock of 20MHz
// CylonEyes.c
#include <avr/io.h>
// The last character is a lower case ‘L’ not a 1 (one)
#define F_CPU 20000000UL
#include <util/delay.h>
int main (void)
{
int i = 0;
// set PORTD for output
DDRD = 0xFF;
while(1) {
for(i = 1; i < 128; i = i*2)
{
PORTD = i;
_delay_loop_2(30000);
}
for(i = 128; i > 1; i -= i/2)
{
PORTD = i;
_delay_loop_2(30000);
}
}
}
Mr BigDog
i gone through ur profile i found that ur also familiar with AVR.
i am using AVR studio-4 to blink an led for 10seconds
when a button is pressed connected to PORTB.
for that purpose i am using #include<util/delay.h> header file.
the program is being compiled and hex file was genereted . i am simulating this by using PROTUS ISIS profetional.
but when i am pressing the button the led is not blinking more than 1second even less.
CODE:
Code:#include<avr/io.h> #include<util/delay.h> void delay_ms(unsigned int d) { _delay_ms(d); } int main(void) { DDRB=0x00; DDRC=0xFF; while(1) { if(PINB==0x01) { PORTC=0x03; delay_ms(10000); PORTC=0x00; } if(PINB==0x02) { PORTC=0x01; } } return 0; }
could you please help me regarding this problem
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
void delay_ms(unsigned int d)
{
_delay_ms(d);
}
int main (void)
{
// set PORTC for output
DDRC = 0xFF;
while(1)
{
PORTC=0xFF;
_delay_ms(10000);
PORTC=0X00;
_delay_ms(10000);
}
return 1;
}
i tried the example which you had attached it was working correctly.but again i tried to glow LED's connected to PORTC for 10seconds delay and off fof 10seconds.
when i simulated it on ISIS simulator i found that LED's where glowing only for 8seconds.
With a 8MHz crystal oscillator what is the maximum delay we can produce:?:. Is there any formula to calculate:?:
Perform a delay of \c __ms milliseconds, using _delay_loop_2().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one,
_delay_ms() provides a decreased resolution functionality. In this
mode _delay_ms() will work with a resolution of 1/10 ms, providing
delays up to 6.5535 seconds (independent from CPU frequency). The
user will not be informed about decreased resolution.
Perform a delay of \c __ms milliseconds, using _delay_loop_2().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one,
_delay_ms() provides a decreased resolution functionality. In this
mode _delay_ms() will work with a resolution of 1/10 ms, providing
delays up to 6.5535 seconds (independent from CPU frequency). The
user will not be informed about decreased resolution.
#include <avr/io.h>
#define F_CPU 8000000UL// F-CPU frequency should be mentioned before calling the delay header preprocesser function i.e.,#include<util/delay.h>
#include <util/delay.h>
void delay_ms(unsigned int d)
{
_delay_ms(d);
}
int main (void)
{
DDRC = 0xFF; // set PORTC for output
while(1)
{
PORTC=0xFF;//Glow all the LED's for 10 seconds
_delay_ms(6000);//as maximum delay can be produced is upto 6.58627s only
_delay_ms(4000);
PORTC=0X00;// off the LED's for 5seconds
_delay_ms(5000);
}
return 0;
}
Thank you for your explanations , i executed the delay program with 6s this time it is getting executed. to achieve 10s i added two delay loops.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?