端口代码怎么编写(端口代码怎么编写出来)
C#连接本地sql非1433端口的代码是怎样写的
Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=IP地址,端口号(127.0.0.1 , 1899)
如果要将CC2530的P11配置成输出端口,如何用代码实现,写出关键的两行代码。
可以用以下方法来解决问题:
1.设计一个端口初始化函数,对端口的功能进行配置,LED相关的端口设置为输出,按键相关的端口设置为输入,并且配置成上拉模式。
2.在主函数中不断扫描按键端口的变化,没有按键按下,该端口为高电平,如果有按键按下,则为低电平。当发现按键端口有低电平时,先要进行去抖动处理。
3.因为一个按键有“开灯”和“关灯”两种状态,需要定义一个按键状态的全局变量来处理按键按下的时候,应该是亮LED还是关LED。
CC2530微控制器采用QFN40封装,有40个引脚。其中,有21个数字I/O端口,其中P0和P1是8位端口,P2仅有5位可以使用。这21个端口均可以通过编程进行配置。实际上,在P2端口的5个引脚中,有2个需要用作仿真,有2个需要用作晶振,你在CC2530的开发中真正能够使用的只有17个引脚。
用VB写端口映射代码 越简单越好
Option Explicit
Dim bMsg() As Byte
Private Sub Form_Load()
Dim strCTemp As String
Dim intCPTemp As Variant
'侦听端口
Winsock1.LocalPort = 2000
Winsock1.Listen
'向Sphere转发数据
Winsock2.RemoteHost = "127.0.0.1"
Winsock2.RemotePort = 2001
Winsock2.Connect
Do While Winsock2.State 7
If Winsock2.State = 9 Or Winsock2.State = 0 Then Winsock2.Close: Exit Do
Select Case Winsock2.State
Case 1
strCTemp = "已打开!"
Case 2
strCTemp = "正在侦听.."
Case 3
strCTemp = "与服务器连接挂起!"
Case 4
strCTemp = "正在识别主机.."
Case 5
strCTemp = "已识别主机!"
Case 6
strCTemp = "正在与服务器连接.."
Case 8
strCTemp = "同级人员正在关闭连接.."
Case 9
strCTemp = "出错"
Winsock2.Close
End Select
If Winsock2.State intCPTemp Then
intCPTemp = Winsock2.State vbCrLf
Text1.Text = Text1.Text strCTemp vbCrLf
End If
DoEvents
Loop
If Winsock2.State = 7 Then
Text1.Text = Text1.Text strCTemp "已成功连接上服务器..." vbCrLf
End If
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
ReDim bMsg(bytesTotal)
Winsock1.GetData bMsg
Text1.Text = Text1.Text bytesTotal vbCrLf
Text1.SelStart = Len(Text1.Text)
Winsock2.SendData bMsg
End Sub
Private Sub Winsock2_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Text1.Text = Text1.Text "Winsock2出错!" vbCrLf
End Sub
Private Sub Winsock2_SendComplete()
Text1.Text = Text1.Text "向Sphere发送了数据.." vbCrLf
End Sub
Private Sub Winsock2_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
Text1.Text = Text1.Text "向Sphere发送了" bytesSent "数据.." vbCrLf
End Sub