AVR單片機(jī)-流水燈2
利用c語(yǔ)言的數(shù)組功能就可以實(shí)現(xiàn)花樣流水燈的設(shè)計(jì),只要把每種流動(dòng)方式的代碼寫(xiě)進(jìn)數(shù)組,依次從數(shù)組取出顯示就可以了。想要多少花樣都由你說(shuō)了算!
本文引用地址:http://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++)//從左到右依次點(diǎn)亮
{
PORTA=~temp;
delay();
delay();
delay();
temp<<=1;
}
temp=0b10000000;
for(i=0;i<9;i++)////從右到左依次點(diǎn)亮
{
PORTA=~temp;
delay();
delay();
delay();
temp>>=1;
}
for(i=0;i<22;i++)
{
PORTA=~led0[i];
delay();
delay();
delay();
}
}
}
效果圖:
評(píng)論