迷你摇摇棒制作方法

电子说

1.3w人已加入

描述

手头上攒了一些手机电池不知道干嘛就寻思着做一些小玩意,于是就有了一个主意就是摇摇棒即简单又好玩,本人喜欢小而巧的东西所以就把这个东西做的很小。

摇摇棒

上图是摇摇棒的原理利用人的视觉暂留结合单片机控制LED的亮灭就可以在空中显示字符或者图标。

摇摇棒

上图是电路图为了把东西做小我选择了STC15F104单片机它有8个引脚去除VCC和GND还有6个I/O口可以显示一些简单的字母和数字单片机内部自带了EEPROM所以利用它可以存储每一次显示的状态(每一次的开关电源就可以切换到下一个显示的字符)

程序在最后面。

代码在下面:

#include

#define uchar unsigned char

#define EN_EPROM 0x83; //使能EEPROM

#define S_MODE 0x00; //待机模式

#define R_MODE 0x01; //读模式

#define W_MODE 0x02; //写模式

#define F_MODE 0x03; //擦除模式

sfr IAP_DATA = 0xC2;

sfr IAP_ADDRH = 0xC3;

sfr IAP_ADDRL = 0xC4;

sfr IAP_CMD = 0xC5;

sfr IAP_TRIG = 0xC6;

sfr IAP_CONTR = 0xC7;

void init();

uchar num=0,m=0;

uchar read_dat(uchar addr_h,uchar addr_l);

void erase_dat(uchar addr_h,uchar addr_l);

void write_dat(uchar addr_h,uchar addr_l,uchar w_dat);

unsigned char code tab[10][32]={

{

0xe7,0xc3,0xc1,0xe0,0xc1,0xc3,0xe7,0xff,

0xff,0xff,0xff,0xe7,0xc3,0xc1,0xe0,0xc1,

0xc3,0xe7,0xff,0xff,0xff,0xff,0xe7,0xc3,

0xc1,0xe0,0xc1,0xc3,0xe7,0xff,0xff,0xff

},

{

0xff,0xff,0xde,0xc0,0xde,0xff,0xff,0xff,

0xff,0xff,0xff,0xe7,0xc3,0xc1,0xe0,0xc1,

0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xc1,

0xfe,0xfe,0xfe,0xfe,0xc1,0xff,0xff,0xff

},

{

0xde,0xed,0xf3,0xf3,0xed,0xde,0xff,0xff,

0xff,0xff,0xff,0xde,0xed,0xf3,0xf3,0xed,

0xde,0xff,0xff,0xff,0xff,0xff,0xff,0xde,

0xed,0xf3,0xf3,0xed,0xde,0xff,0xff,0xff

},

{

0xfb,0xfd,0xd6,0xe8,0xd6,0xfd,0xfb,0xff,

0xff,0xff,0xff,0xfb,0xfd,0xd6,0xe8,0xd6,

0xfd,0xfb,0xff,0xff,0xff,0xff,0xfb,0xfd,

0xd6,0xe8,0xd6,0xfd,0xfb,0xff,0xff,0xff

},

{

0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,

0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,

0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,

0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5

},

{

0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,

0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,

0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,

0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff

},

{

0xf0,0xed,0xdd,0xed,0xf0,0xff,0xff,0xdf,

0xdf,0xc0,0xdf,0xdf,0xff,0xff,0xc1,0xfe,

0xfe,0xfe,0xc1,0xff,0xff,0xc1,0xfe,0xf1,

0xfe,0xc1,0xff,0xff,0xe1,0xde,0xde,0xe1

},

{

0xc0,0xfb,0xfb,0xfb,0xc0,0xff,0xff,0xff,

0xff,0xff,0xde,0xed,0xf3,0xf3,0xed,0xde,

0xff,0xff,0xff,0xff,0xff,0xff,0xcf,0xf7,

0xf8,0xf7,0xcf,0xff,0xff,0xff,0xff,0xff

},

{

0xc0,0xde,0xd2,0xda,0xda,0xc2,0xfe,0xc0,

0xdf,0xd0,0xd6,0xd6,0xd2,0xde,0xc0,0xff,

0xc0,0xde,0xd2,0xda,0xda,0xc2,0xfe,0xc0,

0xdf,0xd0,0xd6,0xd6,0xd2,0xde,0xc0,0xff

},

{

0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,

0xf7,0xef,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

0xfd,0xfb,0xf7,0xef,0xdf,0xef,0xf7,0xfb,

0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xff

},

};

