Hello again, Ok I switched off the adc'd with adcon1 statement.
And that must have done something because now everytime I start the program it locks up at the display temp part.
If I remove the serin code it works (just the program not the recieve signal from the PC)
If I remove the wire from the serin port to the rx on the max 232 adapter it works
This is all when the PC is not even plugged in the the max 232
the wire seems to be shorting out the program or the signal is screwing it up
To me the USART seems to be more work then a simple serin command why would I use it?
here is the pic code
Code:
Include "MODEDEFS.BAS"
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 5
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 7
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATUS 50
ADCON1=%00000111
'
RST var portd.2
DQ var portd.0
CLK var portd.1
temp var word 'storage for temperature
pcsig var word
'
low rst 'reset 1620
'
lcdout $fe,1,"Temp in Degrees C"
' Main loop
mainloop:
RST = 1'enable device might be high
Shiftout DQ,CLK,LSBFIRST,[$ee] 'send read command
RST = 0 ' reset device
Pause 1000 ' wait for conversion to compleate
'
RST = 1 ' SAA
Shiftout DQ,CLK,LSBFIRST, [$aa] ' send read command
Shiftin DQ,CLK,LSBPRE, [temp\9]'read 9 bits temp
RST = 0
'
lcdout $fe,1,dec(temp>>1), ".", dec(temp.0*5), " Degrees C"
pause 1000
serout portd.3,t2400,[#temp]
pause 1000
serin porta.1,t2400,pcsig
if pcsig > 1 then high porta.1
lcdout $fe,1,pcsig,"pcsig"
pause 1000
goto mainloop
END
Here is the VB code
I ommitted a class
Code:
Public Class Form1
Dim WithEvents serialport As New IO.Ports.SerialPort
Dim temperature As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If serialport.IsOpen Then
serialport.Close()
End If
With serialport
.PortName = "com1"
.BaudRate = 2400
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'.DtrEnable = True
'.ReadBufferSize = 40
.ReceivedBytesThreshold = 2
End With
serialport.Open()
End Sub
Private Sub Datarecieved(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialport.DataReceived
TextBox1.Invoke(New mydelegate(AddressOf updatetextbox), New Object() {})
End Sub
Public Delegate Sub mydelegate()
Public Sub updatetextbox()
Dim mytemp As New temp
mytemp.binary = serialport.ReadExisting
Dim resultc As Decimal = celciusconversion(mytemp.binary)
Dim resultf As Decimal = farconversion(resultc)
TextBox1.Text = resultc
TextBox2.Text = resultf
If resultc >= 24 Then
'serialport.Write("a")
serialport.Write(100)
TextBox3.BackColor = Color.Green
TextBox3.Text = "fan on"
Else
TextBox3.BackColor = Color.Red
TextBox3.Text = "fan off"
End If
End Sub
Public Function celciusconversion(ByVal datarecieved As String) As Decimal
Return datarecieved * 0.5
End Function
Public Function farconversion(ByVal datarecieved As String) As Decimal
Return (datarecieved * 1.8) + 32
End Function
Thank you for your time.
I am trying to help out on this forum as much as I can, I have been sending copies of my slot car timer to users who ask for it.
Bookmarks