照明用led多功能智能调光电路.docx
《照明用led多功能智能调光电路.docx》由会员分享,可在线阅读,更多相关《照明用led多功能智能调光电路.docx(12页珍藏版)》请在冰点文库上搜索。
照明用led多功能智能调光电路
电路图
电路功能:
1. 实现三个LED灯的十个不同亮度等级的调光,光强等级在数码管上显示出来;
2. 三个LED灯的调光方式可以有自动调光、手动调光和根据外部光强自动调光;
3. 本电路还可以进一步成为开发LED灯的更多功能的实验电路。
驱动程序:
#include
#defineucharunsignedchar
#defineuintunsignedint
#include
sbitst=P3^0;
sbitoe=P3^5;
sbiteoc=P3^1;
sbitup=P3^2;
sbitdown=P3^3;
sbitclk=P3^4;
sbitzd=P1^7;
sbitsd=P1^5;
sbitwd=P1^6;
sbitred=P1^0;
sbitgreen=P1^1;
sbitblue=P1^2;
ucharcodetab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0x39,0x5e,0x79,0x71,0x00,0xf3,0x76,0x80,0x40};//数码管显示段码
ucharm,k,l;
inta=5,b;
voidmaichong();
voiddelaynms(uintx);//nms延时程序
voidad0809();//芯片启动程序
main()
{
/*************自动调光程序********************/
while(!
zd)
{uinta,b;
ucharc,d;
for(a=0;a<10;a++)
{
if(!
zd)
{ for(c=20000;c>0;c--)
{for(d=10;d>0;d--)
{
red=1;
green=1;
blue=1;
P0=codetab[a];
delaynms(a);
b=10-a;
red=0;
green=0;
blue=0;
delaynms(b);
}
}
}
}
for(a=9;a>0;a--)
{
if(!
zd)
{ for(c=20000;c>0;c--)
{for(d=10;d>0;d--)
{
red=1;
green=1;
blue=1;
P0=codetab[a];
delaynms(a);
b=10-a;
red=0;
green=0;
blue=0;
delaynms(b);
}
}
}
}
}
/**********************手动调光程序**********************/
while(!
sd)
{ EA=1;
EX0=1;
EX1=1;
IT0=0;
IT1=0;
a=5;
while(!
sd)
{
P0=codetab[a];
red=1;
green=1;
blue=1;
delaynms(a);
red=0;
green=0;
blue=0;
delaynms(10-a);
}
}
/*******************************外动调光程序&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/
while(!
wd)
{
intm,i,shu,x;
while(!
wd)
{ clk=0;
st=0;
oe=0;
eoc=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=0;
st=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=0;
st=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
for(i=8;i--;i>0)//0~8个时钟周期
{
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
while(!
eoc)
{clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}//等待转换结束此时继续给脉冲
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=0;
oe=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
m=P2;//数据有效
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
oe=0;
_nop_();
_nop_();
_nop_();
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
shu=(m*2)/51;
for(x=5000;x--;x>0)
{
P0=codetab[shu];
red=1;
green=1;
blue=1;
for(i=shu;i--;i>0)
{
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
}
red=0;
green=0;
blue=0;
for(i=10-shu;i--;i>0)
{
clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
}
}
//nms延时程序
voiddelaynms(uintx)
{
uchari;
while(x-->0)
{
for(i=0;i<125;i++)
{;}
}
}
wbzd0()interrupt0
{while(!
up);
a++;
if(a>9)
a=9;
}
wbzd1()interrupt2
{
while(!
down);
a--;
if(a<0)
a=0;
}