ATMEGA16花样流水灯程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include
#include
main()
{
#define T 500
#define W 50
int i;
DDRA=0XFF;
DDRB=0XFF;
DDRC=0XFF;
DDRD=0XFF;
while(1)
{
for(i=1;i<3;i++)//左右闪烁
{
PORTA=0XAA;
PORTB=0XAA;
PORTC=0XAA;
PORTD=0XAA;
_delay_ms(T);
PORTA^=0XFF;
PORTB^=0XFF;
PORTC^=0XFF;
PORTD^=0XFF;
_delay_ms(T);
}
for(i=1;i<3;i++)//向右单排走
{
PORTA=0X01;
PORTB=0X01;
PORTC=0X01;
PORTD=0X01;
_delay_ms(T);
PORTA^=0X03;
PORTB^=0X03;
PORTC^=0X03;
PORTD^=0X03;
_delay_ms(T);
PORTA^=0X06;
PORTB^=0X06;
PORTC^=0X06;
PORTD^=0X06;
_delay_ms(T);
PORTA^=0X0C;
PORTB^=0X0C;
PORTC^=0X0C;
PORTD^=0X0C;
_delay_ms(T);
PORTA^=0X18;
PORTB^=0X18;
PORTC^=0X18;
PORTD^=0X18;
_delay_ms(T);
PORTA^=0X30;
PORTB^=0X30;
PORTC^=0X30;
PORTD^=0X30;
_delay_ms(T);
PORTA^=0X60;
PORTB^=0X60;
PORTC^=0X60;
PORTD^=0X60;
_delay_ms(T);
PORTA^=0XC0;
PORTB^=0XC0;
PORTC^=0XC0;
PORTD^=0XC0;
_delay_ms(T);
}

{//向右双排走并存档
PORTA=0X03;
PORTB=0X03;
PORTC=0X03;
PORTD=0X03;
_delay_ms(T);
PORTA^=0X05;
PORTB^=0X05;
PORTC^=0X05;
PORTD^=0X05;
_delay_ms(T);
PORTA^=0X0A;
PORTB^=0X0A;
PORTC^=0X0A;
PORTD^=0X0A;
_delay_ms(T);
PORTA^=0X14;
PORTB^=0X14;
PORTC^=0X14;
PORTD^=0X14;
_delay_ms(T);
PORTA^=0X28;
PORTB^=0X28;
PORTC^=0X28;
PORTD^=0X28;
_delay_ms(T);
PORTA^=0X50;
PORTB^=0X50;
PORTC^=0X50;
PORTD^=0X50;
_delay_ms(T);
PORTA^=0XA0;
PORTB^=0XA0;
PORTC^=0XA0;
PORTD^=0XA0;
_delay_ms(T);//
PORTA^=0X03;
PORTB^=0X03;
PORTC^=0X03;
PORTD^=0X03;
_delay_ms(T);
PORTA^=0X05;
PORTB^=0X05;
PORTC^=0X05;
PORTD^=0X05;
_delay_ms(T);
PORTA^=0X0A;
PORTB^=0X0A;
PORTC^=0X0A;
PORTD^=0X0A;
_delay_ms(T);
PORTA^=0X14;
PORTB^=0X14;
PORTC^=0X14;
PORTD^=0X14;
_delay_ms(T);
PORTA^=0X28;
PORTB^=0X28;
PORTC^=0X28;
PORTD^=0X28;
_delay_ms(T);//
PORTA^=0X03;
PORTB^=0X03;
PORTC^=0X03;
PORTD^=0X03;
_delay_ms(T);
PORTA^=0X05;
PORTB^=0X05;
PORTC^=0X05;
PORTD^=0X05;
_delay_ms(T);
PORTA^=0X0A;
PORTB^=0X0A;
PORTC^=0X0A;
PORTD^=0X0A;
_delay_ms(T);//
PORTA^=0X03;
PORTB^=0X03;
PORTC^=0X03;
PORTD^=0X03;
_delay_ms(T);
}
for(i=1;i<3;i++)
{
PORTA=0XFF;
PORTB=0x81;
PORTC=0x81;
PORTD=0XFF;
_delay_ms(T);
PORTA&=0x00;
PORTB^=0xFF;
PORTC^=0xFF;
PORTD&=0x00;
_delay_ms(T);
}
PORTA=0X00;
PORTB=0X00;
PORTC=0X00;
PORTD=0X00;
_delay_ms(W);
PORTA|=0x03;
PORTC=0X08;
_delay_ms(W);
PORTA^=0x05;
_delay_ms(W);
PORTA^=0x0A;
_delay_ms(W);
PORTA&=~0x04;
PORTB|=0X08;
_delay_ms(W);
PORTA&=~0x04;
PORTB|=0X08;
PORTB

|=0x40;
_delay_ms(W);
PORTA&=~0x08;
PORTD|=0x08;
_delay_ms(W);
PORTB&=~0x08;
PORTD|=0X10;
_delay_ms(W);
PORTC&=~0x08;
PORTD|=0x20;
_delay_ms(W);
PORTD^=0x48;
_delay_ms(W);//
PORTC|=0X40;
PORTD&=~0x10;
_delay_ms(W);
PORTC|=0X40;
PORTD&=~0x10;
PORTC|=0x08;
_delay_ms(W);//
PORTB|=0x20;
PORTD&=~0x20;
_delay_ms(W);
PORTC|=0x20;
PORTD&=~0x40;
_delay_ms(W);
PORTC^=~0x50;


/////////////////
}

}

相关文档
最新文档