VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4635
ClientLeft = 60
ClientTop = 450
ClientWidth = 6525
LinkTopic = "Form1"
ScaleHeight = 4635
ScaleWidth = 6525
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text4
Height = 375
Left = 3720
TabIndex = 8
Text = "Average Measure"
Top = 2760
Width = 1695
End
Begin VB.TextBox Text3
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1032
SubFormatType = 1
EndProperty
Height = 375
Left = 3720
TabIndex = 7
Text = "Volts"
Top = 1680
Width = 1095
End
Begin VB.TextBox Text2
Height = 375
Left = 3720
TabIndex = 3
Text = "Measure"
Top = 600
Width = 1095
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 1
Text = "Text1"
Top = 1200
Width = 975
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 615
Left = 120
TabIndex = 0
Top = 1680
Width = 855
End
Begin MSCommLib.MSComm MSComm1
Left = 480
Top = 240
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = 0 'False
End
Begin VB.Label Label6
Caption = "Label6"
Height = 375
Left = 1320
TabIndex = 6
Top = 1680
Width = 615
End
Begin VB.Label Label2
Caption = " ADRESLtemp"
Height = 375
Left = 1320
TabIndex = 4
Top = 2160
Width = 1215
End
Begin VB.Label Label1
Caption = "ADRESH"
Height = 375
Left = 1320
TabIndex = 2
Top = 360
Width = 855
End
Begin VB.Label Label5
Caption = "ADRESL"
Height = 375
Left = 1320
TabIndex = 5
Top = 960
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim a(0) As Byte
' a(0) = Text1.Text
MSComm1.Output = a
End Sub
Private Sub Form_Load() ' Initalisation of application upon loading
MSComm1.RThreshold = 2 ' Fire comEvReceive Event Every Two Bytes
MSComm1.InputLen = 2 ' When Inputting Data, Input 2 Bytes at a time
MSComm1.Settings = "38400,N,8,1" ' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.DTREnable = False ' Disable DTR
MSComm1.CommPort = 1 ' Use COM1
MSComm1.PortOpen = True ' Open the port for communication
Average = 0
i = 0
End Sub
Private Sub MSComm1_OnComm() ' Routine that serves the event which generated whenever the
' value of the CommEvent property changes, indicating that
' either a communication event or an error occurred.
Dim BUFFER As String
Dim Measure As Integer
Dim ADRESLtemp As Integer
Dim Volts As Single
Dim ADRESH As Byte
Dim ADRESL As Byte
If MSComm1.CommEvent = comEvReceive Then ' Routine that executes upon the event of receiving
' two bytes in USARTs Input Buffer
BUFFER = MSComm1.Input ' Get data from USARTs Input Buffer
Dim sChar As String
Dim x As Long
Dim Shift As Byte
sChar = Mid$(BUFFER, 1, 1) 'Gets the ADRESH character
ADRESH = Asc(sChar) 'Gets ASCII value of character
Label1.Caption = ADRESH
sChar = Mid$(BUFFER, 2, 1) 'Gets the ADRESL charcter in sText
ADRESLtemp = Asc(sChar) 'Gets ASCII value of character
Label2.Caption = ADRESLtemp
ShrW ADRESLtemp, 6 ' Shift ADRESL six times right in order to put it in the
ADRESL = ADRESLtemp ' right format 0000 00LL (L: LSBs of the AD conversion)
Label5.Caption = ADRESL
Measure = 0 ' Measure length is 16 bits
Measure = ADRESH ' Put ADRESH in Measure
ShlW Measure, 2 ' Shift ADRESH in Measure two times left in order hence
Label6.Caption = Measure ' 000000MM MMMMMM00 (M: ADRESH bits)
Measure = Measure Or ADRESL
Text2.Text = Measure
Volts = (Measure * 5) / 1023 ' Evaluate the Voltage from the 10bits AD conversion
Text3.Text = Volts
i = i + 1
Average = Average + Volts
If i = 20 Then
Text4.Text = (Average / 20)
Average = 0
i = 0
End If
End If
End Sub
| file: /images/boards/picmeter/VBasic_code/rs232TRRS.frm, 5KB, , updated: 2005/11/23 18:59, local time: 2012/2/10 16:07,
38.107.179.232:LOG IN |
| ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.piclist.com/images/boards/picmeter/VBasic_code/rs232TRRS.frm"> </A> |
| Did you find what you needed? |
|
Robotics nuts!Check out http://users.frii.com/dlc/robotics/projects/botproj.htm from Dennis Clark. This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.