使用单片机能够做出各种把戏的流水灯作用,从前就见有人用一片STC89C52单片机接了32个LED,做成一个心的形状,然后送给了女朋友。呵呵~~
使用c言语的数组功用就能够完成把戏流水灯的规划,只要把每种活动方法的代码写进数组,顺次从数组取出显现就能够了。想要多少把戏都由你说了算!
源代码:
/*
* 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();
}
}
}
作用图: