简单点也可以只用1排LED,PINC4上的方向开关最好用滚珠开关,没有买到,只好用废旧鼠标按钮手工操作
用CVAVR.其中设置等等为自动生成的
代码如下:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.6 Evaluation
Automatic Program Generator
?Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : FOR NO EDITCARD!
Version :
Date : 2007-11-1
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega8L
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
// Declare your global variables here
char dsp1,dsp2,dsp3,dsp4; //索引
char word1[8],word2[8],word3[8],word4[8]; //显示数组
const char playdsp[16][8]={{0XF7,0X03,0XFC,0XB7,0X78,0X03,0XDB,0XB3}, //小小字库,自己瞎编的,
{0X7B,0XA3,0XD8,0XA3,0XF6,0X76,0X02,0XF4},
{0XAB,0XDB,0XA3,0X77,0XB8,0XCB,0XBB,0X73},
{0X6B,0X87,0XBB,0X45,0X6E,0X03,0X7B,0X43},
{0XBF,0XC1,0X75,0X95,0XE0,0XD5,0XB5,0X7D},
{0XDB,0XEA,0X01,0XAB,0XD0,0X86,0X76,0X38},
{0XFD,0XF5,0XF4,0X05,0XD5,0XB4,0X85,0XFD},
{0XFF,0XFF,0X03,0X6D,0X6D,0X7D,0X81,0XFF},
{0X87,0X01,0XD7,0X5B,0X80,0XDB,0X83,0X5F},
{0XEF,0X6D,0XA3,0X6D,0X02,0XEE,0XBE,0X6F},
{0XF7,0X78,0X6B,0X6B,0X00,0X6B,0X6B,0X7B},
{0XF7,0X03,0XFC,0X77,0X55,0X00,0X55,0X77},
{0X7B,0XBB,0X9B,0XE0,0XDB,0XBB,0X7B,0X7F},
{0XFF,0XFD,0X15,0X55,0X50,0X55,0X95,0XFD},
{0xf5,0x78,0x05,0x91,0xb8,0xa8,0x02,0x78},
{0XB7,0XD5,0X01,0XD5,0XF6,0XC3,0X7F,0X81}};
// 你//好*//*欢*//*迎*//*庆*//*祝*//*节*//*日*//*快*//*乐*//*生*//*佳*//*大*/
/*吉*//*贺*//*利*/
/////////////////////////////////////////////play
void ply(void) // ok
{
signed char i;
PORTB=0XFF;
DDRB=0;
if ((!PINB.0)&(!PINB.1)&(!PINB.2))//000 拨码开关000,显示:你好欢迎
{
dsp1=0;
dsp2=1;
dsp3=2;
dsp4=3;
}
else if ((PINB.0)&(!PINB.1)&(!PINB.2))//001 拨码开关001,显示:庆祝节日
{
dsp1=4;
dsp2=5;
dsp3=6;
dsp4=7;
}
else if ((!PINB.0)&(PINB.1)&(!PINB.2))//010 拨码开关010,显示:节日快乐
{
dsp1=6;
dsp2=7;
dsp3=8;
dsp4=9;
}
else if ((PINB.0)&(PINB.1)&(!PINB.2))//011 拨码开关011,显示:生日快乐
{
dsp1=10;
dsp2=7;
dsp3=8;
dsp4=9;
}
else if ((!PINB.0)&(!PINB.1)&(PINB.2))//100 拨码开关100,显示:庆贺佳节
{
dsp1=4;
dsp2=14;
dsp3=11;
dsp4=6;
}
else if ((PINB.0)&(!PINB.1)&(PINB.2))//101 拨码开关101,显示:大吉大利
{
dsp1=12;
dsp2=13;
dsp3=12;
dsp4=15;
}
else if ((!PINB.0)&(PINB.1)&(PINB.2))//110 拨码开关110,显示:庆贺生日
{
dsp1=4;
dsp2=14;
dsp3=10;
dsp4=7;
}
else //111 拨码开关111,显示:佳节快乐
{
dsp1=11;
dsp2=6;
dsp3=8;
dsp4=9;
}
for ( i=0; i<=7; i++ )
{
word1=*(playdsp[dsp1]+i); //根据索引从字库查出显示码
word2=*(playdsp[dsp2]+i);
word3=*(playdsp[dsp3]+i);
word4=*(playdsp[dsp4]+i);
}
while(1)
{
while (PINC.4) //move forward loop 1 正相运动
{
delay_ms(10); //延时避免换向开始出现镜像字
for (i=0;i<=7;i++) //顺序显示第1个字的字库显示码
{
PORTD=word1; //依次把显示码送到PORTD就空中刷出字来了
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF; //显示完1个字关闭6毫秒形成字间间隔
delay_ms(6);
for (i=0;i<=7;i++) //类似,显示第2个字
{
PORTD=word2;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
for (i=0;i<=7;i++) //类似,显示第3个字
{
PORTD=word3;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
for (i=0;i<=7;i++) //类似,显示第4个字
{
PORTD=word4;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
}
while (!PINC.4) //move backward loop 2 反向运动时,显示必须从最后一个字最后1列反向显示
{
delay_ms(10); //延时避免换向开始出现镜像字
for (i=7;i>=0;i--) //顺序显示第4个字的字库显示码,从后往前显示一下都类似
{
PORTD=word4;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
for (i=7;i>=0;i--)
{
PORTD=word3;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
for (i=7;i>=0;i--)
{
PORTD=word2;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
for (i=7;i>=0;i--)
{
PORTD=word1;
delay_ms(2);
PORTD=0XFF;
}
PORTD=0XFF;
delay_ms(6);
}
}
}
void main(void) //下面的初始化代码都是cv自动生成添加的仅仅是“ply()”
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=P State6=P State5=P State4=P State3=P State2=P State1=P State0=P
PORTB=0xFF;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=P State3=T State2=T State1=T State0=T
PORTC=0x10;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTD=0xFF;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
while (1)
{
// Place your code here
ply();
};
}
下面的都不错
转自http://www.ouravr.com/bbs/bbs_content.jsp?bbs_sn=979582&bbs_page_no=1&search_mode=1&search_text=摇&bbs_id=9999
奇幻魔术棒,摇出你的精彩!!!
另外有 http://www.ouravr.com/bbs/bbs_content.jsp?bbs_sn=642162&bbs_page_no=1&search_mode=1&search_text=摇&bbs_id=9999
帮朋友小孩做的手摇棒
http://www.cdle.net/bbs/dispbbs.asp?boardid=2&id=17573&page=&star=1
jizzll_617398179 2008-5-3 21:20
用户393407 2008-5-3 14:23