具有暴闪功能的强光LED手电设计.docx

上传人:牧羊曲112 文档编号:5039860 上传时间:2023-05-31 格式:DOCX 页数:25 大小:140.64KB
返回 下载 相关 举报
具有暴闪功能的强光LED手电设计.docx_第1页
第1页 / 共25页
具有暴闪功能的强光LED手电设计.docx_第2页
第2页 / 共25页
具有暴闪功能的强光LED手电设计.docx_第3页
第3页 / 共25页
具有暴闪功能的强光LED手电设计.docx_第4页
第4页 / 共25页
具有暴闪功能的强光LED手电设计.docx_第5页
第5页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《具有暴闪功能的强光LED手电设计.docx》由会员分享,可在线阅读,更多相关《具有暴闪功能的强光LED手电设计.docx(25页珍藏版)》请在三一办公上搜索。

1、这是以前看一网友做的小玩意,看到现在有人发LED灯的电路就拿出来给需要的 参考 下。电路功能:单锂3WLED恒流驱动,3.0V-4.2V全程恒流,最大可输出700mA(实际 可达 1000mA);四种档位模式:1.三档调光+暴闪+慢闪+SOS+信标;2. 三档调光+暴闪+SOS;3. 二档调光;4. 六档调光+暴闪+慢闪+SOS+信标;有记忆功能;只有一个电源开关控制,关机关电源,完全不耗电;电池过放保护,电压低于3V进入应急模式自动切换到30 mA,电压低于2.7V进入休眠模式。,jNL: u:.住用开机检测是舂记恬冷能时版E1UF,使用关机拒则是否记已时取1成: ATtiny134.800

2、000 MHz: Tiny 0 :16DEBUG2/#define debug #include(原文件名:3454.jpg)引用图片有两种不同的代码,开机记忆或关机记忆 /* Chip typeClock frequency Memory model External SRAM size : Data Stack size 四组档位模式,关闭2秒记忆 */ /#define#include #define#define#define#define#defineCHANGE_WAITING 62MAX_CURRENT 9205233/5233=3.2V 4812=3.0V4331/4331=2

3、.7V1000/定义开机后是否变VOLTAGE_LIMIT_TO_30mAVOLTAGE_OUT_OFFVOLTAGECHANGE 换档位的电压值,如大于此值则变换档位,否则用上次关机时的档位#define K1 318682由于 3454在压控恒流模式工作时输出电流会随电池电压降低而升高,为了做到真正的 恒流,引入K1、K2根据电池电压对控制电压进行修正。#define K2 341#define XINGBIAO 3#define MAX_DANGWEI 9 #define ADEN ADCSRA.7#define ADSC ADCSRA.6#define EN_30mA PORTB.5#

4、define EN_PWM PORTB.1#define WDCE 4#define WDE 3eeprom unsigned char null;eeprom unsigned char circle=2;flash unsigned char time_set318=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,/ bao frash16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,/ flash4,8,4,8,4,25,12,8,12,8,12,25,4,8,4,8,4,50/ sos 亮(0.5秒)-

5、暗(1秒)-亮(0.5秒)-暗(1秒)-亮(0.5秒) -暗(3.5 秒)-亮(1.5 秒)-暗(1 秒)-亮(1.5 秒)-暗(1 秒)- 亮(1.5 秒)-暗(3.5 秒)-亮(0.5 秒)-暗(1 秒)-亮(0.5 秒)- 暗(1秒)-亮(0.5秒)-暗(3.5秒);flash unsigned int i_setMAX_DANGWEI+1=920,700,700,50,/xingbiao920,700,480,348,135,20;bit flashing_on_off;bit adc_busy;bit check_change_circle;unsigned char temp;un

