ATMEGA8 beginner problem

OP #3487115
Rate this post
• ▲ useful
▼ not useful
I'm using ATmega 8 (8L - 8PI) , I am trying to blink two LED's in 
alternate order with legs PB0 and PB6 for each LED's but its not 
working..
1
‪#‎define‬ F_CPU 1000000UL
2

3
‪#‎include‬ <avr/io.h>
4
#include <util/delay.h>
5

6
int
7
main (void)
8
{
9
DDRB |= _BV(DDB0);
10
DDRB |= _BV(DDB6);
11
while(1)
12
{
13
PORTB = 00000001;
14
_delay_ms(500);
15
PORTB = 01000000;
16

17
_delay_ms(500);
18
}
19
}
#3487150
Rate this post
• ▲ useful
▼ not useful
Ajay R. wrote:
> I am new to this(noob),can you please modify my code.

Adopt your main loop to look something like this:
1
PORTB = 0x01;
2
_delay_ms(500);
3
PORTB = 0x40;
4
_delay_ms(500);

Alternatively, if you are using avr-gcc, you can also make use of the 
"0b" notation:
1
PORTB = 0b00000001;
2
_delay_ms(500);
3
PORTB = 0b01000000;
4
_delay_ms(500);

Best regards,
Karol Babioch
OP #3487166
Rate this post
• ▲ useful
▼ not useful
Karol Babioch wrote:
> Ajay R. wrote:
>> Thanks to all of you,its working now :D
>
> Well, you should try to understand what was wrong with your notation in
> order to learn something from your mistake ;).
>
> Best regards,
> Karol Babioch

Karol can you name a book or give a link from where i can learn basic 
AVR,I understood what i did wrong but want to further expand my 
knowledge.
Thanks in advance

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.