AVR單片機-流水燈2
利用c語言的數(shù)組功能就可以實現(xiàn)花樣流水燈的設計,只要把每種流動方式的代碼寫進數(shù)組,依次從數(shù)組取出顯示就可以了。想要多少花樣都由你說了算!
本文引用地址:http://m.butianyuan.cn/article/201611/323497.htm源代碼:
/*
* LED1.c
*
* Created: 2011-6-24 15:29:32
* Author: ZYIN
*/
#include <avr/io.h>
unsigned char led0[]={0x81,0x42,0x24,0x18,0x00,0x18,0x24,0x42,0x81,0x00,0x55,0xaa,0x55,0xaa,0x55,0xaa,0xff,0x00,0xff,0x00,0xff,0x00};
void delay(void)
{
unsigned int j;
j=60000;
while(j--);
}
int main(void)
{
DDRF=0xff;
PORTF=0b00001000;
DDRA=0xff;
while(1)
{
char temp;
int i;
temp=0b00000001;
for(i=0;i<9;i++)//從左到右依次點亮
{
PORTA=~temp;
delay();
delay();
delay();
temp<<=1;
}
temp=0b10000000;
for(i=0;i<9;i++)////從右到左依次點亮
{
PORTA=~temp;
delay();
delay();
delay();
temp>>=1;
}
for(i=0;i<22;i++)
{
PORTA=~led0[i];
delay();
delay();
delay();
}
}
}
效果圖:
評論