6、signed char lower_times;unsigned char time_flash,frash_count;/ Watchdog timeout interrupt service routine interrupt WDT void wdt_timeout_isr(void) (if( temp!=XINGBIAO)(time_flash+;WDTCR|=0x40;if( temptime_settempfrash_count) (time_flash=0;frash_count+;if(frash_count17)(frash_count=0;flashing_on_off=

7、1; elseflashing_on_off=flashing_on_off; #ifndef DEBUG2/ ADC interrupt service routineinterrupt ADC_INT void adc_isr(void) ( unsigned int adc_result;adc_result=10*ADCW;if(check_change_circle=1)(check_change_circle=0;if(adc_resultVOLTAGE_CHANGE)temp+; switch (PINB&0x18) (case 0x08:/PB4 接地,三档调光+暴闪+慢闪+S

8、OS+信标(if(temp4)temp+;break;case 0x10:/PB3 接地,三档调光+暴闪+SOS(temp+;break;case 0x00:/PB3、PB4 接地,二档调光(temp=temp=5?7:4;break;default: break;没有连接,六档调光+暴闪+慢闪+SOS+信标if(tempMAX_DANGWEI)temp=0;circle=temp;if(adc_resultVOLTAGE_OUT_OFF)(EN_PWM=0;#ifndef debugEN_30mA=0;#endifelse(if(adc_result10)(TCCR0B=0x00;EN_PW

9、M=0;#ifndef debugEN_30mA=flashing_on_off;#endifelse(lower_times=0;EN_PWM=flashing_on_off;#ifndef debugEN_30mA=0;#endifOCR0A=(unsigned char)(K1-(unsigned long)K2*i_sett emp)/(adc_result);adc_busy=0;#endif/ Timer 0 output compare A interrupt service routine interrupt TIM0_COMPA void timer0_compa_isr(v

10、oid) (if(adc_busy=0)ADSC=1;adc_busy=1;void main(void)(#pragma optsize-#ifdef _OPTIMIZE_SIZE_#pragma optsize+#endif/PORTB=0x19;/DDRB=0x23;flashing_on_off=1;lower_times=0;time_flash=0;frash_count=0;#asm(sei) temp=circle;TIMSK0=0x04;DIDR0=0x0F;ADMUX=0x41;ADCSRA=0x8D;#pragma optsize-WDTCR |= (1WDCE)|(1W

11、DE);WDTCR=0x41; /64ms#ifdef _OPTIMIZE_SIZE_#pragma optsize+#endifOCR0A=200;TCCR0A=0x83;TCCR0B=0x01;check_change_circle=1;ADSC=1;adc_busy=1;while(check_change_circle=1);delay_ms(1);while (1)(if(temp=XINGBIAO)(EN_30mA=1;delay_ms(50);EN_30mA=0;#pragma optsize-WDTCR |= (1WDCE)|(1WDE);WDTCR=0x60; /4s#ifd

12、ef _OPTIMIZE_SIZE_#pragma optsize+#endifMCUCR=0x20;#asm(sleep);#asm(NOP);/*Chip typeClock frequencyMemory modelExternal SRAM sizeData Stack size: ATtiny13:4.800000 MHz: Tiny:0:16四组档位模式,两秒连续内按开关换档,点亮超过2秒记忆当前档,*/#define DEBUG2/#define debug#include #include #define CHANGE_WAITING 62#define MAX_CURRENT

13、 920#define VOLTAGE_LIMIT_TO_30mA 5233/5233=3.2V 4812=3.0V#define VOLTAGE_OUT_OFF4331/4331=2.7V#define K1 333167/由于3454在压控恒流模式工作时输出电流会随电池电压降低而升高,为了做到真正的恒流,引入K1、K2根据电池电 压对控制电压进行修正。#defineK2 292#defineXINGBIAO3#defineMAX_DANGWEI9#defineADEN ADCSRA.7#defineADSC ADCSRA.6#defineEN_30mAPORTB.5#defineEN_PW

14、MPORTB.1#defineWDCE 4#defineWDE 3eepromunsignedcharnull;eepromunsignedcharchange_needed=0;eepromunsignedcharcircle=2;flash unsigned char time_set318=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,/ bao frash16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,/ flash4,8,4,8,4,25,12,8,12,8,12,25,4,8,4,8,4,50/

15、 sos 亮(0.5秒)-暗(1秒)-亮(0.5秒)-暗(1秒)-亮(0.5秒) -暗(3.5 秒)-亮(1.5 秒)-暗(1 秒)-亮(1.5 秒)-暗(1 秒)- 亮(1.5 秒)-暗(3.5 秒)-亮(0.5 秒)-暗(1 秒)-亮(0.5 秒)- 暗(1秒)-亮(0.5秒)-暗(3.5秒);flash unsigned int i_setMAX_DANGWEI+1=650,650,650,50,/xingbiao1000,750,520,350,180,50;bit flashing_on_off;bit adc_busy;unsigned char temp;unsigned cha

16、r time,lower_times;unsigned char time_flash,frash_count;/ Watchdog timeout interrupt service routine interrupt WDT void wdt_timeout_isr(void) (if( temp!=XINGBIAO)(time_flash+;WDTCR|=0x40;if(timeCHANGE_WAITING)time+;else(if(change_needed!=0)change_needed=0;if( temptime_settempfrash_count)(time_flash=

17、0;frash_count+;if(frash_count17)(frash_count=0;flashing_on_off=1; else(flashing_on_off=flashing_on_off; #ifndef DEBUG2/ ADC interrupt service routine interrupt ADC_INT void adc_isr(void) ( unsigned int adc_result;adc_result=10*ADCW;(if(adc_resultVOLTAGE_OUT_OFF)(EN_PWM=0;#ifndef debug EN_30mA=0;#end

18、ifelse(if(adc_result10)(TCCR0B=0x00;EN_PWM=0;#ifndef debugEN_30mA=flashing_on_off;#endifelse(lower_times=0;EN_PWM=flashing_on_off;#ifndef debugEN_30mA=0;#endifif(flashing_on_off=0)(OCR0A=200;else(OCR0A=(unsigned char)(K1-(unsigned long)K2 *i_settemp)/(adc_result);adc_busy=0;#endif/ Timer 0 output co

19、mpare A interrupt service routine interrupt TIM0_COMPA void timer0_compa_isr(void) (if(adc_busy=0)ADSC=1;adc_busy=1;void main(void)(#pragma optsize-#ifdef _OPTIMIZE_SIZE_#pragma optsize+#endif/PORTB=0x19;/DDRB=0x23;TCCR0A=0x83;flashing_on_off=1;time=0;lower_times=0;time_flash=0;frash_count=0;#asm(se

20、i)temp=circle;if(change_needed=0)(change_needed=1;else(temp+;switch (PINB&0x18)(case 0x08:/PB4 接地,三档调光+暴闪+慢闪+SOS+信标(if(temp4)temp+;break;case 0x10:/PB3 接地,三档调光+暴闪+SOS(temp+;break;case 0x00:/PB3、PB4 接地,二档调光(temp=temp=5?7:4;break;default: break;没有连接,六档调光+暴闪+慢闪+SOS+信标if(tempMAX_DANGWEI) temp=0;circle=t

21、emp;if(temp!=XINGBIAO)(/GIMSK=0x20;/PCMSK=0x10;/GIFR=0x20;TIMSK0=0x04;DIDR0=0x0F;ADMUX=0x41;ADCSRA=0x8D;#pragma optsize-WDTCR |= (1WDCE)|(1WDE);WDTCR=0x41; /64ms#ifdef _OPTIMIZE_SIZE_#pragma optsize+#endifOCR0A=250;TCCR0B=0x01;delay_ms(5);adc_busy=0;while (1)(if(temp=XINGBIAO)(EN_30mA=1;delay_ms(100

22、);EN_30mA=0;#pragma optsize-WDTCR |= (1WDCE)|(1(原文件名:sch.jpg)引用图片/*This program was produced by theCodeWizardAVR V2.03.9 StandardAutomatic Program Generator?Copyright 1998-2008 Pavel Haiduc, HP InfoTechProject :Version :Date: 2009-4-3Author : userCompany : DellComments: ATtiny134.800000 MHz: Tiny:0:

23、24Chip typeAVR Core Clock frequency:Memory modelExternal RAM size Data Stack sizeREF=1.07V */#include #include #define DEBUG 0#define OUT_ENABLEPORTB.0#define KEY_CHECKPINB.2#define BOOST_ENABLEPORTB.3#define OUTPUT_VOLTAGE_SELECT PORTB.1PORTB.5 01#if !DEBUG#define LED_OUT#define LED_ON#define LED_O

24、FF#endif #define WDCE 4#define WDE 3#define ADEN ADCSRA.7#define ADSC ADCSRA.6volatileunsignedchartemp_v16;volatileunsignedcharCount;volatileunsignedcharReal_voltage;volatileunsignedcharSystem_statesunsigned char Shut_up_voltage;unsigned int Worked_timer_count;bit adc_busy;bit enable_lower_voltage_p

25、rotect;unsigned char Lower_voltage_checked_times;interrupt PCINT0 void pin_change_isr(void) (unsigned char i=0;while(KEY_CHECK=0)(i+;delay_ms(10);if(i=250)/if(KEY_CHECK=1|i=250)(break;if(i=200)按钮按下时间大于2秒,启动或关闭输出(if(System_states!=2)(System_states=2;Worked_timer_count=0;else(System_states=0;else按钮按下时

26、间小于2秒,启动或关闭放电低电压保护,并显示空载电压值及低电压保护值(if(i=5)(if(System_states!=2)(System_states=1;enable_lower_voltage_protect=enable_lower_voltage protect;/ Watchdog timeout interrupt service routine/interrupt WDT void wdt_timeout_isr(void)/ Timer 0 output compare A interrupt service routine interrupt TIM0_COMPA voi

27、d timer0_compa_isr(void) (if(adc_busy=0)(ADSC=1;adc_busy=1;/ ADC interrupt service routine interrupt ADC_INT void adc_isr(void) (unsigned char i;unsigned int temp;temp_vCount=ADCH;Count+;if(Count15)(Worked_timer_count+;Count=0;temp=0;for(i=0;i16;i+)(temp+=(unsigned int)temp_vi;Real_voltage=(unsigned

28、 char)(unsigned long )temp*1531)/100 000);if(Real_voltage=22500)/电池电压低或约一小时后关闭输出(Lower_voltage_checked_times+;if(Lower_voltage_checked_times3) /连续三次采样都低于 保护值(System_states=0;BOOST_ENABLE =0;OUT_ENABLE=1; #if !DEBUG LED_OUT=LED_OFF;#endifelse(Lower_voltage_checked_times=0;adc_busy=0;/*显示数值,长闪次数为十位数值,

29、短闪次数为个位数值 /* void display_value(unsigned char value) (#if !DEBUGunsigned char i;unsigned char temp;temp二value/10;for(i=0;itemp;i+)(LED_OUT=LED_OFF;delay_ms(200);LED_OUT=LED_ON;delay_ms(500);temp=value%10;for(i=0;i=31)大于3.1V,低电压保护值设为2.8V (带载时),用于锂电池过放保护(Shut_up_voltage=28;else(if(Real_voltage=20)大于2.

30、0V,低电压保护值设为1.0V (带载时),用于2x镍电池过放保 护(Shut_up_voltage=1文档从互联网中收集,已重新修正排版,word格式支持编辑,如有帮助欢迎下载支持。 0;else(Shut_up_voltage=4 ;小于2.0V,低电压保护值设为0.4V (带载时), 用于1x镍电池过放保护 else ( Shut_up_voltage=0;/如果不启用过放保护,低电压保护值设为0.0V,用于非可充电池delay_ms(1000);display_value(Shut_up_voltage); / 显示低电压保护值System_states=0;break; case 2

31、: ( OUTPUT_VOLTAGE_SELECT=1; BOOST_ENABLE =1; OUT_ENABLE=0; display_value(Real_voltage); / /显示带载电池电压delay_ms(3000);break;default:未启动输出,进入休眠(Worked_timer_count=0;BOOST_ENABLE =0;OUT_ENABLE=1;#if !DEBUGLED_OUT=LED_OFF;#endif#pragma optsize-MCUCR=0x20;#asm(sleep);#asm(NOP);;#ifdef _OPTIMIZE_SIZE#pragma optsize+#endifbreak;

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

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号