- This topic has 5 replies, 3 voices, and was last updated 14 years ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.
|
Microcontroller › AVR › how to make running led using atmega16
I have a question to all member in this forum, I want to make the runing led with the atmega16 but I can’t make the programs ??? anyone can help me ? please tell me
how many LEDS to want to interface…
algo for simple running 8 LEDs:
while(1)
{
PORTB=(1<<0);
_delay_ms(100);
PORTB=(1<<1);
_delay_ms(100);
PORTB=(1<<2);
_delay_ms(100);
PORTB=(1<<3);
_delay_ms(100);
PORTB=(1<<4);
_delay_ms(100);
PORTB=(1<<5);
_delay_ms(100);
PORTB=(1<<6);
_delay_ms(100);
PORTB=(1<<7);
_delay_ms(100);
}
I am confused because you have entered above algo is on port B all, if it can be one input (1 pin) is for 8 LED PORTB? or means of PORTB0 to PORTB 7?? please explain, thanks
i dint get you…
are you asking for PORTB=(1<<n);
PORTm is use to send output on port m in avr…
suppose i want to make PB3 means 3rd pin of port B as high and rest all as low i can write it as
PORTB=0b00001000; // b stands for binary…
PORTB=0x80; // here x stand for hexadecimal…
or
PORTB=(1<<PB3);
PORTB=(1<<3);
if you want to put multiple pin as output (in a port) you can use:
PORTm=(1<<n)|(1<<n’)|(1<<n”);
but remember in above statement on n n’ n” pin will be high and rest all will be low…
and if you want to change only a single pin with out affecting the rest of port values use bit wise operation….
i think it is also can be done by
// for left shift
for(i=0;i<6;i++)
{
PORTx = (PORTx<<1);
_delay_ms(1000);
}
// for right shift
for(i=0;i<6;i++)
{
PORTx = (PORTx<<1);
_delay_ms(1000);
}
// for cicular shift
while(1)
{
PORTx = (PORTx<<1)|(PORTx>>7);
_delay_ms(1000);
}
for right shift
PORTx=(PORTx>>1);