摇摇棒程序注释已完成.docx
- 文档编号:28329698
- 上传时间:2023-07-10
- 格式:DOCX
- 页数:13
- 大小:685.95KB
摇摇棒程序注释已完成.docx
《摇摇棒程序注释已完成.docx》由会员分享,可在线阅读,更多相关《摇摇棒程序注释已完成.docx(13页珍藏版)》请在冰豆网上搜索。
摇摇棒程序注释已完成
LED摇摇棒的详细制作资料
大家知道,人的眼睛存在视觉暂留现象,正因为眼睛的反应迟钝,才丰富了人的视觉感受。
LED摇摇棒很好地利用了人眼的视觉暂留特性。
下图是基于51单片机控制、16只高亮度LED发光二极管构成的摇摇棒,配合手的左右摇晃就可呈现一幅完整的画面,可以显示字符、图片等。
演示效果见自制LED摇摇棒展示【图】。
实物外形图:
基本原理与硬件电路设计:
16只LED发光管作为画面每一列的显示,左右摇晃起到了扫描的作用,人眼的视觉暂留现象使得看到的是一幅完整的画面。
与LED点阵的显示有几分相仿。
硬件电路如下图(点击可放大)。
系统电源VCC为5V,下载程序和调试时一定要保证5V电压,实际使用时用3节干电池串联4.5V即可。
AT89S52单片机作为控制器,在它的P0、P2口接有16只以共阳的方式连接的高亮度LED,由单片机输出低电平点亮。
P0口的上拉电阻RA1不能少。
串在LED公共端的二极管D1会产生一定的压降,用来保护LED,经实测LED点亮时两端电压为3V左右,在LED的安全承受范围内。
K1是画面切换开关,用于切换显示不同内容;S1为水银开关。
水银开关的作用:
棒在摇动时,只能在朝某一方向摇动时显示,否则会出现镜像字或镜像画面,所以通过接一只水银开关来控制,使摇摇棒从左向右摇动时将内容显示出来。
硬件制作:
使用的是直径5mm的红色高亮LED,感觉太大了些,远看效果很好但近看时字不够连贯。
建议使用直径为3mm的高亮LED,颜色可根据个人喜好选择。
水银开关里的水银珠很活跃,导致在接通时容易产生抖动,所以将水银开关斜向上放置(尖尖朝斜上方45°角),靠水银珠自身重力的作用减少抖动:
IC座里面隐藏元件,既美观又能保护元件:
软件设计:
/**********************************************************
程序名称:
LED摇摇棒显示64*16像素
简要说明:
外部中断方式INT0显示;取模方式:
纵向取模、字节倒序
编写:
JiangX.net
最后更新:
08/11/15晚
**********************************************************/
#include
#defineucharunsignedchar
#defineuintunsignedint//宏定义
#defineKEYP3_0//定义画面切换按键
ucharKY;//KY作用在后面说明
uchardisp;//显示汉字指针
ucharpic=0,num=0;//pic为按键次数;num为中断次数
ucharcodelove[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,
0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,
0x04,0x10,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x04,0x10,0xF8,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x20,0x00,0x10,
0x00,0x08,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,
0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*LOVE*/
};
ucharcodeloveyou[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0x00,0xFC,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,
0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,
0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*心形图案*/
};
ucharcodehehe[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,
0xF0,0x0F,0x08,0x10,0x04,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,
0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x20,
0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,
0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x04,0x20,0x08,0x10,
0xF0,0x0F,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*呵呵o(∩_∩)o图案*/
};
unsignedcharcodehanzi[]={
//--欢--
0x04,0x10,0x34,0x08,0xC4,0x06,0x04,0x01,
0xC4,0x82,0x3C,0x8C,0x20,0x40,0x10,0x30,
0x0F,0x0C,0xE8,0x03,0x08,0x0C,0x08,0x10,
0x28,0x60,0x18,0xC0,0x00,0x40,0x00,0x00,
//--迎--
0x40,0x00,0x42,0x40,0x44,0x20,0xC8,0x1F,
0x00,0x20,0xFC,0x47,0x04,0x42,0x02,0x41,
0x82,0x40,0xFC,0x7F,0x04,0x40,0x04,0x42,
0x04,0x44,0xFE,0x63,0x04,0x20,0x00,0x00,
//--使--
0x40,0x00,0x20,0x00,0xF8,0xFF,0x07,0x00,//64
0x04,0x80,0xF4,0x43,0x14,0x45,0x14,0x29,
0x14,0x19,0xFF,0x17,0x14,0x21,0x14,0x21,
0x14,0x41,0xF6,0xC3,0x04,0x40,0x00,0x00,
//--用--
0x00,0x80,0x00,0x60,0xFE,0x1F,0x22,0x02,//92
0x22,0x02,0x22,0x02,0x22,0x02,0xFE,0x7F,
0x22,0x02,0x22,0x02,0x22,0x42,0x22,0x82,
0xFF,0x7F,0x02,0x00,0x00,0x00,0x00,0x00,
//--神--
0x08,0x01,0x88,0x00,0x49,0x00,0xEE,0xFF,//128
0x58,0x00,0x88,0x00,0x00,0x00,0xF8,0x1F,
0x88,0x08,0x88,0x08,0xFF,0xFF,0x88,0x08,
0x88,0x08,0xFC,0x1F,0x08,0x00,0x00,0x00,
//--奇--
0x40,0x00,0x40,0x00,0x44,0x00,0x44,0x3E,
0x64,0x12,0x54,0x12,0x4C,0x12,0x47,0x12,
0x4C,0x3F,0x54,0x42,0x74,0x80,0xC6,0x7F,
0x44,0x00,0x60,0x00,0x40,0x00,0x00,0x00,
//--魔--
0x00,0x40,0x00,0x30,0xFE,0x8F,0x4A,0x80,
0xAA,0x5F,0x9A,0x4A,0xFE,0x2A,0xAA,0x1A,
0xCB,0x0F,0xAA,0x7A,0xFE,0x8A,0x9A,0xAA,
0xAA,0x8F,0x6B,0x80,0x22,0xE0,0x00,0x00,
//--幻--
0x80,0x20,0xC0,0x30,0xA0,0x28,0x98,0x24,
0x87,0x22,0x80,0x21,0xC4,0x30,0x04,0x60,
0x04,0x00,0x04,0x20,0x04,0x40,0x04,0x80,
0x04,0x40,0xFE,0x3F,0x04,0x00,0x00,0x00,
//--摇--
0x10,0x02,0x10,0x42,0x10,0x81,0xFF,0x7F,
0x90,0x04,0x54,0x05,0xCC,0xF4,0xB4,0x44,
0x84,0x44,0xBC,0x7F,0x82,0x44,0xA2,0x44,
0x9B,0xF4,0x82,0x06,0x00,0x04,0x00,0x00,
//--摇--
0x10,0x02,0x10,0x42,0x10,0x81,0xFF,0x7F,
0x90,0x04,0x54,0x05,0xCC,0xF4,0xB4,0x44,
0x84,0x44,0xBC,0x7F,0x82,0x44,0xA2,0x44,
0x9B,0xF4,0x82,0x06,0x00,0x04,0x00,0x00,
//--棒--
0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,
0x90,0x00,0x54,0x05,0x44,0x12,0xD4,0x15,
0x74,0x14,0x5F,0xFF,0xD4,0x14,0x54,0x15,
0x56,0x12,0x44,0x06,0x40,0x02,0x00,0x00,
//--!
--
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3B,
0xFE,0x3B,0x7C,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*****函数声明*****/
voiddisplay1(void);
voiddisplay2(void);
voiddisplay3(void);
voiddisplay4(void);
/*****n(us)延时子程序*****/
voidDelayUs(uintN)
{
uintx;
for(x=0;x<=N;x++);
}
/*****中断服务程序*****/
voidintersvr0(void)interrupt0using1
{
KY=~KY;//每个摇动来回水银开关会在摆幅两端分别产生下降沿中断,只提取其中一次.只有在两个端点的时候,水银开关才会闭合!
!
!
!
!
!
!
(从左向右摇才显示)。
主函数中KY的值为0,当摇摇棒从右至左端时,KY=~KY,此时KY=1,当摇摇棒从左至右端时,KY=~KY,此时KY=0,然后继续执行下面的函数。
if(KY==0)
{
num++;//计算中断次数,作用是——例:
12个汉字分为3次显示完(每次显示4个字),每中断10次切换
switch(pic)//选择画面,pic为按键次数
{
case0:
{display1();}break;
case1:
{display2();}break;
case2:
{display3();}break;
case3:
{display4();}break;
default:
{display1();}
}
}
}
/*****显示子程序1(汉字)*****/
voiddisplay1(void)
{
uchari;
if(num>10){disp++;num=0;}//12个汉字分为3次显示完(每次显示4个),每中断10次切换,disp的不同值代表不同的画面。
if(disp>2)disp=0;//disp有0,1,2三种选择!
!
!
!
DelayUs(5200);//此处延时时间依各硬件差别而各不相同,试着调整使得显示内容居中即可
for(i=0;i<64;i++)
{//disp=0的时候,显示第一个64行(即第一个画面),disp=1的时候,显示第二个画面。
解析:
hanzi[]中,共有12个汉字,每四个汉字为一个画面,在hanzi[]中,每个汉字为4行8列,共32个16进制,由于纵向取模的原因,所以在取模软件中共为16行,4个汉字共为64行。
在取模软件中16行64列即为一个画面。
P0=~hanzi[disp*128+i*2];//disp=1时,为第二个画面,即从第五个字开始。
此时disp=1,i=0,所以P0=128,P1=129。
P2=~hanzi[disp*128+i*2+1];
DelayUs(100);
}
}
/*****显示子程序2(LOVE)*****/
voiddisplay2(void)
{
uchari;
DelayUs(4000);
for(i=0;i<64;i++)//64列,16行。
{//P0=0,P1=1,原因是纵向取模!
!
!
P0=~love[i*2];
P2=~love[i*2+1];
DelayUs(120);
}
}
/*****显示子程序3(心形图案)*****/
voiddisplay3(void)
{
uchari;
DelayUs(4000);
for(i=0;i<64;i++)
{
P0=~loveyou[i*2];
P2=~loveyou[i*2+1];
DelayUs(120);
}
}
/*****显示子程序4(呵呵o(∩_∩)o图案)*****/
voiddisplay4(void)
{
uchari;
DelayUs(4000);
for(i=0;i<64;i++)
{
P0=~hehe[i*2];
P2=~hehe[i*2+1];
DelayUs(120);
}
}
/*****主函数*****/
voidmain(void)
{
IT0=1;
EX0=1;
EA=1;//开中断,下降沿中断
KY=0;
while
(1)//主程序中只检测按键
{
if(KEY==0)//画面切换键按下
{
DelayUs(10000);//按键去抖
if(KEY==0);
pic++;}//pic为按键次数,根据pic的值进行画面选择!
!
!
!
!
!
if(pic>3)pic=0;
}
}
/*****END*****/
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 摇摇 程序 注释 完成
![提示](https://static.bdocx.com/images/bang_tan.gif)