void delay(uchar xms)

{

char i,j;

for(i=0;i for(j=0;j《50;j++);

}

void main()

{

init();

num=read_dat(0x00,0x01);

++num;

if(num》=11)

{

num=1;

};

erase_dat(0x00,0x01);

write_dat(0x00,0x01,num);

while(1)

{

uchar i=0;

for(i=0;i《32;i++)

{

P3=tab[num-1][i];

delay(100);

}

}

}

void init()

{

IAP_CONTR = EN_EPROM; //把第7位置1允许EEPROM可以读写

IAP_CMD = S_MODE; //待机模式无ISP操作

IAP_ADDRH = 0x00;

IAP_ADDRL = 0x00;

}

uchar read_dat(uchar addr_h,uchar addr_l)

{

uchar E_dat = 0x00;

IAP_CMD = R_MODE; //模式选择为读EEPROM

IAP_ADDRH = addr_h;

IAP_ADDRL = addr_l;

IAP_TRIG = 0x5A; //使命令有效

IAP_TRIG = 0xA5; //使命令有效

E_dat = IAP_DATA;

return E_dat;

}

void write_dat(uchar addr_h,uchar addr_l,uchar w_dat)

{

IAP_CMD = W_MODE; //模式选择为写EEPROM

IAP_ADDRH = addr_h;

IAP_ADDRL = addr_l;

IAP_DATA = w_dat;

IAP_TRIG = 0x5A; //使命令有效

IAP_TRIG = 0xA5; //使命令有效

}

void erase_dat(uchar addr_h,uchar addr_l)

{

IAP_CMD = F_MODE; //模式选择为擦除EEPROM

IAP_ADDRH = addr_h;

IAP_ADDRL = addr_l;

IAP_TRIG = 0x5A; //使命令有效

IAP_TRIG = 0xA5; //使命令有效

}

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
评论(0)
发评论
qdznkj1815 2022-08-23
0 回复 举报
http://house.china.com.cn/sousou/%25B4%25FA%25C0%25ED%252C%2B%25B9%25FB%25B8%25D2%25F6%25CE%25CA%25A4%25B9%25FA%25BC%25CA%25D3%25E9%25C0%25D6B2024.cN_1s.htm http://house.china.com.cn/sousou/%25C6%25F3%25D2%25B5%252C%2B%25C3%25E5%25B5%25E9%25B9%25FB%25B2%25A9%25B9%25AB%25CB%25BEB2024.cN_55s.htm http://house.china.com.cn/sousou/%25D6%25B1%25D3%25AA%252C%2B%25C3%25E5%25B5%25E9%25D0%25C2%25B0%25D9%25C0%25FB%25D3%25E9%25C0%25D6%25BE%25C6%25B5%25EAB2024.cN%252C%25B3%25A3%25B5%25C2%25C8%25C8%25C3%25C5_4s.htm http://house.china.com.cn/sousou/%25B4%25FA%25C0%25ED%252C%2B%25C3%25E5%25B5%25E9%25CD%25F5%25D5%25DF%25D6%25C1%25D7%25F0%25CD%25F8%25CD%25B6%25B2%25BFB2024.cN%252C%25BF%25AA%25B7%25E2%25BD%25DA%25C4%25BF%25B1%25ED_4s.htm http://house.china.com.cn/sousou/%25C6%25BD%25CC%25A8%252C%2B%25C3%25E5%25B5%25E9%25D0%25C2%25BD%25F5%25BD%25AD%25BF%25CD%25B7%25FEB2024.cN%252C%25D5%25BF%25BD%25AD%25CC%25E5%25D3%25FD_3s.htm 收起回复

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分