If Pind.3 = 0 Then '启动
Waitms 20
If Pind.3 = 0 And A = 0 Then
A = A1
Locate 1 , 12
Lcd "ON "
Waitms 250
End If
End If
If Pind.3 = 0 Then '停止
Waitms 20
If Pind.3 = 0 And A > 1 Then
A1 = A
A = 0
Locate 1 , 12
Lcd "OFF"
End If
End If
If Pind.4 = 1 Then B2 = 0 '电压+
If Pind.4 = 0 Then
Waitms 20
If Pind.4 = 0 Then
If A < 1023 Then
A = A + 1
B2 = B2 + 1
If B2 > 20 And A < 1013 Then
A = A + 10
End If
End If
End If
End If
If Pind.5 = 1 Then B3 = 0 '电压-
If Pind.5 = 0 Then
Waitms 20
If Pind.5 = 0 Then
If A > 1 Then
A = A - 1
B3 = B3 + 1
If B3 > 20 And A > 10 Then
A = A - 10
End If
End If
End If
End If
If Pind.6 = 1 Then B4 = 0 '电流+
If Pind.6 = 0 Then
Waitms 20
If Pind.6 = 0 Then
If C < 1500 Then
C = C + 1
B4 = B4 + 1
If B4 > 20 And C < 1480 Then
C = C + 20
End If
End If
End If
End If
If Pind.7 = 1 Then B5 = 0 '电流-
If Pind.7 = 0 Then
Waitms 20
If Pind.7 = 0 Then
If C > 1 Then
C = C - 1
B5 = B5 + 1
If B5 > 20 And C > 20 Then
C = C - 20
End If
End If
End If
End If
ATMEGA制作0一20V数控电源说明.pdf 下载积分: 积分 -1 分
588.34 KB, 下载次数: 56, 下载积分: 积分 -1 分
电源
'///////////////////////////////////////////////////////////////////////////////
'/ /
'/ 这是一个M8控制LM317的直流稳压电源 /
'/ 输出电压 0-20V 连续调节 /
'/ 最大输出电流 1.5A /
'/ 截止型过电流保护 0-1.5A 连续调节 /
'/ /
'///////////////////////////////////////////////////////////////////////////////
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.0 , Rs = Portd.2
Config Lcd = 16 * 2
'定义LED是16字符,2行
Config Adc = Single , Prescaler = Auto , Reference = Internal
'定义ADC为单次运行模式,转换时钟-自动,内部参考电压
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Prescale = 1
'PWM1A配置,用于数模转换,
Ddrb.1 = 1 'PWM1A输出端子
'定义所需要变量 ////////////////////////////////////////////////////////////////
Dim V_dc As Long , A_dc As Long , W As Long
Dim V1_dc As Word , A1_dc As Word , A As Word , C As Word , A1 As Word
Dim V1 As String * 5
Dim V2 As String * 5
Dim C1 As String * 5
Dim N As Byte , B2 As Byte , B3 As Byte , B4 As Byte , B5 As Byte
'初始化设置/////////////////////////////////////////////////////////////////////
Ddrd.3 = 0 '按键初始化
Ddrd.4 = 0
Ddrd.5 = 0
Ddrd.6 = 0
Ddrd.7 = 0
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
Portd.6 = 1
Portd.7 = 1
Start Timer1
Start Adc
Cls
Cursor Off
A = 0
C = 1500
W = 0
Ddrc.4 = 1 '初始化风扇控制
Portc.4 = 0
Ddrc.3 = 1 '初始化继电器控制
Portc.3 = 0
Ddrc.2 = 1
Portc.2 = 0
'主程序/////////////////////////////////////////////////////////////////////////
Do
Pwm1a = A
N = 1
V1_dc = 0
A1_dc = 0
V_dc = 0
A_dc = 0
For N = 1 To 30 'ADC采样30次
V1_dc = Getadc(0)
V_dc = V_dc + V1_dc 'ADC的原始值累加
A1_dc = Getadc(1)
A_dc = A_dc + A1_dc
Next
V_dc = V_dc / 30
A_dc = A_dc / 30
V_dc = 2560 * V_dc
V_dc = V_dc / 1023
A_dc = 2560 * A_dc
A_dc = A_dc / 1430
If A >= 451 Then Portc.3 = 1 Else Portc.3 = 0 '继电器控制
If A < 451 Then W = 1400 Else W = 2800
W = W - V_dc
W = W * A_dc
If W > 400000 Then Portc.4 = 1 Else Portc.4 = 0 '风扇控制
Gosub Lp_lcd
Gosub Lp_key
If A_dc >= C Then '截止型电流保护
Waitms 500
If A_dc >= C Then
A1 = A
A = 0
Locate 1 , 12
Lcd "OC "
Gosub Mu
End If
End If
Loop
End
'显示处理///////////////////////////////////////////////////////////////////////
Lp_lcd:
V1 = Str(v_dc)
V1 = Format(v1 , " 0.00") '数字转换为字符串,确定小数点
V2 = Str(a_dc)
V2 = Format(v2 , "0.000")
C1 = Str(c)
C1 = Format(c1 , "0.000")
Locate 1 , 1
Lcd "U=" ; V1 ; "V"
Lowerline
Lcd "I=" ; V2 ; "A <"
Locate 2 , 11
Lcd C1 ; "A"
Return
'按键处理//////////////////////////////////////////////////////////////////////
Lp_key:
If Pind.3 = 0 Then '启动
Waitms 20
If Pind.3 = 0 And A = 0 Then
A = A1
Locate 1 , 12
Lcd "ON "
Waitms 250
End If
End If
If Pind.3 = 0 Then '停止
Waitms 20
If Pind.3 = 0 And A > 1 Then
A1 = A
A = 0
Locate 1 , 12
Lcd "OFF"
End If
End If
If Pind.4 = 1 Then B2 = 0 '电压+
If Pind.4 = 0 Then
Waitms 20
If Pind.4 = 0 Then
If A < 1023 Then
A = A + 1
B2 = B2 + 1
If B2 > 20 And A < 1013 Then
A = A + 10
End If
End If
End If
End If
If Pind.5 = 1 Then B3 = 0 '电压-
If Pind.5 = 0 Then
Waitms 20
If Pind.5 = 0 Then
If A > 1 Then
A = A - 1
B3 = B3 + 1
If B3 > 20 And A > 10 Then
A = A - 10
End If
End If
End If
End If
If Pind.6 = 1 Then B4 = 0 '电流+
If Pind.6 = 0 Then
Waitms 20
If Pind.6 = 0 Then
If C < 1500 Then
C = C + 1
B4 = B4 + 1
If B4 > 20 And C < 1480 Then
C = C + 20
End If
End If
End If
End If
If Pind.7 = 1 Then B5 = 0 '电流-
If Pind.7 = 0 Then
Waitms 20
If Pind.7 = 0 Then
If C > 1 Then
C = C - 1
B5 = B5 + 1
If B5 > 20 And C > 20 Then
C = C - 20
End If
End If
End If
End If
Return
'报警声音///////////////////////////////////////////////////////////////////////
Mu:
Sound Portc.5 , 100 , 1000
Waitms 20
Sound Portc.5 , 100 , 1000
Waitms 20
Sound Portc.5 , 100 , 1000
Return
'///////////////////////////////////////////////////////////////////////////////
一周热门 更多>