标题:
城市LED路灯控制电路和程序
[打印本页]
作者:
yuchengze
时间:
2016-12-23 20:41
标题:
城市LED路灯控制电路和程序
本帖最后由 yuchengze 于 2016-12-27 11:38 编辑
电路很简单,接在开关电源的稳压回路中就可控制城市的路灯了。这程序只控制关和开,全功率和半功率。24小时循环可不要人工干涉。
stm8单片机源程序:
#include"ADC.h"
#include "Eeprom.h" //包含用到的外设的头文件
extern u8 minlimit;
extern u8 maxlimit;
extern u16 right_valume;
extern u8 SaveDATA1H;
u8 Adj_Valume;
u8 DATA0H;
u8 ADJADDR;
extern u8 t1ms;
u8 Adc_Flag;
u8 HeCong;
u8 NoLight;
u8 NewLight;
u8 ADC_Valume;
u16 BufllAcc;
u8 BufllPoint;
u8 Adc_Bufll[8];
u8 ReadSample1(void)
{
right_valume = 0;
right_valume += ADC1->DB1RH;
right_valume += ADC1->DB2RH;
right_valume += ADC1->DB3RH;
right_valume += ADC1->DB4RH;
right_valume += ADC1->DB5RH;
right_valume += ADC1->DB6RH;
right_valume += ADC1->DB7RH;
right_valume += ADC1->DB8RH;
ADC_Valume = right_valume>>3; //求平均
return ADC_Valume;
}
u8 t =10;
void StartUP_ADC(void)
{
TIM1_SetCompare1(0); //改变PC1输出的PWM的占空比,0
t1ms = 0; //
while(t1ms <= t)
{
nop();
}
NoLight = ReadSample1(); //环境光
TIM1_SetCompare1(Adj_Valume); //改变PC1输出的PWM的占空比,80%
t1ms = 0;
while(t1ms <= t)
{
;
}
HeCong = ReadSample1(); //合成光
SaveDATA1H = NoLight - HeCong; //增量光,标准光点
}
/*******************************************************************************
* ==ADC初始化函数==
* ADC_DeInit(); --> 复位定时器4寄存器
*******************************************************************************/
void ADC_INIT(void)
{
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, ENABLE); //给ADC时钟
ADC1->CR1 = 0X03;//ADC = fMASTER /3 = f /4.使能ADC并开始转换
ADC1->TDRH = 0X00;//施密特触发器禁止
ADC1->TDRL = 0XF8;//施密特触发器禁止
ADC1->CSR = 0X03;//模拟通道 AIN4
ADC1->CR2 = 0X00;//单次转换模式,数据左对齐
ADC1->CR3 = 0X80;//数据缓存功能/禁止
ADC1->CR1 |= 0x01; //开始转换
}
u8 T1S_Count;
//ADC开始
void ADCStart(void)
{
T1S_Count++;
if(T1S_Count ==5)
{
T1S_Count = 0;
right_valume = 0;
right_valume += ADC1->DB1RH;
right_valume += ADC1->DB2RH;
right_valume += ADC1->DB3RH;
right_valume += ADC1->DB4RH;
right_valume += ADC1->DB5RH;
right_valume += ADC1->DB6RH;
right_valume += ADC1->DB7RH;
right_valume += ADC1->DB8RH;
NewLight = right_valume>>3; //求平均
DATA0H =NoLight - NewLight;
Adc_Flag = 1;
}
}
u8 w;
//ADC以查询方式工作
void AdjRight(void)
{
w = ~SaveDATA1H;
if(Adc_Flag == 1 ) //20MS抽一次
{
Adc_Flag = 0;
if(NewLight > w)
{
if(Adj_Valume <= maxlimit)
{
Adj_Valume++;
}
}
else if(NewLight < w)
{
if(Adj_Valume >= minlimit)
{
Adj_Valume--;
}
}
}
}
复制代码
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0