编程语言
首页 > 编程语言> > 实例源码2---基于51单片机的摇摇棒制作

实例源码2---基于51单片机的摇摇棒制作

作者:互联网

最近整理资料,看见这个之前做的摇摇棒,是基于51单片机的,下面把源程序贴出来,有任何问题欢迎留言!

#include
#define uchar unsigned char
#define uint unsigned int

sbit key = P3^0;//定义切换画面开关
uchar Key_num;//定义按键次数
uchar Int0_num=0;//定义中断次数
uchar Direction;//定义摇动方向(从左到右)
uchar code Embed[]={
0x40,0x00,0x20,0x00,0xd0,0x3f,0x4c,0x40,0x43,0x40,0x44,0x42,0x48,0x44,0xd8,0x43,
0x30,0x78,0x10,0x00,0x00,0x00,0xfc,0x07,0x00,0x20,0x00,0x40,0xff,0x3f,0x00,0x00,

0x20,0x21,0x24,0x11,0x2c,0x4d,0x35,0x81,0xe6,0x7f,0x34,0x05,0x2c,0x59,0x24,0x21,
0x00,0x18,0xfc,0x07,0x24,0x00,0x24,0x00,0xe2,0xff,0x22,0x00,0x22,0x00,0x00,0x00,

0x00,0x00,0x10,0x82,0x0c,0x82,0x04,0x42,0x4c,0x42,0xb4,0x23,0x94,0x12,0x05,0x0a,
0xf6,0x07,0x04,0x0a,0x04,0x12,0x04,0xe2,0x14,0x42,0x0c,0x02,0x04,0x02,0x00,0x00,

0x02,0x08,0xfa,0x08,0x82,0x04,0x82,0x24,0xfe,0x40,0x80,0x3f,0x40,0x22,0x60,0x2c,
0x58,0x21,0x46,0x2e,0x48,0x20,0x50,0x30,0x20,0x2c,0x20,0x23,0x20,0x20,0x00,0x00,

0x00,0x40,0x10,0x40,0x2c,0x48,0x24,0x49,0xa4,0x49,0x64,0x49,0x25,0x49,0x26,0x7f,
0x24,0x49,0x24,0x49,0xa4,0x49,0x24,0x4b,0x34,0x48,0x2c,0x40,0x04,0x40,0x00,0x00,
};
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,
};

uchar code love_picture[] = {
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 Hello[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x08,0x20,0xF8,0x3F,0x08,0x21,0x00,0x01,0x00,0x01,0x08,0x21,0xF8,0x3F,0x08,0x20,

0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x13,0x00,0x00,

0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,

0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1F,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x33,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

uchar code Smile[] = 
{
  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,
  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[]={
0x02,0x01,0xf2,0x03,0x12,0x41,0x12,0x81,0x1e,0x7f,0x00,0x00,0x80,0x00,0x80,0x40,
0xff,0xff,0xa0,0x40,0x90,0x23,0x88,0x0c,0x86,0x10,0x84,0x60,0x80,0x20,0x00,0x00,
0x80,0x00,0x80,0x40,0x80,0x30,0x80,0x0c,0xfe,0x03,0x82,0x00,0x8a,0x00,0x92,0x00,
0xf2,0x00,0xa2,0x20,0x82,0x40,0xfe,0x3f,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,
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,
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,
};

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,0x3B,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,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,
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)
{
  uint i;
  for(i=0;i<=X;i++)
   ;
}
void delay1(uint n)
{
       uintx,y;
       for(x=0;x<120;x++)
       for(y=0;y
}
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];
    P2=~Embed[disp*64+i*2+1];
  delay(120);//延时时间自己可以调,最好让画面显示在中间
 }
}
void display2()
{ 
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~love[i*2];
 P2=~love[i*2+1];
 delay(150);
  }

}
void display3()
{
  uchar i;
   delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~love_picture[i*2];
 P2=~love_picture[i*2+1];
 delay(200);
  }
}

void display4()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Hello[i*2];
 P2=~Hello[i*2+1];
 delay(120);
  }
}
void display5()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Smile[i*2];
 P2=~Smile[i*2+1];
 delay(150);
  }
}

void display6()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Hxembed_Make[i*2];
 P2=~Hxembed_Make[i*2+1];
 delay(90);
  }
}
void display7()
{
  uchar i;
  delay(12000);
 for(i=0;i<48;i++)
  {
  P0=~Thanks[i*2];
 P2=~Thanks[i*2+1];
 delay(80);
  }
}

void int0(void) interrupt 0
{
Direction=~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);
 }
}
}

标签:0x00,0x20,51,0x40,单片机,源码,0x80,0xff,0xFE
来源: https://blog.51cto.com/12483417/2419117