仿真时需要注意:有4个按键控制4种不同样式的流水灯,按下第一个按键后,需等第一的样式结束后,才能进行其他的样式仿真
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code led1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code led2[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar code led3[]={0x55,0xaa,0x00,0xff,0x55,0xaa,0x00,0xff};
uchar code led4[]={0x0f,0xf0,0xaa,0x55,0x0f,0xf0,0xaa,0x55};
uchar key_value,key_value_pre;
//sbit K1=P1^0;
//sbit K2=P1^1;
//sbit K3=P1^2;
//sbit K4=P1^3;
void delayms(uint xms)
{
uint x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
uchar key;
if(P1!=0xff)
{
delayms(10);
if(P1!=0xff)
{
switch(P1)
{
case 0xfe:key=1;break;
case 0xfd:key=2;break;
case 0xfb:key=3;break;
case 0xf7:key=4;break;
}
while(P1!=0xff); //按键松手检测
}
return key;//如果有按键按下,返回具体键值
}return key=0;//如果没有按键按下,返回键值为0
}
//利用数组查表的方法实现任意花样灯的点亮控制子程序
void led(uchar *pt,uint time)
{
uchar i;
for(i=0;i<8;i++)
剩下程序请下载文件浏览:
花样流水灯.zip
(21.58 KB, 下载次数: 102)
|