|
-實(shí)際項(xiàng)目:按鍵控制大功率燈珠實(shí)現(xiàn)調(diào)光】
項(xiàng)目實(shí)際電路圖:

程序:
/***********************************************************************/
/***名稱:按鍵控制PWM對(duì)大功率LED燈調(diào)光 ******************************/
/***功能:按動(dòng)按鍵可以實(shí)現(xiàn)9級(jí)調(diào)光,初始亮度為50% */
/*** 按鍵KEY1實(shí)現(xiàn)9級(jí)亮度調(diào)節(jié),按動(dòng)按鍵可以實(shí)現(xiàn)循環(huán) */
/***********************************************************************/
#include<reg51.h>
typedef unsigned char U8;
typedef unsigned int U16;
/*---------------------------------------------------------------------*/
/*-- 端口定義 ---------------------------------------*/
/*---------------------------------------------------------------------*/
sbit LED = P2^3;
sbit KEY1 = P2^0;
U8 j;
/*---------------------------------------------------------------------*/
/*-- 顯示子程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
void display()
{
U8 i;
for(i=255;i>0;i--)
LED=(j<i)?0x00:0xff;
}
/*---------------------------------------------------------------------*/
/*-- 按鍵子程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
void in_key()
{
if(KEY1==0)
{
while(~KEY1)
{
display();
}
if(j<251)
j+=31;
else
j=3;
}
}
/*---------------------------------------------------------------------*/
/*-- 主程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
void main()
{
LED=0X00;
IT0 = 0; //set INT0 int type (1:Falling 0:Low level)
EX0 = 1; //enable INT0 interrupt
EA = 1; //open global interrupt switch
j=127; //改變j的值就改變了占空比,初值50%
while(1)
{
display();
in_key();
}
}
/*---------------------------------------------------------------------*/
/*-- 程序結(jié)束 ---------------------------------------*/
/*---------------------------------------------------------------------*/
我想問下,如果是用三個(gè)色的LED是不是要用三顆驅(qū)動(dòng)芯片啊
回 這個(gè)是驅(qū)動(dòng)單色的3X1W(3顆1W串聯(lián))大功率LED燈珠調(diào)光的,有一個(gè)PT4115就是恒流IC,很多人在問我調(diào)光手電的原理,這就是調(diào)光手電的工作原理,和源程序!
|
|