本帖最后由 pdc201 于 2010-10-24 09:51 编辑
最近学校举行了个电子设计大赛,我们选了题目是LED摇摇棒,就是摇动的时候显示出图形和文字那种,但是因为题目是固定的,也有很多人都做过同样的作品,所以本人想在原本按键切换显示画面的基础上更改成红外遥控切换画面,但是本人是初学者,对这方面不很懂,请各位大侠帮帮忙改进改进,电路图和程序都如下,只需改进成红外遥控切换画面就行了,需要什么硬件,程序如何修改,请各位大侠此赐教赐教,小弟感激不尽~!!!!!
程序:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int //宏定义
sbit KEY=P3^0; //定义画面切换按键
uchar KY; //KY作用在后面说明
uchar pic=0,num=0; //pic 为按键次数;num 为中断次数
uchar code dianzi[64]={
0x00,0x00,0xF8,0x07,0x48,0x02,0x48,0x02,
0x48,0x02,0x48,0x02,0xFF,0x3F,0x48,0x42,
0x48,0x42,0x48,0x42,0x48,0x42,0xFC,0x47,
0x08,0x40,0x00,0x70,0x00,0x00,0x00,0x00,//电
0x80,0x00,0x80,0x00,0x82,0x00,0x82,0x00,
0x82,0x00,0x82,0x40,0x82,0x80,0xE2,0x7F,
0xA2,0x00,0x92,0x00,0x8A,0x00,0x86,0x00,
0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,//子
};
uchar code zifu[224]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0x03,0xFC,0x0F,0x00,0x0E,0x80,0x03,
0x00,0x0E,0xFC,0x0F,0xFC,0x03,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x08,
0xE4,0x08,0x0C,0x0C,0x1C,0x0E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x04,0x08,
0x00,0x08,0x00,0x0C,0x00,0x0E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0x03,0xF8,0x07,0x0C,0x0C,0x04,0x08,
0x04,0x08,0x0C,0x0C,0x18,0x06,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0x03,0xF8,0x07,0x0C,0x0C,0x04,0x08,
0x0C,0x0C,0xF8,0x07,0xF0,0x03,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0x0F,0xFC,0x0F,0x38,0x00,0x70,0x00,
0x38,0x00,0xFC,0x0F,0xFC,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x04,0x08,0xFC,0x0F,0xFC,0x0F,0x44,0x08,
0xE4,0x08,0x0C,0x0C,0x1C,0x0E,0x00,0x00,
};
uchar code wuhuan[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF8,0x00,0xFC,0x01,0x06,0x03,0x03,0x06,
0x03,0x06,0x03,0x06,0x03,0x06,0x03,0x1E,
0x03,0x3F,0x86,0x61,0xFC,0xC0,0x78,0xC0,
0x60,0xC0,0x60,0xC0,0x78,0xC0,0xFC,0xC0,
0x86,0x61,0x03,0x3F,0x03,0x1E,0x03,0x0C,
0x03,0x0C,0x03,0x1E,0x03,0x3F,0x86,0x61,
0xFC,0xC0,0x78,0xC0,0x60,0xC0,0x60,0xC0,
0x78,0xC0,0xFC,0xC0,0x86,0x61,0x03,0x3F,
0x03,0x1E,0x03,0x06,0x03,0x06,0x03,0x06,
0x03,0x06,0x06,0x03,0xFC,0x01,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,} ;
void display1(void);
void display2(void);
void display3(void);
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;
default:{display1();}
}
}
}
void display1(void)
{ uchar i;
DelayUs(4000);
for(i=0;i<64;i++)
{ P0=~dianzi[i*2];
P2=~dianzi[i*2+1];
DelayUs(120);
}
}
void display2(void)
{ uchar i;
DelayUs(4000);
for(i=0;i<224;i++)
{ P0=~zifu[i*2];
P2=~zifu[i*2+1];
DelayUs(120);
}
}
void display3(void)
{ uchar i;
DelayUs(5000);
for(i=0;i<122;i++)
{ P0=~wuhuan[i*2];
P2=~wuhuan[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>2)pic=0;
}
} |