《LED数显太阳能充电控制器基本资料介绍.doc》由会员分享,可在线阅读,更多相关《LED数显太阳能充电控制器基本资料介绍.doc(28页珍藏版)》请在三一办公上搜索。
1、LED太阳能充电控制器原理图第一层原理图第二层原理图第三层原理图PCB版图拼版图(PCB)PCB打样仿真图仿真图(proteus)实物图实物图(1)实物图(2)实物图(3)源程序/*|=太阳能充电控制器=|使用芯片:ATMEGA8A软件设计人:何涛工程开始时间:2012.06.12联系电话:13798974197(珠海)QQ:562673469=|*/*74HC164.C*/#include app.hvoid Show_164(unsigned char _ShowValue) unsigned char Count0; for(Count0=0;Count0=1; PORTD=PORTD&
2、0XFD; /CLK 0 /delay(1); PORTD=PORTD|0X02; /CLK 1 /delay(10); PORTD=PORTD|0X02; /CLK 1 /*74HC164.H*/void Show_164(unsigned char _ShowValue);/*AD.C*/#include app.h/*ADC*/void ADC_Init(INT8U channel) /*/ switch(channel)/AREF2.56V ADLAR channelcase 0:ADMUX=0xc0+0;break;case 1:ADMUX=0xc0+1;break;case 2:A
3、DMUX=0xc0+2;break;case 3:ADMUX=0xc0+3;break;case 4:ADMUX=0xc0+4;break;case 5:ADMUX=0xc0+5;break;case 6:ADMUX=0xc0+6;break;case 7:ADMUX=0xc0+7;break;default:break; ADCSRA=0x00;/ 16INT16U ADC_Start(INT8U channel) INT8U Temp_L; INT8U Temp_H;INT16U AD_Data;switch(channel)case 0:ADMUX=0xc0+0;break;case 1
4、:ADMUX=0xc0+1;break;case 2:ADMUX=0xc0+2;break;case 3:ADMUX=0xc0+3;break;case 4:ADMUX=0xc0+4;break;case 5:ADMUX=0xc0+5;break;case 6:ADMUX=0xc0+6;break;case 7:ADMUX=0xc0+7;break;default:break; ADCSRA |=0xC0;/AD Temp_L=ADCL; Temp_H=ADCH;AD_Data=Temp_H*256+Temp_L;ADCSRA =0x80;/AD switch(channel)case 0:A
5、DMUX=0xc0+0;break;case 1:ADMUX=0xc0+1;break;case 2:ADMUX=0xc0+2;break;case 3:ADMUX=0xc0+3;break;case 4:ADMUX=0xc0+4;break;case 5:ADMUX=0xc0+5;break;case 6:ADMUX=0xc0+6;break;case 7:ADMUX=0xc0+7;break;default:break; ADCSRA |=0xC0;/AD Temp_L=ADCL; Temp_H=ADCH; AD_Data=Temp_H*256+Temp_L;ADCSRA =0x80;/A
6、D return(AD_Data);void AD_select(INT8U channel) switch(channel) case 0:LED_NUM20=ADC_Start(6)/4;break;/UXX.X 10 case 1:LED_NUM21=ADC_Start(7)/4;break;/AXX.X case 2:LED_NUM22=ADC_Start(0)/4;break;/bXX.X case 3:LED_NUM23=ADC_Start(1)/4;break;/CXX.X /*AD.H*/void ADC_Init(unsigned char channel);unsigned
7、 int ADC_Start(unsigned char channel);void AD_select(unsigned char channel);/*APP.H*/#include #include #include /#include Kernel.h/#include task.h#include misc.h#include initial.h#include 74HC164.h#include delay.h#include LED.h#include AD.h#include EEPROM.h/*DELAY.H*/#include app.hunsigned int Min =
8、 0;/unsigned int Sec = 0;/void delay(unsigned int a) unsigned int i,j; for(i=0;ia;i+) for(j=0;j59) Sec = 0; Min +; /*DELAY.H*/extern unsigned int Min;/extern unsigned int Sec;/extern unsigned int Count,flag_count;/void delay(unsigned int a);void SolarCount(void);/*EEPROM.H*/#include app.hvoid EEPROM
9、_Init(void) INT8U i=0; flag_0 =EEPROMread(1); flag_3 =EEPROMread(4); flag_4 =EEPROMread(5); flag_5 =EEPROMread(6); flag_6 =EEPROMread(7); flag_7 =EEPROMread(8); flag_9 =EEPROMread(10); flag_10=EEPROMread(11);void EEPROM_Start(void) EEPROMwrite(1,flag_0); EEPROMwrite(4,flag_3); EEPROMwrite(5,flag_4);
10、 EEPROMwrite(6,flag_5); EEPROMwrite(7,flag_6); EEPROMwrite(8,flag_7);/125 EEPROMwrite(10,flag_9); EEPROMwrite(11,flag_10);void EEPROM_Recover(void) EEPROMwrite(1,6); EEPROMwrite(4,50); EEPROMwrite(5,108); EEPROMwrite(6,144); EEPROMwrite(7,0); EEPROMwrite(8,125); EEPROMwrite(10,0); EEPROMwrite(11,0);
11、 /*EEPROM.C*/void EEPROM_Init(void);void EEPROM_Start(void);void EEPROM_Recover(void);/*INITIAL.C*/#include app.hINT16U Time1=3;void Gpio_Init(void);void Timer1_Init(void);void Timer2_Init(void);void Interrupt_Init(void);void Battery_Init(void);void Hardware_Init(void) ADC_Init(6); EEPROM_Init(); Gp
12、io_Init();Timer1_Init(); Timer2_Init(); Interrupt_Init();Battery_Init(); void Battery_Init(void) INT16U i=4,j=5; while(Time1)/6s if(flag_count=1) Time1-;flag_count=0; Display4(Time1); while(i-) while(j-) Display1(windows_1,120); PORTD=0XFF; delay(1000); j=8; / delay(100); /*void Gpio_Init(void)DDRB
13、= 0xDF; /PB5PORTB = 0x20; DDRC = 0x00;PORTC = 0xFF; DDRD = 0xFF; PORTD = 0xFF; /TIMER1 initialize - prescale:1024/ WGM: 0) Normal, TOP=0xFFFF/ desired value: 1Hz/ actual value: 1.000Hz (0.0%)void Timer1_Init(void) TCCR1B = 0x00; /stop TCNT1H = 0xFF; /setup TCNT1L = 0xB2; OCR1AH = 0x00; OCR1AL = 0x4E
14、; OCR1BH = 0x00; OCR1BL = 0x4E; ICR1H = 0x00; ICR1L = 0x4E; TCCR1A = 0x00; TCCR1B = 0x05; /start Timer TIMSK |= 0x10;/Avoid Timer2_Init(void) TCCR2 = 0x00; /stop ASSR = 0x00; /set async mode TCCR2 = 0x0F; /start TCNT2 = 0x00; /setup OCR2 = 0x4D; TIMSK|= 0x80; void Interrupt_Init(void)SREG |= 0x80; /
15、Enable Global Interrupt/*INITIAL.H*/void Hardware_Init(void);/*INTERPUTL.C*/#include app.hunsigned int Count=0,flag_count=0;/#pragma interrupt_handler Timer1_Interrupt:7void Timer1_Interrupt(void)/Clear Timer2 OCIF FlagTIFR |= 0x10; TCNT2 = 0x00;#pragma interrupt_handler Timer2_Interrupt:4void Timer
16、2_Interrupt(void)TIFR |= 0x80;/Clear Timer2 OCIF Flag TCNT2 = 0x00;Count+;if(Count100) Count=0; flag_count=1;/1S SolarCount();/if(flag_timestart!=1)/Min=0;/*LCD.C*/#include app.hINT8U LED_NUM=0x28,/*0*/ 0xEB,/*1*/ 0x32,/*2*/ 0xA2,/*3*/ 0xE1,/*4*/ 0xA4,/*5*/ 0x24,/*6*/ 0xEA,/*7*/ 0x20,/*8*/ 0xA0,/*9*
17、/ 0x60,/*A*/ 0x25,/*b*/ 0x3C,/*C*/ 0x74,/*F*/ 0x29,/*U*/ 0xFF,/* 15*/;/INT8U LED_NUM1=0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x0E,0x41; /+INT8U LED_NUM1= 0x08,/*0*/ 0xCB,/*1*/ 0x12,/*2*/ 0x82,/*3*/ 0xC1,/*4*/ 0x84,/*5*/ 0x04,/*6*/ 0xCA,/*7*/ 0x00,/*8*/ 0x80,/*9*/ 0x40,/*A*/
18、 0x05,/*B*/ 0x1C,/*C*/ 0x54,/*F*/ 0x09,/*U*/ 0xFF,/* 15*/ ;INT8U LED_NUM2=0,1,2,3;INT16U Fixed_Time=1,5,10,60,120,180,240,300,360,420,480,540,600,660,720;/14void Display2(INT8U value);void Display3(INT8U value);void Display1(INT8U windows,INT8U value) INT8U s=value; if(windows=0) /1 UXX.X Show_164(L
19、ED_NUM14); PORTD=0XD8; delay(10); if(windows=1) /2 AXX.X B Show_164(LED_NUM10); PORTD=0XD8; delay(10); if(windows=2) /3 bXX.X A Show_164(LED_NUM11); PORTD=0XD8; delay(10); if(windows=3) /4 CXX.X Show_164(LED_NUM12); PORTD=0XD8; delay(10); Show_164(LED_NUMs/100); PORTD=0X78; delay(10); Show_164(LED_N
20、UM1s%100/10); PORTD=0XB8; delay(10); Show_164(LED_NUMs%10); PORTD=0XE8; delay(10); void Display2(INT8U value) INT8U s=value; Show_164(LED_NUM113); /F.XXX PORTD=0XD8; delay(10); Show_164(LED_NUM0); PORTD=0X78; delay(10); Show_164(LED_NUMs/10); PORTD=0XB8; delay(10); Show_164(LED_NUMs%10); PORTD=0XE8;
21、 delay(10); void Display3(INT8U value) INT8U s=value; Show_164(LED_NUMs/100); PORTD=0XD8; delay(10); Show_164(LED_NUM1s%100/10); PORTD=0X78; delay(10); Show_164(LED_NUMs%10); PORTD=0XB8; delay(10); Show_164(LED_NUM14); /XX.XU PORTD=0XE8; delay(10); void Display4(INT16U value)/ XXXX INT16U t=value; S
22、how_164(LED_NUMt/1000); PORTD=0XD8; delay(10); Show_164(LED_NUMt%1000/100); PORTD=0X78; delay(10); Show_164(LED_NUMt%100/10); PORTD=0XB8; delay(10); Show_164(LED_NUMt%10); PORTD=0XE8; delay(10); void Display5(INT16U value) INT16U t=value; /720min Show_164(LED_NUMt/100);/7 PORTD=0XD8; delay(10); Show
23、_164(LED_NUMt%100/10);/2 PORTD=0X78; delay(10); Show_164(LED_NUMt%10);/0 PORTD=0XB8; delay(10); if(Count50) Show_164(0XDF);/ else if(Count4)i=0; Key_Manage(); if(flag_timestart!=1)/ Display(); else if(flag_timestart=1)/ Display5(Fixed_Timeflag_0-Min); judgement(); performance(); LED_Control(); /*MIS
24、C.C*/#include app.h/*/*/ INT8S flag_0=6;/10.8 INT8U flag_4=108;/10.8 INT8U flag_5=144;/14.4 INT8U flag_7=125;/12.5 INT8U flag_3=20; INT8S flag_6=0; INT8U flag_9=0; INT8U flag_10=0; INT8U flag_11=0; INT8U flag_timestart=0;/ 1 INT8U flag_light=0; / INT8U flag_wait=0; /*/ INT8U Enter1=0; INT8U Enter2=0
25、; INT8U Enter3=0;/*/ INT8U windows_1=0;/ INT8S windows_2=0;/11/*/ INT8U flag_undervoltage=0;/ INT8U flag_overvoltage =0;/*/ INT16U Time=4;/*/ INT8U OUT_A=0,OUT_B=0,CHA=0,CHB=0;/local function(s) declarationINT16U swGet_Key1(void);INT16U swGet_Key2(void);INT16U swGet_Key3(void);INT16U swGet_Key4(void
26、);/*INT16U swGet_Key1(void)static INT16U wKeyStatus = 1;if(wKeyStatus = 1)if(PINB & (1 Key_R) = 0) /Key PressedwKeyStatus = 0;else if(wKeyStatus = 0)if(PINB & (1 Key_R) /Key ReleasedwKeyStatus = 1;return(true);return(false);/*INT16U swGet_Key2(void)static INT16U wKeyStatus = 1;if(wKeyStatus = 1)if(P
27、INC & (1 Key_S) = 0) /Key PressedwKeyStatus = 0;else if(wKeyStatus = 0)if(PINC & (1 Key_S) /Key ReleasedwKeyStatus = 1;return(true);return(false);/*INT16U swGet_Key3(void)static INT16U wKeyStatus = 1;if(wKeyStatus = 1)if(PINC & (1 Key_A) = 0) /Key PressedwKeyStatus = 0;else if(wKeyStatus = 0)if(PINC
28、 & (1 Key_A) /Key ReleasedwKeyStatus = 1;return(true);return(false);/*INT16U swGet_Key4(void)static INT16U wKeyStatus = 1;if(wKeyStatus = 1)if(PINC & (1 Key_B) = 0) /Key PressedwKeyStatus = 0;else if(wKeyStatus = 0)if(PINC & (1 Key_B) /Key ReleasedwKeyStatus = 1;return(true);return(false);/*INT8U Ke
29、y_Detection(void)if(swGet_Key1() = true)return 3;if(swGet_Key2() = true)return 4;if(swGet_Key3() = true)return 2;if(swGet_Key4() = true)return 1;return 0;/*void Key_Manage(void) switch(Key_Detection() case S: if(!(Enter1|Enter2|Enter3)Enter1=1;break;/ if(Enter1=1)Enter2=1;Enter1=0;break;/ if(Enter2=1)Enter3=1;Enter2=0;/ if(Enter3=1) while(Time) if(flag_count=1) Time-;flag_count=0; Display4(Time);if(flag_11=0)EEPROM_Start(); /else