摇摇棒原理图和PCB图及程序
基于单片机的摇摇棒设计1
郑州科技学院单片机课程设计题目基于单片机的摇摇棒设计学生姓名张焦焦专业班级电气工程及其自动化3班学号201147078院(系)电气工程学院指导教师程晓琦完成时间2014年12月12日目录1 前言 (1)2 设计方案与论证 (2)2.1 方案设计 (2)2.2 主要部件原理 (3)3 系统硬件设计 (4)3.1 基本原理设计 (4)3.2 系统硬件设计 (6)4 系统软件设计 (9)4.1 软件设计思路 (9)4.2 主程序流程图 (9)5 系统调试与分析 (11)5.1 常见故障与调试方法 (11)5.2 调试过程 (13)6 总结 (16)参考文献 (17)附录1:总体电路原理图 (18)附录2:实物图 (19)附录3:元器件清单 (20)1 前言摇摇棒是一种利用视觉暂留效应制作的“高科技”玩具。
可以用“静如处子,动如脱兔”来形容它,即当静止时,它只是几个LED发光二极管(后简称LED),而一旦按照一定的频率去摇晃它,它就会随着位置的变化而变化(亮或灭),最终显示一幅图片或字符串。
它是由单片机控制一排LED灯有规律地亮暗,再通过摇动使之在空中呈现一幅段时间的画面。
它的设计需要解决几个问题。
因为通过摇动产生的图像是有方向的,所以,要使图像正确不重叠,就要将摇摇棒设计成单方向才显示图像。
如果摇动一下的速度比显示一幅图像的速度慢,可能会出现:第二幅图的前面部分在第一下摇动的末尾,后面部分在第二下摇动的开始。
这就要使摇摇棒在一次摇动中只显示一次图像。
如果要设计一个16X20分辨率的摇摇棒,LED数为16只,LED每5ms—10ms变换一次,共变换20次组成一幅图像。
测试间隔8ms效果较好。
其中亮灯3ms,暗灯5ms。
这样能使亮点不呈一条横线,黑暗宽度与LED间隔相近。
单片机系统可采用AT89S52单片机。
选择P0和P2口输出,连接16只LED灯。
P3.2为外部中断INT0,低电平触发方式,接一个轻触开关,功能为切换图像。
32位摇摇棒图纸和程序
#include<STC11F60XE.h>/*********外猘部?接ï口ò定¨义?**********/#define uchar unsigned char#define uint unsigned int//宏ê定¨义?#define out P1 //数簓据Y输?出?端?口òsbit led1=P3^0; //第台?EDsbit led2=P3^1; //第台?EDsbit led3=P3^3; //第台?EDsbit led4=P3^4; //第台?EDsbit key1=P3^5; //按恪键ó输?入?sbit p3_2=P3^2;uchar KY,num; //KY作痢用?在ò后ï面?说μ明ðuchar BUFF; //缓o存?/*********全?局?变?量?定¨义?**********/unsigned long int TimeCount=0;unsigned int DelayN=80, //延ï时骸临ⅷ时骸计?数簓DelayTime=80; //每?次?延ï时骸的?周ó期ò个?数簓unsigned char key,keyy;/**********************************************/void delay(unsigned char n);void DelayMs(void);/*******************************************/unsigned char code text0[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"",0*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xB7,0xBB,0xB7,0xBB,0xB3,0xBB,0xB4,0xBB,0xB5,0x BB,0xB7,0xBB,0xB7,0xBB,0xB7,0xBB,0x07,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"自?",1*/0xBF,0xBF,0xBE,0xDF,0x39,0xE0,0xFF,0xDF,0xEF,0xBF,0xEF,0xBF,0x6D,0xB0,0x6D,0xB7,0x6D,0x B7,0x01,0xB7,0x6E,0xB7,0x6E,0xB7,0x6E,0xB0,0xEF,0xBF,0xEF,0xBF,0xFF,0xFF,/*"适酣?,2*/0xFF,0xBF,0xFF,0xC7,0x03,0xF8,0xBB,0xDF,0x7B,0xDF,0xFB,0xD0,0xEB,0xDB,0xDA,0xDF,0x39,0x DC,0x7B,0xCF,0xFB,0xD3,0xFB,0xDC,0x1B,0xDF,0xBB,0xDF,0xFF,0xDF,0xFF,0xFF,/*"应畖",3*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",4*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x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xCF,0xFF,0xFF,0xFF,0xC7,0x07,0x 00,0x00,0xC0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,/*"未′命ó名?文?件t",0*/};/***********n s)?延ï时骸子哩程ì序î***************/void DelayUs(uint N){uint x;for(x=0; x<=N;x++);}/******************************************/void main(){AUXR=0x80;CLK_DIV=1;EX0=1; //开a放?外猘部?中D断?0IT0=1; //中D断?0为a边?沿?触洌发ぁ方?式?IP=0x02; //设Θ置?中D断?优?先è级?TMOD=0x02; //定¨时骸器ð0方?式?2,?8位?重?装痢载?TH0=0x80; //设Θ定¨定¨时骸器ð初?值μTL0=0x80;KY=0;EA=1; //开a放?中D断?ET0=1; //开a放?定¨时骸器ð0中D断?TR0=1; //启?动ˉ定¨时骸器ð0,?开a始?计?时骸?/key=0; //初?始?化ˉ显?示?第台一?组哩文?字?keyy=0;P1M0=0x55; //0101 0101 /P1.0 P1 .2 P1.4 P1.6推?输?出?P1M1=0xAA;while(1){//等台待鋣中D断?if(key1==0){ //有瓺键ó按恪下?DelayUs(50);if(key1==0){key++; //更ó换?下?一?幅え图?片?if(key>2) key=0; //图?片?循-环·显?示? 根ñ据Y显?示?的?组哩数簓来ぁ定¨义? 这a里?有瓺9组哩?所ñ以?就í要癮keyy>9while(key1==0); //等台待鋣按恪键ó释酣放?}}if(num>10) //每?中D断?10次?切D换?{keyy++;num=0;}if(keyy>2)keyy=0; //图?片?循-环·显?示? 根ñ据Y显?示?的?组哩数簓来ぁ定¨义? 这a里?有瓺9组哩?所ñ以?就í要癮keyy>9}}/*********文?字?显?示?子哩程ì序î**********/void display_word(unsigned char code *text){unsigned char i,j=2; //j为a图?片?起e始?位?置? 3 为a第台?个?开a始?是?图?片? 如?果?要癮显?示?高?时骸?2的?大洙字? 也?属?图?片?格?式?DelayUs(6400);for(i=0;i<64;i++){P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B;if((key>=j)||(keyy>=j))BUFF=(*(text+i*4+3));elseBUFF=(*(text+128+i*2+1));led4=0;P1=~BUFF>>1;P3M0=0x10; //0001 0000 //P3.4推?输?出? P3 .0 P3.3 P3.1输?入?高?阻哩P3M1=0x0B; //0000 1011delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001 1011led4=1;P1=BUFF; //01010101 1357P3M0=0x10; //0001 0000 //P3.4推?输?出? P3 .0 P3.3 P3.1输?入?高?阻哩P3M1=0x0B; //0000 1011delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001 1011if((key>=j)||(keyy>=j))BUFF=(*(text+i*4+2));elseBUFF=(*(text+128+i*2));led3=0;P1=~BUFF>>1;P3M0=0x08; //0000 1000 //P3.3推?输?出? P3 .0 P3.1 P3.4输?入?高?阻哩delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001 1011led3=1;P1=BUFF; //01010101 1357P3M0=0x08; //0000 1000 //P3.3推?输?出? P3 .0 P3.1 P3.4输?入?高?阻哩P3M1=0x13; //0001 0011delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B;if((key>=j)||(keyy>=j))BUFF=(*(text+i*4+1));elseBUFF=(*(text+i*2+1));led2=0;P1=~BUFF>>1;P3M0=0x02; //0000 0010 //P3.1推?输?出? P3 .0 P3.3 P3.4输?入?高?阻哩P3M1=0x19; //0001 1001delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001 1011led2=1;P1=BUFF; //01010101 1357P3M0=0x02; //0000 0010 //P3.1推?输?出? P3 .0 P3.3 P3.4输?入?高?阻哩P3M1=0x19; //0001 1001delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001if((key>=j)||(keyy>=j))BUFF=(*(text+i*4));elseBUFF=(*(text+i*2));led1=0;P1=~BUFF>>1;P3M0=0x01; //0000 0001 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩delay(1);P3M0=0x00; //0000 0000 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1B; //0001 1011led1=1;P1=BUFF; //01010101 1357P3M0=0x01; //0000 0001 //P3.0推?输?出? P3 .1 P3.3 P3.4输?入?高?阻哩P3M1=0x1A; //0001 1010delay(1);} }/*********显?示?内ò容╕选?择?子哩程ì序î**********/void display(unsigned char t){ keyy=0;switch (t){ //过y按恪键ó选?择?显?示?内ò容╕case 0: {display_word(text0);}break;case 1: {display_word(text1);}break;case 2: {display_word(text2);}break;// case 3: {display_word(text3);}break;// case 4: {display_word(text4);}break;// case 5: {display_word(text5);}break;// case 6: {display_word(text6);}break;// case 7: {display_word(text7);}break;// case 8: {display_word(text8);}break;// case 9: {display_word(text9);}break;// case 10:{display_word(text10);}break;//default:{display_word(text1);}}}/*****************************************/void display1(unsigned char y){switch (y){ //过y按恪键ó选?择?显?示?内ò容╕case 0: {display_word(text0);}break;case 1: {display_word(text1);}break;case 2: {display_word(text2);}break;// case 3: {display_word(text3);}break;// case 4: {display_word(text4);}break;// case 5: {display_word(text5);}break;// case 6: {display_word(text6);}break;// case 7: {display_word(text7);}break;// case 8: {display_word(text8);}break;// case 9: {display_word(text9);}break;// case 10:{display_word(text10);}break;}}/***************************************//*********延ï时骸子哩程ì序î**********/void delay(unsigned char n){for(;n>0;n--){DelayN=DelayTime;while (DelayN);}}/*********中D断?子哩程ì序î**********/void int0() interrupt 0 //使?用?外猘部?中D断?0{KY=~KY;if(KY==0){DelayTime=TimeCount/1580;TimeCount=0; //延ï时骸周ó期ò计?数簓清?零?if(key==0){num++;display1(keyy); //根ñ据Y按恪键ó选?择?循-环·显?示?文?字?}else{display(key); //根ñ据Y按恪键ó选?择?循-环·显?示?文?字?}}}void timer0() interrupt 1 //定¨时骸器ð0中D断?子哩程ì序î{TimeCount++;if (DelayN!=0)DelayN--;}//--------------------------------------------------------------------------------//新一代1T 8051系列单片机内核特殊功能寄存器C51 Core SFRs// 7 6 5 4 3 2 1 0 Reset Valuesfr ACC = 0xE0; //Accumulator 0000,0000sfr B = 0xF0; //B Register 0000,0000sfr PSW = 0xD0; //Program Status Word CY AC F0 RS1 RS0 OV F1 P 0000,0000//-----------------------------------sbit CY = PSW^7;sbit AC = PSW^6;sbit F0 = PSW^5;sbit RS1 = PSW^4;sbit RS0 = PSW^3;sbit OV = PSW^2;sbit P = PSW^0;//-----------------------------------sfr SP = 0x81; //Stack Pointer 0000,0111sfr DPL = 0x82; //Data Pointer Low Byte 0000,0000sfr DPH = 0x83; //Data Pointer High Byte 0000,0000//--------------------------------------------------------------------------------//新一代1T 8051系列单片机系统管理特殊功能寄存器// 7 6 5 4 3 2 1 0 Reset Valuesfr PCON = 0x87; //Power Control SMOD SMOD0 LVDF POF GF1 GF0 PD IDL 0001,0000// 7 6 5 4 3 2 1 0 Reset Valuesfr AUXR = 0x8E; //Auxiliary Register T0x12 T1x12 UART_M0x6 BRTR S2SMOD BRTx12 EXTRAM S1BRS 0000,0000//-----------------------------------sfr AUXR1 = 0xA2; //Auxiliary Register 1 - PCA_P4 SPI_P4 S2_P4 GF2 ADRJ - DPS 0000,0000/*PCA_P4:0, 缺省PCA 在P1 口1,PCA/PWM 从P1 口切换到P4 口: ECI 从P1.2 切换到P4.1 口,PCA0/PWM0 从P1.3 切换到P4.2 口PCA1/PWM1 从P1.4 切换到P4.3 口SPI_P4:0, 缺省SPI 在P1 口1,SPI 从P1 口切换到P4 口: SPICLK 从P1.7 切换到P4.3 口MISO 从P1.6 切换到P4.2 口MOSI 从P1.5 切换到P4.1 口SS 从P1.4 切换到P4.0 口S2_P4:0, 缺省UART2 在P1 口1,UART2 从P1 口切换到P4 口: TxD2 从P1.3 切换到P4.3 口RxD2 从P1.2 切换到P4.2 口GF2: 通用标志位ADRJ:0, 10 位A/D 转换结果的高8 位放在ADC_RES 寄存器, 低2 位放在ADC_RESL 寄存器1,10 位A/D 转换结果的最高2 位放在ADC_RES 寄存器的低2 位, 低8 位放在ADC_RESL 寄存器DPS: 0, 使用缺省数据指针DPTR01,使用另一个数据指针DPTR1*///-----------------------------------sfr WAKE_CLKO = 0x8F; //附加的SFR WAK1_CLKO/*7 6 5 4 3 2 1 0 Reset ValuePCAWAKEUP RXD_PIN_IE T1_PIN_IE T0_PIN_IE LVD_W AKE _ T1CLKO T0CLKO 0000,0000Bb7 - PCAW AKEUP : PCA 中断可唤醒powerdown。
32led摇摇棒
基于视觉暂留原理的摇动显示装置摘要:“摇动显示装置”,俗称“摇摇棒”,是基于人的视觉暂留原理的,通过分时刷新32个发光二极管来显示输出文字或图案等信息的显示装置。
输出信号频率的控制通过单片机来实现,用摇动传感器检测当前摇动状态。
当进行摇动时,由于人的视觉暂留原理,会在发光二极管摇动区域产生一个视觉平面,在视觉平面内的二极管通过不同频率的刷新,会在摇动区域内产生图像,从而达到在该视觉平面上传达信息的作用。
关键字:单片机;摇摇棒;发光二极管;摇动前言:随着人们物质生活水平的提高,人们对精神生活的追求也愈加强烈,对信息的渴求已成为了人们必不可少的需要,更加简捷与新颖的信息传递方式无疑会给人们带来耳目一新的感受。
而现代工具务求简捷化、便携化,因此,摇动显示装置的到来,必将会给人们带来一种新的方便的文化传递方式。
一、系统硬件系统功能主要体现在3个部分:(1)单片机控制(STC12C2052)本装置采用了STC12C2052单片机,它支持直接通过串口线下载程序,对于本设计而言,显示文字需经常改变,STC12C2052方便许多,因此选择STC12C2052作为本设计所用的单片机。
(2)显示功能。
(D1~D32)信息传递主要由显示来完成,本设计显示功能由32个发光二极管来完成。
32个发光二极管分为4组,以共阳的方式连接,共用P1口作为数据输出口。
另外4条I/O口作为段选,通过三极管选通相应段。
(3)传感器系统。
(S2)硬件传感器主要为摇动传感器,本设计的摇动传感器由滚珠开关构成。
可选摇动开关有水银摇动开关和滚珠开关两种。
水银摇动开关稳定性较高,但容易发生破裂,水银外泄,安全性较差。
滚珠开关稳定性稍差,但不容易损坏,安全度很高。
考虑到实际应用环境,故选用滚珠开关作为系统的摇动传感器。
由滚珠开关带来的不稳定性可以通过软件进行弥补。
图1:滚珠开关内部结构图另外D_B1和D_B2为装饰用的蓝色发光二极管,J1为串口,供下载程序用。
魔幻摇摇棒原理(基于AT89S52单片机)
魔幻摇摇棒设计原理原理:“摇摇棒”是基于人的视觉暂留原理的,通过分时刷新16个发光二极管来显示输出文字或图案等信息的显示装置。
输出信号频率的控制通过单片机来实现,用摇动传感器检测当前摇动状态。
当进行摇动时,由于人的视觉暂留原理,会在发光二极管摇动区域产生一个视觉平面,在视觉平面内的二极管通过不同频率的刷新,会在摇动区域内产生图像,从而达到在该视觉平面上传达信息的作用。
一、引言LED显示棒,又称摇摇棒,是一种利用视觉暂留效应制作的“高科技”玩具。
可以用“静如处子,动如脱兔”来形容它,即当静止时,它只是几个LED发光二极管(后简称LED),而一旦按照一定的频率去摇晃它,它就会随着位置的变化而变化(亮或灭),最终显示一幅图片或字符串。
本设计要求制作完成一个LED的显示棒。
要求LED灯线状排列,通过摇动时形成的亮灯扇形区域能够分辨出如:“你最棒”、“0K”、爱心之类的汉字或图案且可以使用按键对显示内容进行切换。
二、系统设计方案1.设计思路本系统要求设计一个LED显示棒,且需要有按键进行内容切换,它主要是由中央控制部分、LED驱动部分、LED显示部分以及电源部分组成,如图1所示:图1:LED显示棒系统框图单片机将提取的字模进行存储,当接收到按键输入的指令时单片机就将相应的字模代码通过I/O口输出,使LED点亮,利用视觉暂留原理最终使图案完整的显示在摆动的显示屏中。
本题的难点在于送数据的时间间隔以及较长画面或文字的完整显示。
以下将对各模块的方案进行论证与比较:2.模块方案的论证与比较2.1 LED灯的选择方案一:传统LED发光二极管。
颜色多样,在可以同样显示图案的前提下使用它更为经济,但是颜色较为黯淡,不鲜亮。
方案二:高亮LED发光二极管。
正如其名,它的亮度比传统二极管要亮,而且同样也有很多颜色,但是高亮LED的工作电流也要大于传统二极管。
为了使显示的图案清晰、明了,我们选择方案二,经过比较,使用红色的LED使得显示画面更为明显、突出,使用两片CR2032纽扣电池为其供电,提供足够的电流。
摇摇棒制作教程
摇摇棒制作教程
本摇摇棒设计所用的软件是proteus8.3 很多原件都没有都是自己画出来的所以做出来的板子不是太理想主要就是焊盘量身定做没有画的稍大点导致焊接很不爽别的貌似没啥了如果你们感觉我哪里做的不好欢迎批评(o゚v゚)ノ
这些都是电脑上设计的图。
无奈proteus 只能输出cam文件去给人家打板。
哎
反正最后是吧板子做出来了一共十一张板子每张板子2套体积大约是2*10*1cm
很小吧~( ̄▽ ̄~)(~ ̄▽ ̄)~
下面就是制作过程咯~~ 一张大板子。
还得自己切开
一个摇摇棒分为两个板子一个是摇摇棒本身的主要电路另一个是电池以及充电电路开关神马的。
LED摇摇棒实际制作图文教程【含汇编程序】
LED摇摇棒实际制作图文教程【含汇编程序】LED摇摇棒实际制作图文教程【含汇编程序】总体介绍:大家知道,人的眼睛存在视觉暂留现象,正因为眼睛的反应迟钝,才丰富了人的视觉感受。
意思是时间小于1/24秒人就分辨不出了,LED摇摇棒很好地利用了人眼的视觉暂留特性。
配合手的左右摇晃就可呈现一幅完整的画面,可以显示字符、图片等。
讲白了就和点阵的显示没什么去别,只是你的手摇晃的过程代替了点阵的片选。
下面是总体的设计电路图:D1是电源指示灯,习惯性做法,是为了更好的了解你电路的物理现象。
下面是摇摇棒的效果图:硬件模块:总体电路图有了我就说一下,焊接步骤及需要注意的细节,第一步:焊好16个LED灯,当然个数随喜好而定,LED颜色也随喜好,但最好不要用白光。
(正面) (背面)第二步:焊单片机最小系统元件放在里面一是为了保护元器件;二是为了美观、好看。
这里注意一下:我们可以在单片机的TXD和RXD及地那里接出来三根排针,接到单片机开发板上的TXD、RXD和地。
是为了烧程序方便,不用每烧一次程序就把它取出来,这样既减少了操作也减少了对单片机的损坏。
第三步:接线(正面)反面第四步:完成,还有按键和水银开关没接,等会会介绍。
总体以焊好下面介绍切换按键和水银开关的接发和作用。
1、水银开关在这里起的是防止镜像文字,深沉点给单片机一个下降沿的触发。
镜像文字通俗点讲是希望当文字向左晃动显示,向右晃动时不让其显示。
但如果没有水银开关给个中断的话,文字会一直显示,造成两排文字重叠在一起。
使人看不清。
当然我们要避免这种情况就接了个水银开关。
水银开关的安放最好是与LED成45度角,既容易触发、减少抖动也是为了安全,当装好后,可以用胶把它封起来,这样就避免了水银开关的破碎。
2、按键开关主要是为了切换模式,这个比较简单,端口随便接哪都可以,我接的是P0.2,软件模块:;===================================================== ;=====程序名称:摇摇棒================================ ;=====硬件说明:16个LED分别接P1、P2口,水银开关接P3.2,;===============按键开关接P0.2======================== ;=====软件说明:采用查表方式,外部中断0===============;=====程序编辑时间:2010-11-14-11-15================== ;=====程序编辑人:李阳辉============================== ;=====所用芯片:STC89C52============================== ;=====所用晶振:12MHz================================= ;=====版本:V1.0====================================== ;=====当前进度:完成================================== ;=====程序完成时间:2010-11-16-10-20================== ;================================================== === ;=====分配单元地址==================================== OUTPUT1 EQU 31H ;P2口查表的暂存器OUTPUT2 EQU 30H ;P1口查表的暂存器COUNT1 EQU 32HC1 EQU 33HC2 EQU 34HC3 EQU 35H C4 EQU 36H C5 EQU 37H C6 EQU 38H C7 EQU 39H C8 EQU 3AH C9 EQU 3BH C10 EQU 3CH KEY BIT P0.2ORG 0000H ;起始地址JMP RESETORG 0003H ;外部中断入口地址JMP INTORG 0030H/*===========================================复位程序===========================================*/RESET:MOV C1,#00H ;偏移量MOV C2,#00HMOV C3,#00HMOV C4,#00H/*MOV C5,#00HMOV C6,#00HMOV C7,#00HMOV C8,#00HMOV C9,#00HMOV C10,#00H */MOV OUTPUT1,#00HMOV OUTPUT2,#00HSETB KEY ;把P0.2置高,作为输入口MOV COUNT1,#00HSETB EX0 ;分中断SETB EA ;总中断SETB IT0 ;启动/*========================================== 主程序==========================================*/ MAIN:CALL KEY_SCANCALL NOADLJMP MAIN/*========================================= 按键处理程序只做了两种模式,大家可以再加=========================================*/ KEY_SCAN:JB KEY,KEY_RETLCALL DELAYJB KEY,KEY_RETINC COUNT1INC COUNT1MOV A,COUNT1CJNE A,#4,KEY_DMOV COUNT1,#00HKEY_D:JNB KEY,$KEY_RET:RET/*========================================== 散转程序==========================================*/ NOAD:MOV DPTR,#TAB_B ;设置散转表地址MOV A,COUNT1JMP @A+DPTRTAB_B: ;散转表AJMP OPR_0AJMP OPR_2OPR_0:MOV DPTR,#TAB1MOV A,C1MOVC A,@A+DPTRMOV OUTPUT1,AMOV DPTR,#TAB2MOV A,C2MOVC A,@A+DPTRMOV OUTPUT2,AMOV P2,OUTPUT1 MOV P1,OUTPUT2 CALL DELAYINC C1INC C2MOV A,C2CJNE A,#64,OPR_0 MOV C1,#00H MOV C2,#00H LJMP OPR_RET OPR_2:MOV DPTR,#TAB3 MOV A,C3MOVC A,@A+DPTR MOV OUTPUT1,A MOV DPTR,#TAB4 MOV A,C4MOVC A,@A+DPTR MOV OUTPUT2,A MOV P2,OUTPUT1 MOV P1,OUTPUT2 CALL DELAYINC C3INC C4MOV A,C4CJNE A,#64,OPR_2MOV C3,#00HMOV C4,#00HLJMP OPR_RETOPR_RET:RET/*===========================================中断处理程序===========================================*/ INT:MOV P1,#0FFHMOV P2,#0FFHCALL DELAYRETI/*===========================================延时程序===========================================*/ DELAY:MOV R7,#3D1: MOV R6,#0E0HDJNZ R6,$DJNZ R7,D1RET;===========================真心爱你========================== TAB1: DB0FFH,0F7H,0F3H,0F7H,0F7H,0F7H,0F0H,0F7H,0C7H,0E7H,0B7H,0CBH,0EFH,0 F0H,0FBH,0FDHDB0FFH,0F9H,0F8H,0ABH,0AH,0B2H,0BAH,0A2H,0DBH,0DAH,0C2H,0DAH,0DBH,0E8H ,0F9H,0FFHDB0FFH,0E1H,0DEH,0BFH,0BFH,0BFH,0DFH,0EFH,0EFH,0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,0FFH,0FFH,0FH,0F1H,0FFH,0EFH,8FH,0B0H,03H,0B7H,9F H,0EFH;=======================================================END ;结束。
摇摇棒电路的设计
《电子线路CAD》课程论文题目:摇摇棒电路的设计1 电路功能和性能指标该电路是摇摇棒,在晃动过程中会显示出芯片程序中编写的字。
2 原理图设计2.1原理图元器件制作如图一所示a.自制元器件名称:二极管图一b.器件制作方法和步骤:1.新建集成库工程;2.给工程添加新的原理图;3.在原理图里面放置多边形画出三角形;4.放置两个引脚,按TAB键修改引脚编号属性(如图二所示),然后保存。
图二2.2 原理图设计1.设计步骤:新建PCB工程--->给工程添加新的原理图--->保存工程为摇摇棒2.绘制完成后的原理图如图三所示图三3.生成PCB图过程中的message信息如图四所示步骤:工程--->compile--->system--->message--->没有错误即可图四4.生成元器件库如图六,七所示步骤:design compiler--->navigator(如图五所示)-->设计-->生成原理图库图五 图六 图七5.设计过程中需要注意的地方a.在画原理图的过程中,善于用网络标号,使图看起来更加简洁;b.在message 信息框中有错误时,点击该错误,会在原理图中详细的显示出来的哪个部位,然后进行修改。
2.3 原理图报表1.生成原理图的网络表如图八所示步骤:在原理图中:设计--->工程的网络表图八2.网络表的作用:网络表是电路自动布线的灵魂,也是原理图设计软件SCH与印刷电路设计软件PCB之间的接口。
概括的说:一是网络表文件可以支持印刷电路板的自动布线及电路模拟程序;二是可以与最后从印刷电路版图中获取的网络表文件比较,进行核对查错。
3.以下面元器件为例讲解其参数意义(如图九所示)图九该元器件的名称为:自制二极管,其引脚为1 的引脚后面写的VCC,表示该二极管的1号引脚接着VCC,另一个引脚连接着NET 24.以NetD2_2这个网络为例,找出其网络上的元器件如图十,十一所示图十图十一5.生成该原理图的简易元器件清单如图十二所示步骤:报告--->single boom图十二6.个人设计过程中说明的地方a.要善于利用网络报表,这是对原理图中各个元器件之间电气连接的定义;b.对于生成的各种报表要学会分析观察。
摇摇棒制作资料讲解
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显示;取模方式:纵向取模、字节倒序编写:最后更新:08/11/15晚**********************************************************/#include <AT89X52.h>#define uchar unsigned char#define uint unsigned int //宏定义#define KEY P3_0 //定义画面切换按键uchar KY; //KY作用在后面说明uchar disp; //显示汉字指针uchar pic=0,num=0; //pic为按键次数;num为中断次数uchar code love[] = {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*/};uchar code loveyou[] = {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,/*心形图案*/};uchar code hehe[] = {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图案*/};unsigned char code hanzi[] = {//-- 欢 --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,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,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,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 };/*****函数声明*****/void display1(void);void display2(void);void display3(void);void display4(void);/*****n(us)延时子程序*****/void DelayUs(uint N){uint x;for(x=0; x<=N;x++);}/*****中断服务程序*****/void intersvr0(void) interrupt 0 using 1{KY=~KY; //每个摇动来回水银开关会在摆幅两端分别产生下降沿中断,只提取其中一次(从左向右摇才显示)if(KY==0){num++; //计算中断次数switch(pic) //选择画面{case 0:{display1();}break;case 1:{display2();}break;case 2:{display3();}break;case 3:{display4();}break;default:{display1();}}}}/*****显示子程序1(汉字)*****/void display1(void){uchar i;if(num>10){disp++;num=0;} //12个汉字分为3次显示完(每次显示4个),每中断10次切换if(disp>2)disp=0;DelayUs(5200); //此处延时时间依各硬件差别而各不相同,试着调整使得显示内容居中即可for(i=0;i<64;i++){P0=~hanzi[disp*128+i*2];P2=~hanzi[disp*128+i*2+1];DelayUs(100);}}/*****显示子程序2(LOVE)*****/void display2(void){uchar i;DelayUs(4000);for(i=0;i<64;i++){P0=~love[i*2];P2=~love[i*2+1];DelayUs(120);}}/*****显示子程序3(心形图案)*****/void display3(void){uchar i;DelayUs(4000);for(i=0;i<64;i++){P0=~loveyou[i*2];P2=~loveyou[i*2+1];DelayUs(120);}}/*****显示子程序4(呵呵o(∩_∩)o图案)*****/ void display4(void){uchar i;DelayUs(4000);for(i=0;i<64;i++){P0=~hehe[i*2];P2=~hehe[i*2+1];DelayUs(120);}}/*****主函数*****/void main(void){IT0=1;EX0=1;EA=1; //开中断,下降沿中断KY=0;while(1) //主程序中只检测按键{if(KEY==0) //画面切换键按下{DelayUs(10000); //按键去抖if(KEY==0);pic++;}if(pic>3)pic=0;}}/*****END*****/(注:专业文档是经验性极强的领域,无法思考和涵盖全面,素材和资料部分来自网络,供参考。
摇摇棒实训报告
河南机电高等专科学校综合实训报告系部:专业:班级:学生姓名:学号:2012年 6月实训任务1.时间:2012年5月28日~2012年6月22日2. 实训单位:河南机电高等专科学校3. 实训目的:熟悉电路板及电子产品的制作全过程4. 实训任务:①了解电路板图得来的方法,掌握电路板图的打印技巧;②会使用热转印机将电路图转印到覆铜板上;③掌握电路板的腐蚀过程及注意事项;④会使用高速钻床给电路板打孔;⑤认识电子元器件,熟悉常用元器件的特性;⑥熟练掌握焊接方法和技巧,完成电路板的焊接;⑦掌握电子产品通电调试的注意事项,会编写程序;⑧作好实训笔记,对自己所发现的疑难问题及时请教解决;⑨联系自己专业知识,体会电子产品制作过程,总结自己的心得体会; 10参考相关的书籍、资料,认真完成实训报告。
○综合实训报告前言:大家都知道,人的眼睛存在视觉暂留现象,而正因为眼睛的反应迟钝,才丰富了人的视觉感受。
16led摇摇棒正是很好地利用了人眼的视觉暂留特性,而产生了奇妙的效果!本次试验通过掌握单片机及其开发流程,综合模拟电子技术和数字电子技术,掌握以单片机为核心的电子系统体系,从而更熟悉单片机在实际生活中的应用。
一:实训内容16只led发光管作为画面每一列的显示,快速左右摇晃起到了扫描的作用,视觉暂留会使影像在人眼视觉中保留一段时间,因而人眼可以看到一幅完整的画面。
与led点阵的显示有几分相仿。
硬件电路如下图。
系统电源vcc为5v~6v,下载程序和调试时一定要保证5v电压,实际使用时用2节cr2032的纽扣电池串联6v即可。
at89s51单片机作为控制器,在它的p0、p2口接有16只以共阳的方式连接的高亮度led,由单片机输出低电平点亮。
k2是芯片的复位按键;k1是画面切换按键,用于切换显示不同内容;水银开关信号送给int0。
系统的扩展接口有三个:j1用于和led显示及水银开关扩展板进行连接;j6用于串口的扩展,同时可以利用该串口进行isp程序下载,该接口为5v的电平,如需和计算机连接需要外接电平转换模块;j7为扩展接口,可以连接其它扩展功能模块。
单片机--摇摇棒
K1为普通开关
K2为水银开关
LED(1~16)为3MM发光二极管
用到的电阻都是10K,排阻由于买元件时没有考虑到,故自己焊接了电阻在对应的引脚
元件买回来后开始是想按照网上的做成一个长条形状,因此很轻易的将一块万用板损坏,建议没有必要的工具千万不要乱裁剪万用板,得不偿失。
焊元件是很简单的事,只要按照原理图细心就是,下面是我焊的板子,比较丑陋的,不过毕竟是第一次啊,嘿嘿
正面,将P1口的排阻焊在IC插槽内,比较美观
背面就很差劲,特别是有线交叉的时候一定要测试好,避免短路
我的一点点焊接方面的经验,在清除原理图的情况下,模块与模块之间要分开焊接,比如焊接起振模块时就不要去焊接其他模块,那样就不会漏掉要焊接的细节,比如接地和接电源。最好是焊好一个模块后用万用表检查一遍,尽量减少错误的产生,当然最后一次检查是有必要的。焊接时细心细心还是细心。
调试流水灯程序:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
char num,a=0,b=3,c;
uchar code table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
这是关于摇摇棒原理的解释:我们知道屏幕上显示连续的画面是通过扫描实现的,电影就是如此,一秒钟播放二十四张画面,这样在眼睛的暂留时间内就会显示下一张画面,看起来就是动起来的连续的动画,摇摇棒的原理也是如此,在纵向有16个发光二极管,我们可以通过横向移动来进行扫描,把程序中流水灯变化的时间间隔设置在眼睛暂留时间内一般小于0.04S就可以,因此我们在横向扫描时触动水银开关,程序开始执行,因此就可以显示一幅完整的画面。简单吧。
LED显示摇棒全套方案及源程序
LED显示摇棒全套方案及源程序以下是一个基于Arduino的LED显示摇棒的完整方案和源代码:硬件材料:- Arduino UNO- LED灯带(可选择RGB灯带或单色灯带)- 9V电池或电源模块- 电源线- 杜邦线- 面包板- 陶瓷电容- 电阻- 节拍器(可选)连接电路:1. 将Arduino UNO连接到面包板上。
2. 将LED灯带的正极连接到Arduino的5V引脚,负极连接到GND引脚。
如果使用RGB灯带,请将红色、绿色和蓝色引脚连接到Arduino的数字引脚。
3. 将一个陶瓷电容器连接到电路的输入部分,以平滑电源电压。
4. 连接一个电阻并将其连接到Arduino的A0引脚,以测量摇杆所在位置。
源代码:```c++// 引入库#include <FastLED.h>// 定义LED灯带的引脚#define LED_PIN 5// 定义LED灯带的类型#define LED_TYPE WS2812B// 定义LED灯带使用的颜色类型#define COLOR_ORDER GRB// 定义LED灯带上的LED数量#define NUM_LEDS 60// 创建LED灯带对象CRGB leds[NUM_LEDS];// 定义摇杆的引脚const int JOYSTICK_PIN = A0;// 定义灯带的亮度#define BRIGHTNESS 50// 定义摇杆的中心位置#define JOYSTICK_CENTER 512// 定义摇杆的阈值#define JOYSTICK_THRESHOLD 100// 初始化灯带void setup() {// 设置灯带的类型和引脚FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);// 设置灯带的亮度FastLED.setBrightness(BRIGHTNESS);// 启动串行通信Serial.begin(9600);}// 主循环void loop() {// 读取摇杆的值int joystickValue = analogRead(JOYSTICK_PIN);// 判断摇杆的位置if (joystickValue < JOYSTICK_CENTER - JOYSTICK_THRESHOLD) {// 向左移动LEDmoveLeft();}else if (joystickValue > JOYSTICK_CENTER + JOYSTICK_THRESHOLD) { // 向右移动LEDmoveRight();}// 更新LED灯带FastLED.show();}// 向左移动LED灯带void moveLeft() {// 将最后一个LED的颜色复制到第一个LEDleds[0] = leds[NUM_LEDS - 1];// 将所有LED向左移动一个位置for (int i = 1; i < NUM_LEDS; i++) {leds[i] = leds[i - 1];}}// 向右移动LED灯带void moveRight() {// 将第一个LED的颜色复制到最后一个LEDleds[NUM_LEDS - 1] = leds[0];// 将所有LED向右移动一个位置for (int i = NUM_LEDS - 1; i > 0; i--) {leds[i] = leds[i - 1];}}```这个方案可以通过读取摇杆的值,来控制LED灯带的移动方向。
摇摇棒原理图和PCB图及程序
在此,摇摇棒的原理就不说了,下面是我做的摇摇棒,附原理图,和PCB图:上面是原理图。
S1为水银开关,上拉电阻10k。
上图为PCB图,从下到上为D1~D16,D1~D8由P1.7~P1.0控制,D9~D16由P0.7~ P0.7控制。
图像切换有P2.0控制。
注意水银开关与水平方向成45度角放置。
注意本图连接采用PCtoLCD2002取模,取模方式为:逐列,逆向,阴码。
如图设置:如有问题,请加QQ:457569074,一起讨论学习。
下面是程序:#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit key= P2^0;//定义切换画面开关uchar Key_num;//定义按键次数uchar Int0_num=0;//定义中断次数uchar Direction;//定义摇动方向(从左到右)uchar code Embed[]={0x00,0x00,0x08,0x00,0x08,0x20,0xFE,0x1F,0x08,0x08,0x08,0x10,0x08,0x10,0xF8,0x0F,0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x0F,0x00,0x00,/*"加",0*/0x00,0x00,0x80,0x20,0x10,0x11,0x20,0x0A,0x00,0x04,0x00,0x02,0xE0,0x1F,0x20,0x11,0x20,0x11,0x20,0x11,0xFE,0x1F,0x20,0x11,0x20,0x11,0x20,0x11,0xE0,0x1F,0x00,0x00,/*"油",0*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x48,0x02,0xFE,0x1F,0x48,0x22,0x48,0x22,0x48,0x22,0xF8,0x23,0x00,0x18,0x00,0x00,0x00,0x00,/*"电",0*/0x00,0x00,0x00,0x00,0x80,0x00,0x88,0x00,0x88,0x40,0x88,0x80,0x88,0x80,0xC8,0xFF,0xA8,0x00,0x98,0x00,0x88,0x00,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"子",0*/0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x02,0x00,0x02,0x00,0x02,0x60,0xC2,0x6F,0x62,0x60,0x36,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"?",0*/};uchar code love[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,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,0x 02,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,0 x00,0x00,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x8 2,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*LOVE */};uchar code love_picture[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,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,0x FE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,0xF8,0x7F,0xFC,0x3F,0xFE,0 x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*心形图案*/};uchar code Hello[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"",0*/ 0x08,0x20,0xF8,0x3F,0x08,0x21,0x00,0x01,0x00,0x01,0x08,0x21,0xF8,0x3F,0x08,0x20,/*"H",1 */0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x13,0x00,0x00,/*"e",2*/ 0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,/*"l",3*/ 0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,/*"l",4*/ 0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1F,0x00,0x00,/*"o",5* /0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x33,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,/*"!",6*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"",7*/ };uchar code Smile[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,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,0xF0,0x1F,0x3C,0x3C,0x0E,0xF7,0x06,0xEF,0xF3,0xDC,0xF3,0xB0,0x63,0xB0,0x03,0xB0,0xF3,0xB0,0xF3,0xB8,0x03,0xDD,0x06,0xEF,0x0E,0x76,0x3C,0x3C,0xF8,0x1F,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,0x00,0x00}; uchar code Hxembed_Make[]={0x00,0x00,0x60,0x00,0xF0,0x09,0x10,0x07,0xD0,0x07,0x70,0x0C,0x00,0x88,0x00,0x98,0x00,0xC0,0x20,0x70,0x38,0x1C,0x1E,0x07,0xFA,0x3E,0x08,0x60,0x68,0x80,0x18,0x00,/*"欢",0*/0x10,0x04,0x18,0x08,0xF0,0x0F,0x08,0x18,0xFC,0x10,0x02,0x11,0x00,0x11,0x00,0x11,0x80,0x10,0xFC,0x17,0x84,0x10,0x04,0x11,0x04,0x11,0xFC,0x10,0x00,0x08,0x00,0x00,/*"迎",0*/0x00,0x00,0x00,0x00,0xC0,0x00,0xB8,0x1E,0xA0,0x02,0xFE,0x3F,0xA4,0x02,0x60,0x02,0x50,0x1E,0x00,0x00,0xE0,0x03,0x00,0x00,0x14,0x60,0xEC,0x3F,0x00,0x00,0x00,0x00,/*"制",7*/0x00,0x00,0x00,0x01,0x80,0x00,0x40,0x00,0xF0,0x3F,0x0C,0x00,0x80,0x00,0x40,0x00,0x30,0x00,0xEE,0x7E,0x20,0x09,0x20,0x09,0x20,0x05,0x10,0x00,0x00,0x00,0x00,0x00/*"作",8*/};uchar code Thanks[]= {//-- 谢-- //0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x86,0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x00,//--谢-- 0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x86,0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x00,//--!0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3B,0xFE,0 x3B,0x7C,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};uchar code danpan_picture[]={0x7f,0xff,0x7f,0xbf,0x7f,0xcf,0x7f,0xf3,0x01,0xfc,0x7d,0xff,0x75,0xff,0x6d,0xff,0x0d,0xff,0x5d, 0xdf,0x7d,0xbf,0x01,0xc0,0x7f,0xff,0x7f,0xff,0x7f,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,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,0x FE,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,0x 00,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,/*心形图案*/0x9f,0xfb,0xab,0xfb,0xb3,0xfd,0x80,0xdd,0xb3,0xd6,0x28,0xd5,0x92,0x55,0xad,0x01,0x92,0xd5,0xab,0xd5,0x33,0xd5,0x80,0xd6,0xb3,0xdd,0xab,0xf9,0xab,0xfd,0xff,0xff};void delay(uint X){for (i=0;i<=X;i++);}void delay1(uint n){ uint x,y;for(x=0;x<120;x++)for(y=0;y<n;y--);}/* '加油电子?'显示32*16像素*/void display1(){uchar i,disp;if(Int0_num>4 ){disp++;Int0_num=0;}if(disp>1)disp=0;delay(12000);for(i=0;i<48;i++){P0=~Embed[disp*64+i*2];P1=~Embed[disp*64+i*2+1];delay(120);//延时时间自己可以调,最好让画面显示在中间}}/*'LOVE'显示64*16像素*/void display2(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~love[i*2];P1=~love[i*2+1];delay(150);}}/*心形图案显示64*16像素*/void display3(){uchar i;delay(12000);for(i=0;i<64;i++)P0=~love_picture[i*2];P1=~love_picture[i*2+1]; delay(200);}}/*‘Hello!示64*16像素*/void display4(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~Hello[i*2];P1=~Hello[i*2+1];delay(120);}}/*笑脸图案显示64*16像素*/ void display5(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~Smile[i*2];P1=~Smile[i*2+1];delay(150);}}/*‘欢迎制作显示64*16像素’*/ void display6(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~Hxembed_Make[i*2];P1=~Hxembed_Make[i*2+1];delay(90);}/* '谢谢!'显示48*16像素*/void display7(){uchar i;delay(12000);for(i=0;i<48;i++){P0=~Thanks[i*2];P1=~Thanks[i*2+1];delay(80);}}/*外部中断0子函数*/void int0(void) interrupt 0{Direction=~Direction;if(Direction==0){Int0_num++;//中断次数加1switch(Key_num){case 0:display1();break;case 1:display2();break;case 2:display3();break;case 3:display4();break;case 4:display5();break;case 5:display6();break;case 6:display7();break;default :display1();}}}void main(void){EA=1;//开总中断IT0=1;//下降沿中断EX0=1;//启动外部中断0你——怒目Key_num=0;//初始化按键次数为零while(1) {if(!key) {delay1(5); // 去抖,可以跟自己的电路适当选择时间if(key==0){Key_num++;if(Key_num>6)//如果超过切换页面的次数就清零Key_num=0;}delay1(5);while(!key);}}}。
基于蓝牙无线传输的摇摇棒设计报告
通信工程专业单片机系统课程设计基于蓝牙无线传输的摇摇棒设计学院(系):信息与通信工程学院专业:通信工程学生姓名:梅宇华黄馨莹学号:2013136219 2013136209指导教师:丁纪峰完成日期:2015年5月24日大连民族大学摘要本文介绍了一种以STC89C52RC单片机为主控制器,利用人眼的视觉暂留设计的摇摇棒。
摇摇棒在摇动过程中形成一个扇形平面,平面内可清晰显示文字、字母、图案。
蓝牙作为一种新型的信息传送工具,具有无限传输、方便、快捷的优点。
将蓝牙的这种特性运用到摇摇棒上,再结合摇摇棒本身可以在手挥式摆动下动态显示文字及图案的特性,使得摇摇棒具有更好的利用价值在设计中,通过蓝牙无线传输,可以实现摇摇棒显示内容的实时修改。
本系统由STC89C52单片机控制模块、32个高亮度LED发光二极管、供电模块及蓝牙串口模块组成。
关键词:STC89C52RC单片机;视觉暂留;动态扫描;LED目录摘要 (1)目录 (1)1 设计背景及要求 (1)1.1 设计背景 (1)1.2 设计要求 (1)1.2.1 基本要求 (1)1.2.2 拓展要求 (1)2 系统设计原理 (2)2.1 系统总体设计方案 (2)2.2 摇摇棒显示原理 (2)2.3 图片显示原理 (2)3 系统硬件电路设计 (4)3.1 单片机最小系统设计 (4)3.1.1 时钟电路 (4)3.1.2 复位电路 (4)3.2 LED显示电路的设计 (5)3.3 串口电路设计 (6)3.4 电源电路设计 (7)3.5蓝牙/串口线选择电路设计 (7)4 系统软件设计 (9)4.1 主程序设计思路 (9)4.2 主程序流程图 (9)4.3 串口接收程序 (9)4.4 LED显示程序 (10)5 系统调试 (12)5.1 硬件调试 (12)5.2 软件调试 (12)5.3 整体调试 (12)6 总结 (13)7 参考文献 (14)附录一系统硬件电路图 (15)附录二实物照片 (16)附录三系统完整程序代码 (19)致谢 (21)1 设计背景及要求1.1 设计背景摇摇棒是如今流行的一种玩具,在各种聚会、节日中均见得到它的身影。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
在此,摇摇棒的原理就不说了,下面是我做的摇摇棒,附原理图,和PCB图:上面是原理图。
S1为水银开关,上拉电阻10k。
上图为PCB图,从下到上为D1~D16,D1~D8由~控制,D9~D16由~ 控制。
图像切换有控制。
注意水银开关与水平方向成45度角放置。
注意本图连接采用PCtoLCD2002取模,取模方式为:逐列,逆向,阴码。
如图设置:如有问题,请,一起讨论学习。
下面是程序:#include<>#define uchar unsigned char#define uint unsigned intsbit key= P2^0;//定义切换画面开关uchar Key_num;//定义按键次数uchar Int0_num=0;//定义中断次数uchar Direction;//定义摇动方向(从左到右)uchar code Embed[]={0x00,0x00,0x08,0x00,0x08,0x20,0xFE,0x1F,0x08,0x08,0x08,0x10,0x08,0x10,0xF8,0x0F,0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x0F,0x00,0x00,/*"加",0*/ 0x00,0x00,0x80,0x20,0x10,0x11,0x20,0x0A,0x00,0x04,0x00,0x02,0xE0,0x1F,0x20,0x11,0x20,0x11,0x20,0x11,0xFE,0x1F,0x20,0x11,0x20,0x11,0x20,0x11,0xE0,0x1F,0x00,0x00,/*"油",0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x48,0x02,0xFE,0x1F,0x48,0x22,0x48,0x22,0x48,0x22,0xF8,0x23,0x00,0x18,0x00,0x00,0x00,0x00,/*"电",0*/0x00,0x00,0x00,0x00,0x80,0x00,0x88,0x00,0x88,0x40,0x88,0x80,0x88,0x80,0xC8,0xFF,0xA8,0x00,0x98,0x00,0x88,0x00,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"子",0*/0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x02,0x00,0x02,0x00,0x02,0x60,0xC2,0x6F,0x62,0x60,0x36,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"",0*/};uchar code love[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x20,0x00,0x20,0x00,0 x20,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,0x 00,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,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,/*LOVE*/};uchar code love_picture[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,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,0x FC,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,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,/*心形图案*/};uchar code Hello[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,/*"",0*/0x08,0x20,0xF8,0x3F,0x08,0x21,0x00,0x01,0x00,0x01,0x08,0x21,0xF8,0x3F,0x08,0x2 0,/*"H",1*/0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x13,0x00,0x0 0,/*"e",2*/0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x0 0,/*"l",3*/0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x0 0,/*"l",4*/0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1F,0x00,0x0 0,/*"o",5*/0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x33,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x0 0,/*"!",6*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,/*"",7*/};uchar code Smile[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0xF0,0x1F,0x3C,0x3C,0x0E,0xF7,0x06,0xEF,0xF3,0xDC,0xF3,0xB0,0x63,0xB0,0x03,0xB 0,0xF3,0xB0,0xF3,0xB8,0x03,0xDD,0x06,0xEF,0x0E,0x76,0x3C,0x3C,0xF8,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0};uchar code Hxembed_Make[]={0x00,0x00,0x60,0x00,0xF0,0x09,0x10,0x07,0xD0,0x07,0x70,0x0C,0x00,0x88,0x00,0x98,0x00,0xC0,0x20,0x70,0x38,0x1C,0x1E,0x07,0xFA,0x3E,0x08,0x60,0x68,0x80,0x18,0x00,/*"欢",0*/0x10,0x04,0x18,0x08,0xF0,0x0F,0x08,0x18,0xFC,0x10,0x02,0x11,0x00,0x11,0x00,0x11,0x80,0x10,0xFC,0x17,0x84,0x10,0x04,0x11,0x04,0x11,0xFC,0x10,0x00,0x08,0x00,0x00,/*"迎",0*/0x00,0x00,0x00,0x00,0xC0,0x00,0xB8,0x1E,0xA0,0x02,0xFE,0x3F,0xA4,0x02,0x60,0x0 2,0x50,0x1E,0x00,0x00,0xE0,0x03,0x00,0x00,0x14,0x60,0xEC,0x3F,0x00,0x00,0x00,0x00,/*"制",7*/0x00,0x00,0x00,0x01,0x80,0x00,0x40,0x00,0xF0,0x3F,0x0C,0x00,0x80,0x00,0x40,0x0 0,0x30,0x00,0xEE,0x7E,0x20,0x09,0x20,0x09,0x20,0x05,0x10,0x00,0x00,0x00,0x00,0x0 0/*"作",8*/};uchar code Thanks[]= {//-- 谢 -- //0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x8 6,0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x0 0,//--谢--0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x8 6,0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x0 0,//--!0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3 B,0xFE,0x3B,0x7C,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00};uchar code danpan_picture[]={0x7f,0xff,0x7f,0xbf,0x7f,0xcf,0x7f,0xf3,0x01,0xfc,0x7d,0xff,0x75,0xff,0x6d,0xf f,0x0d,0xff,0x5d,0xdf,0x7d,0xbf,0x01,0xc0,0x7f,0xff,0x7f,0xff,0x7f,0xff,0xff,0 xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,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,0x FC,0x3F,0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x0 0,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,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,0x0 0,/*心形图案*/0x9f,0xfb,0xab,0xfb,0xb3,0xfd,0x80,0xdd,0xb3,0xd6,0x28,0xd5,0x92,0x55,0xad,0x0 1,0x92,0xd5,0xab,0xd5,0x33,0xd5,0x80,0xd6,0xb3,0xdd,0xab,0xf9,0xab,0xfd,0xff,0xf f};void delay(uint X){uint i;for (i=0;i<=X;i++);}void delay1(uint n){ uint x,y;for(x=0;x<120;x++)for(y=0;y<n;y--);}/* '加油电子'显示32*16像素 */ void display1(){uchar i,disp;if(Int0_num>4 ){disp++;Int0_num=0;}if(disp>1)disp=0;delay(12000);for(i=0;i<48;i++){P0=~Embed[disp*64+i*2];P1=~Embed[disp*64+i*2+1];delay(120);//延时时间自己可以调,最好让画面显示在中间 }}/*'LOVE'显示64*16像素 */void display2(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~love[i*2];P1=~love[i*2+1];delay(150);}/*心形图案显示64*16像素 */ void display3(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~love_picture[i*2]; P1=~love_picture[i*2+1]; delay(200);}}/*‘Hello!示64*16像素 */ void display4()uchar i;delay(12000);for(i=0;i<64;i++){P0=~Hello[i*2];P1=~Hello[i*2+1];delay(120);}}/*笑脸图案显示64*16像素*/ void display5(){uchar i;delay(12000);for(i=0;i<64;i++)P0=~Smile[i*2];P1=~Smile[i*2+1];delay(150);}}/*‘欢迎制作显示64*16像素’*/ void display6(){uchar i;delay(12000);for(i=0;i<64;i++){P0=~Hxembed_Make[i*2];P1=~Hxembed_Make[i*2+1];delay(90);}/* '谢谢!'显示48*16像素 */ void display7(){uchar i;delay(12000);for(i=0;i<48;i++){P0=~Thanks[i*2];P1=~Thanks[i*2+1];delay(80);}}/*外部中断0子函数*/void int0(void) interrupt 0Direction=~Direction;if(Direction==0){Int0_num++;//中断次数加1 switch(Key_num){case 0:display1();break; case 1:display2();break; case 2:display3();break; case 3:display4();break;case 4:display5();break;case 5:display6();break;case 6:display7();break;default :display1();}}void main(void){EA=1;//开总中断IT0=1;//下降沿中断EX0=1;//启动外部中断0你——怒目Key_num=0;//初始化按键次数为零while(1) {if(!key) {delay1(5); // 去抖,可以跟自己的电路适当选择时间 if(key==0){Key_num++;if(Key_num>6)//如果超过切换页面的次数就清零Key_num=0;}delay1(5);while(!key);}}}。