Sunday, July 18, 2010

Mikrokontoroler test wIth LED

This program I created for it using AVR studio where this program turn the fruit led eight couples who pins on PORTD

#include
#include

void kanan() //arah geral led kekanan
{
DDRD=0xff; //set pin D
int i;        // i inisilisai
for (i=1 ;i<=128; i=i*2)
{
PORTD=i;    // i inisilisai
_delay_ms(500);
}
}
void kiri() //arah geral led kekiri
{
DDRD=0xff; //set pin D
int  i;  // i inisilisai
for (i=128; i>1 ; i -=i/2)
{
PORTD=i;  // i inisilisai
_delay_ms(500);
}
}
void blink()
{
unsigned char i= 0 ;
for (i=0;i<8;i++)
{
PORTD=0xff;
_delay_ms(500);
_delay_ms(500);
PORTD=0×00;
_delay_ms(500);
_delay_ms(500);
}
}
int main() // tempat beraksi
{
while(1)
{
kiri();
kanan();
_delay_ms(500);
_delay_ms(500);
blink();
_delay_ms(500);
_delay_ms(500);
kanan();
kiri();
_delay_ms(500);
_delay_ms(500);
blink();
_delay_ms(500);
_delay_ms(500);
}
return(0);
}

1 comment: