《重点资料照明用led多功能智能调光电路.doc》由会员分享,可在线阅读,更多相关《重点资料照明用led多功能智能调光电路.doc(12页珍藏版)》请在装配图网上搜索。
电路图
电路功能:
1. 实现三个LED灯的十个不同亮度等级的调光,光强等级在数码管上显示出来;
2. 三个LED灯的调光方式可以有自动调光、手动调光和根据外部光强自动调光;
3. 本电路还可以进一步成为开发LED灯的更多功能的实验电路。
驱动程序:
#include
#define uchar unsigned char
#define uint unsigned int
#include
sbit st=P3^0;
sbit oe=P3^5;
sbit eoc=P3^1;
sbit up=P3^2;
sbit down=P3^3;
sbit clk=P3^4;
sbit zd=P1^7;
sbit sd=P1^5;
sbit wd=P1^6;
sbit red=P1^0;
sbit green=P1^1;
sbit blue=P1^2;
uchar codetab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0x39,0x5e,0x79,0x71,0x00,0xf3,0x76,0x80,0x40};//数码管显示段码
uchar m,k,l;
int a=5,b;
void maichong();
void delaynms(uint x);//nms延时程序
void ad0809();//芯片启动程序
main()
{
/*************自动调光程序********************/
while(!zd)
{uint a,b;
uchar c,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)
{
int m,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 延时程序
void delaynms(uint x)
{
uchar i;
while(x-->0)
{
for(i=0;i<125;i++)
{;}
}
}
wbzd0() interrupt 0
{ while(!up);
a++;
if(a>9)
a=9;
}
wbzd1() interrupt 2
{
while(!down);
a--;
if(a<0)
a=0;
}
链接地址:https://www.zhuangpeitu.com/p-8794554.html