直流电子负载Word文档格式.docx
《直流电子负载Word文档格式.docx》由会员分享,可在线阅读,更多相关《直流电子负载Word文档格式.docx(19页珍藏版)》请在冰豆网上搜索。
2.4单片机模块设计
单片机模块基本电路
三、测试及分析
测试原始数据
1.恒流模式数据测量
模式
设定值(A)
测量值1(A)
测量值2(A)
测量值3(A)
工作电压(V)
恒流
0.37
0.43
0.85
2.08
3.49
0.75
0.76
1.23
2.43
4.45
1.13
1.15
1.42
4.09
5.38
1.70
1.72
2.29
4.66
6.22
1.89
1.91
3.24
5.35
6.87
2.恒压模式数据测量
设定值(V)
测量值1(V)
测量值2(V)
测量值3(V)
恒压
1.11
1.12
1.68
3.81
7.40
3.11
3.16
3.08
3.14
4.87
7.34
10.25
9.00
8.96
9.04
9.04
10.03
12.27
15.33
15.22
15.16
15.24
15.18
15.49
17.78
19.34
20.00
19.92
19.84
19.90
20.22
21.12
22.23
四、附录
基本程序
恒流模块
#include<
reg52.h>
#include<
intrins.h>
#defineuintunsignedint
#defineucharunsignedchar
sbitrs=P2^7;
sbitE=P2^6;
sbitadwr=P2^5;
sbitadrd=P2^4;
floatadval;
longinttemp;
voiddelay(uintz)//延时子程序
{
uintx,y;
for(x=z;
x>
0;
x--)
for(y=110;
y>
y--);
}
write_com(ucharcom)//写命令
{
rs=0;
P0=com;
delay(5);
E=1;
E=0;
write_data(uchardat)//写数据
rs=1;
P0=dat;
init()//液晶初始化
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80+3);
voidDisplay_Resulti(uchardac)//恒流设定值子程序
floatdb=0.0;
ucharshi=0,ge=0,xs=0,xxs=0;
P3=dac;
db=dac*3.00/158.00;
shi=(int)db/10;
ge=(int)db%10;
db*=10.0;
xs=(int)db%10;
xxs=(int)db%10;
write_com(0x80+1);
delay
(2);
write_data('
c'
);
u'
r'
e'
n'
t'
write_data(0x3a);
if(shi==0)
{
write_data(0x20);
}
else
write_data(0X30+shi);
write_data(0X30+ge);
write_data(0x2e);
write_data(0x30+xs);
write_data(0x30+xxs);
voidDisplay_Resulti1(floatadval)//测量电流值子程序
ucharge,xs,shi,xxs;
temp=(longint)(adval*105/51);
shi=temp/1000;
ge=temp/100%10;
xs=temp/10%10;
xxs=temp%10;
write_com(0x80+0x40+1);
C'
U'
R'
E'
N'
T'
voidADC()//启动AD转换
adwr=1;
_nop_();
adwr=0;
P1=0xff;
adrd=1;
adrd=0;
adval=P1;
voidmain()//主程序
init();
TMOD=0x02;
//定时器初始化
TH0=0x6f;
TL0=0x00;
IE=0x82;
TR0=1;
while
(1)//显示模块
ucharkey=0;
bitkeyflag=1;
uintdac=0;
Display_Resulti(dac);
while
(1)//键盘扫描控制显示
{Display_Resulti1(adval);
ADC();
key=P2&
0x0f;
switch(key)
{
case0x0e:
if(keyflag)
dac=0;
Display_Resulti(dac);
keyflag=0;
}
break;
case0x0d:
if(keyflag)
dac+=10;
keyflag=0;
case0x0b:
dac-=10;
case0x07:
dac=158;
case0x0f:
keyflag=1;
break;
}
恒压模块
voidDisplay_Resultu1(floatadval)//恒压设定值子程序
temp=(longint)(adval*110/51);
temp=temp*4;
sh