break;
case SYS_RL2_ON:
case SYS_RL2_OFF:
set_adc_channel(RELAY2_ADC_CN);
sensor_scale = 1;
break;
case SYS_RL3_ON:
case SYS_RL3_OFF:
set_adc_channel(RELAY3_ADC_CN);
sensor_scale = 1;
break;
case SYS_RL4_ON:
case SYS_RL4_OFF:
set_adc_channel(RELAY4_ADC_CN);
sensor_scale = 4;
break;
}
delay_ms(10);
adc_raw_cnt = 0;
// Start timer0 interrupt enable_interrupts(INT_TIMER0);
}
void uart_puts(unsigned char *string) {
while(*string != '\n' && *string != '\0') {
putc(*string++);
} }
Phần mềm giao diện:
'========================================================
=======
'
' CHUONG TRINH CLIENT DIEU KHIEN THIET BI QUA MANG INTERNET '
'===============================================================
Dim CUR_REF As Double Dim AppPath As String Dim rl1_on_cnt As Integer Dim rl2_on_cnt As Integer Dim rl3_on_cnt As Integer Dim rl4_on_cnt As Integer
Dim sAns As String sAns = App.Path
If Right(App.Path, 1) <> "\" Then sAns = sAns & "\"
AppPath = sAns rl1_on_cnt = 0 rl2_on_cnt = 0 rl3_on_cnt = 0 rl4_on_cnt = 0
CUR_REF = CDbl(txtCurTH.Text)
Image1.Picture = LoadPicture(AppPath & "stock-vector.jpg") Image2.Picture = LoadPicture(AppPath & "stock-vector.jpg") Image3.Picture = LoadPicture(AppPath & "stock-vector.jpg") Image4.Picture = LoadPicture(AppPath & "stock-vector.jpg") 'on1.Caption = "Tat"
'on2.Caption = "Tat"
'on3.Caption = "Tat"
'on4.Caption = "Tat"
'Image1.Picture = LoadPicture("Light-Bulb.jpg") 'txtIrms1.Text = "0.01 A" ' Display received current 'Image2.Picture = LoadPicture("Light-Bulb.jpg") 'txtIrms2.Text = "1.2 A" ' Display received current 'Image3.Picture = LoadPicture("stock-vector.jpg") 'txtIrms3.Text = "0.02 A" ' Display received current 'Image4.Picture = LoadPicture("Light-Bulb.jpg") 'txtIrms4.Text = "2 A" ' Display received current End Sub
Private Sub cmdCon_Click()
If sock.State = sckClosed Then ' if the socket is closed sock.RemoteHost = txtIP.Text ' set server adress
sock.RemotePort = txtPort.Text ' set server port sock.Connect ' start connection attempt
cmdCon.Picture = LoadPicture(AppPath & "btn_connect.jpg") Else ' if the socket is open
sock.Close ' close it
cmdCon.Picture = LoadPicture(AppPath & "btn_disconnect.jpg") End If
End Sub
Private Sub on1_Click()
If sock.State = sckConnected Then ' if there is a connection If on1.Caption = "Tat" Then
sock.SendData "0" ' send data to the other side on1.Caption = "Bat"
Else
sock.SendData "1" ' send data to the other side on1.Caption = "Tat"
End If End If End Sub
Private Sub on2_Click()
If sock.State = sckConnected Then ' if there is a connection If on2.Caption = "Tat" Then
sock.SendData "2" ' send data to the other side on2.Caption = "Bat"
Else
sock.SendData "3" ' send data to the other side on2.Caption = "Tat"
End If End If End Sub
Private Sub on3_Click()
If sock.State = sckConnected Then ' if there is a connection If on3.Caption = "Tat" Then
sock.SendData "4" ' send data to the other side on3.Caption = "Bat"
Else
sock.SendData "5" ' send data to the other side on3.Caption = "Tat"
End If End If End Sub
Private Sub on4_Click()
If sock.State = sckConnected Then ' if there is a connection If on4.Caption = "Tat" Then
Else
sock.SendData "7" ' send data to the other side on4.Caption = "Tat"
End If End If End Sub
Private Sub sock_Close()
sock.Close ' has to be called End Sub
Private Sub sock_DataArrival(ByVal bytesTotal As Long) Dim strData As String ' string for received data Dim irms As Double
sock.GetData strData ' load received data into strData Text1.Text = strData
Dim status As Byte
status = CByte(Asc(strData))
'txtReceive.Text = txtReceive.Text & status ' show new string strData = Mid(strData, 9, 6)
If strData <> "" Then
irms = CDbl(Val(strData)) Else
irms = 0 End If
'irms = irms - 0.2
If status = 48 Or status = 49 Then irms = irms * 0.0556875 - 0.325125 irms = Round(irms, 2)
If (irms < 0.09) Then irms = 0
End If
txtIrms1.Text = CStr(irms) ' Mid(strData, 2, 15) ' Display received current
If irms > CUR_REF Then
rl1_on_cnt = rl1_on_cnt + 1 If rl1_on_cnt > 1 Then
Image1.Picture = LoadPicture(AppPath & "Light-
Bulb.jpg")
on1.Caption = "Tat"
End If Else
Image1.Picture = LoadPicture(AppPath & "stock- vector.jpg")
on1.Caption = "Bat"
rl1_on_cnt = 0 End If
End If
If status = 50 Or status = 51 Then irms = irms * 0.0556875 - 0.325125 irms = Round(irms, 2)
If (irms < 0.09) Then irms = 0
End If
txtIrms2.Text = CStr(irms) 'Mid(strData, 2, 15) ' Display received current
If irms > CUR_REF Then
rl2_on_cnt = rl2_on_cnt + 1 If rl2_on_cnt > 1 Then
Image2.Picture = LoadPicture(AppPath & "Light- Bulb.jpg")
on2.Caption = "Tat"
End If Else
Image2.Picture = LoadPicture(AppPath & "stock- vector.jpg")
on2.Caption = "Bat"
rl2_on_cnt = 0 End If
End If
If status = 52 Or status = 53 Then irms = irms * 0.0556875 - 0.325125 irms = Round(irms, 2)
If (irms < 0.09) Then irms = 0
End If
txtIrms3.Text = CStr(irms) ' Mid(strData, 2, 15) ' Display
If irms > CUR_REF Then
rl3_on_cnt = rl3_on_cnt + 1 If rl3_on_cnt > 1 Then
Image3.Picture = LoadPicture(AppPath & "Light- Bulb.jpg")
on3.Caption = "Tat"
End If Else
Image3.Picture = LoadPicture(AppPath & "stock- vector.jpg")
on3.Caption = "Bat"
rl3_on_cnt = 0 End If
End If
If status = 54 Or status = 55 Then irms = irms * 3.2 / 44
irms = Round(irms, 2) irms = irms - 0.03 If (irms < 0.15) Then irms = 0
End If
txtIrms4.Text = CStr(irms) ' Mid(strData, 2, 15) ' Display received current
If irms > CUR_REF Then
rl4_on_cnt = rl4_on_cnt + 1 If rl4_on_cnt > 3 Then
Image4.Picture = LoadPicture(AppPath & "Light- Bulb.jpg")
on4.Caption = "Tat"
End If Else
Image4.Picture = LoadPicture(AppPath & "stock- vector.jpg")
on4.Caption = "Bat"
rl4_on_cnt = 0 End If
End If