分享好友 天南地北首页 网站导航

简单的单片机关于LED灯点亮的电路设计题?求解

网友发布 2023-08-02 01:23 · 头闻号仪器机械

自个修改一下

#include<reg51.h>//头文件//

#define uchar unsigned char

#define uint unsigned int

#define HI P2

#define LO P0

#define tn1h 0xb1

#define tn1l 0xe0

//全局变量定义

uchar code sia[16]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

uchar code sib[16]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};

uchar code sic[2]={0x55,0xaa};

uchar code sid[2]={0xaa,0x55};

uchar code sie[16]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

uchar code sif[16]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

uchar code sig[2]={0x00,0xff};

uchar code sih[2]={0xff,0x00};

uchar code sit[64]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7e,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7e,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,

0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,};

uchar code six[64]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7e,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7e,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,

0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xfc,0xfe,

0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xfc,0xfe,};

//显示数据

uchar s=0;

uchar tcount,tcount1,tflag,mflag,dflag=0;

void delayns(uchar s)//n秒延时

{uchar sd=0;//tcount1,tcount,tflag=0;

dflag=0;

while(sd<s&&dflag==0)

{while(tflag==1)

{tflag=0;sd++; }

}

}

void delaynms(uchar m)//n秒延时

{uchar sd=0;tcount1=0;

while(sd<m)

{

while(tcount1==1)

{tcount1=0;sd++; }

}

}

void sign0(void)//模式0

{uchar i=0;

while(mflag==0xef)

{while(i<64&&mflag==0xef)

{HI=six[i];

LO=sit[i];

delaynms(4);

i++;

}

i=0;

}

}

void sign1(void)//模式1 依次点亮

{uchar i=0;

while(mflag==0xfe)

{while(i<16&&mflag==0xfe)

{HI=sib[i];

LO=sia[i];

delayns(1);

i++;

}

i=0;

delayns(2);

}

}

void sign2(void)//模式2 奇数亮-->偶数灯亮

{uchar i=0;

while(mflag==0xfd)

{while(i<2&&mflag==0xfd)

{HI=sid[i];

LO=sic[i];

delayns(1);

i++;

}

i=0;

}

}

void sign3(void)//模式3 分别点亮

{uchar i=0;

while(mflag==0xfb)

{while(i<16&&mflag==0xfb)

{HI=sif[i];

LO=sie[i];

delayns(1);

i++;

}

i=0;

delayns(2);

}

}

void sign4(void)//模式4 左八亮-->右八亮

{uchar i=0;

while(mflag==0xf7)

{while(i<2&&mflag==0xf7)

{HI=sih[i];LO=sig[i];

delayns(5);

i++;

}

i=0;

}

}

void keyscan() //键盘扫描

{uchar key=0;

key=mflag;

P1=0xff;

if(P1!=0xff)

{if(key!=P1)dflag=1;mflag=P1;// //

}

}

void t1(void) interrupt 3 using 2 //定时扫描键盘

{TR1=0;

TH1=tn1h;

TL1=tn1l;

TR1=1;

keyscan();

tcount++;tcount1=1;

if(tcount==50) //一秒定时

{tflag=1;

tcount=0;}

}

void main() //主程序

{TMOD=0x11; //定时器工作模式 方式一

TH0=tn0h; //

TL0=tn0l; //

TH1=tn1h; //

TL1=tn1l; //

TR1=1; //启动定时器一

ET0=0; //允许定时器0中断

ET1=1; //允许定时器1中断

EA=1; //开启总中断

while(1)

{

if(mflag==0xef)sign0();

if(mflag==0xfe)sign1();

if(mflag==0xfd)sign2();

if(mflag==0xfb)sign3();

if(mflag==0xf7)sign4();

}

}

免责声明:本平台仅供信息发布交流之途,请谨慎判断信息真伪。如遇虚假诈骗信息,请立即举报

举报
反对 0
打赏 0
更多相关文章

收藏

点赞