51单片机彩灯控制器的设计Word格式.docx

上传人:b****3 文档编号:13988382 上传时间:2022-10-16 格式:DOCX 页数:14 大小:418.64KB
下载 相关 举报
51单片机彩灯控制器的设计Word格式.docx_第1页
第1页 / 共14页
51单片机彩灯控制器的设计Word格式.docx_第2页
第2页 / 共14页
51单片机彩灯控制器的设计Word格式.docx_第3页
第3页 / 共14页
51单片机彩灯控制器的设计Word格式.docx_第4页
第4页 / 共14页
51单片机彩灯控制器的设计Word格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

51单片机彩灯控制器的设计Word格式.docx

《51单片机彩灯控制器的设计Word格式.docx》由会员分享,可在线阅读,更多相关《51单片机彩灯控制器的设计Word格式.docx(14页珍藏版)》请在冰豆网上搜索。

51单片机彩灯控制器的设计Word格式.docx

**************************************************************************************************/

#include<

reg51.h>

#definefalse0

#definetrue1

#defineucharunsignedchar

#defineuintunsignedint

sbitpause_key=P3^0;

//暂停按钮

sbitauto_key=P3^1;

//手动模式的效果切换

sbitchange_key=P3^2;

//手动模式效果切换

sbitpauseLed=P3^6;

//暂停、启动指示灯

sbitautoLed=P3^7;

//自动、手动模式指示灯

intledCode[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//led段码(单个显示)

intledCode2[8]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};

//led段码(半显示半灭)

intdisCode[10]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09};

//数码管段码0~9

voiddisplayLed(void);

//显示led的主函数

voidkeyScan(void);

//键盘扫描处理函数

voidDelay10ms(unsignedintn);

//延时10ms

bitisPause=false;

//是否暂停

bitisAuto=true;

//是否自动运行

bitisChange=false;

//是否要切换下一个效果

uchartime;

//计时满0.5s

uchartypes;

//第几种灯光显示方案

uintcounts;

//灯光的第几个

/*******************************************************************************

*函数名:

T0_INT

*函数功能:

T0定时器中断函数

*输入:

*输出:

*******************************************************************************/

voidT0_INT(void)interrupt1

{

TL0=(65536-50000)/256;

TH0=(65536-50000)%256;

time++;

if(time>

=10)//定时时间:

0.5s

{

time=0;

if(isChange==true)//可以变换下一种显示效果了

counts=0;

types++;

//显示下一种效果

if(types>

9)types=0;

P0=disCode[types];

//更新数码管显示

isChange=false;

}

displayLed();

counts++;

}

main

主函数

voidmain(void)

TMOD=0x61;

//01100001//方式一

//50ms

TR0=1;

//开启T0

ET0=1;

//T0中断允许

EA=1;

//总中断开启

time=0;

//定时器时间扩种(0.5s)

//灯光的第几次

types=0;

//灯光显示模式

pauseLed=0;

//暂停指示灯灭

while

(1)

keyScan();

//键盘扫描及处理

keyScan

键盘扫描处理

voidkeyScan(void)

if(pause_key==0)//按下了暂停按钮

Delay10ms

(1);

if(pause_key==0)

isPause=~isPause;

pauseLed=isPause;

if(isPause==true)

ET0=0;

//关闭T0中断

P0=0xfd;

//数码管显示“-”

P1=0x00;

//所有的灯都亮起来

P2=0x00;

}else{

while(pause_key==0);

//防止按键重复检测

if(auto_key==0)//自动、手动切换按键按下

if(auto_key==0)

isAuto=~isAuto;

autoLed=isAuto;

while(auto_key==0);

if(change_key==0&

&

isAuto==false)//手动模式,并且效果切换按下

if(change_key==0)

isChange=true;

while(change_key==0);

displayLed

显示led灯

(全局变量)types:

显示效果;

counts:

当前效果下的第几次

voiddisplayLed(void)

switch(types)

case0:

//顺时针旋转led灯

if(counts>

=16)counts=0;

=15)

if(isAuto==true)isChange=true;

if(counts<

8)

P1=0xff;

P2=ledCode[7-counts];

else

P1=ledCode[15-counts];

P2=0xff;

break;

case1:

//逆时针旋转LED灯

P1=ledCode[counts];

P2=ledCode[counts-8];

case2:

//交叉替换

if(counts%2==0)//偶数

P1=0xaa;

P2=0xaa;

P1=0x55;

P2=0x55;

case3:

//对角顺时针

=8)counts=0;

=7)

P1=ledCode[7-counts];

P2=ledCode[7-counts];

case4:

//对角逆时针

if(isAuto==true)isChange=

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 动物植物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1