#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC=0X00; // portC as input
DDRD=0XFF; // portD as output
int i;
while(1)
{
if((PINC&0x01)==0)
{
PORTD=0xff;
_delay_ms(200);
PORTD=0x00;
_delay_ms(200);
}
else if ((PINC&0X02)==0)
{
PORTD=0XAA;
_delay_ms(200);
PORTD=0X55;
_delay_ms(200);
}
else if((PINC&0X04)==0)
{
PORTD=0X01;
_delay_ms(200);
for (i=0;i<7;i++)
{
PORTD=PORTD<<1;
_delay_ms(200);
}
}
else if ((PINC&0x08)==0)
{
PORTD=0x80;
_delay_ms(200);
for (i=0;i<7;i++)
{
PORTD=PORTD>>1;
_delay_ms(200);
}
}
}
}
No comments:
Post a Comment