由于仿真protues中缺少电源芯片,故设计分为了两部分,protues实现的是输入端电压的调节,交流电电压调节的范围为85-265VAC.
LED驱动电源电路用altium designer绘制,交流电的输入到53V直流电压的输出。其中包含了变压器,桥式整流,电源芯片等电路。
完整版 电路图和程序代码 下载地址
https://pan.baidu.com/s/1cqWg2X2VoDSn1tZKHTRX2A?pwd=8888
部分代码展示
#include <reg51.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
/******六位七段共阴极数码显示管*******/
uchar code dispbitcode[] = { 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
uchar code dispcode[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00, 0x76, 0x38 };
uchar dispbuf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
void caiji();
void uart();
uint temp, temp1, temp2;
float getdata1, getdata2, max1, max2;
uint w; /* 电压值,电流值切换显示所需变量 */
uchar num = 0;
sbit dula = P2 ^ 0;
sbit wela = P2 ^ 1;
sbit vi = P2 ^ 2;
sbit xuan = P2 ^ 3;
sbit ST = P3 ^ 6;
sbit OE = P3 ^ 7;
sbit EOC = P3 ^ 4;
sbit clock = P3 ^ 2;
/******主函数********/
void main()
{
xuan = 0;
max1 = 0;
max2 = 0;
w = 0;
SCON = 0x80; /* 串行口初始化为方式2 */
PCON = 0x00;
EA = 1;
ES = 1;
ET0 = 1;
ET1 = 1;
TMOD = 0x11;
TH0 = (65535 - 10) / 256; /* adc0809时钟 */
TL0 = (65535 - 10) % 256;
TH1 = (65535 - 10000) / 256; /* 定时中断扫描时间 */
TL1 = (65535 - 10000) % 256;
TR0 = 1;
TR1 = 1;
while ( 1 )
{
caiji();
uart();
}
}
/********电压,电流传感器的数据采集*******/
void caiji()
{
uchar i, j;
/*电压传感器数据采集*/
for ( j = 0; j < 10; j++ )
{
getdata1 = 0;
vi = 0;
ST = 1;
ST = 0;
ST = 1;
while ( EOC == 1 )
;
while ( EOC == 0 )
;
OE = 0;
getdata1 = P1;
for ( i = 0; i <= 200; i++ )
;
OE = 1;
getdata1 = getdata1 / 51 * 717 / 250 * 4400;
if ( getdata1 > max1 )
max1 = getdata1;
temp1 = max1 / 1.414;
}
/*
* if(temp1>22000)
* temp1=22000;
*/
/*电流传感器数据采集*/
for ( j = 0; j < 10; j++ )
{
getdata2 = 0;
vi = 1;
ST = 1;
ST = 0;
ST = 1;
while ( EOC == 1 )
;
while ( EOC == 0 )
;
OE = 0;
getdata2 = P1;
for ( i = 0; i <= 200; i++ )
;
OE = 1;
getdata2 = getdata2 / 51 * 717 / 250 * 800;
if ( getdata2 > max2 )
max2 = getdata2;
temp2 = max2 / 1.414;
/*
* if(temp2>4000)
* temp2=4000;
*/
}
}
/********串行口发送电压,电流值的有效值**********/
void uart()
{
uchar i;
SBUF = temp1; /* 启动串口发送 */
for ( i = 0; i < 200; i++ )
;
}