Snecx
19.11.2007, 02:10
Hallo
ich habe ein Verständnisproblem bei meinem Program. Es soll über die Rs232 ein Steuerbefehl empfangen und dann die Uhr stellen oder wieder zurückgeben. Dazu sende ich zum stellen der Uhr z.B. den Befehl "WB1S12101911071"
Das klappt ohne Probleme. Möchte ich die Uhrzeit wieder auslesen sende ich "WB1G" und hierbei ist das Problem. Egal was ich mache der Code in der Select Case wird nicht ausgeführt.
Kann mir bitte jemand sagen warum??? Wenn ich das gleich Programm in .NET progge geht das. Ich bitte um Tips.
Danke.
$regfile = "m8535.dat"
''$regfile = "m16def.dat"
$crystal = 8000000 ' used crystal frequency
$baud = 9600 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 6 , Mode = 6
'Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portc , Ce = 4 , Ce2 = 3 , Cd = 0 , Rd = 1 , Reset = 5 , Enable = 2
'Clear the screen will both clear text and graph display
Cls
Config 1wire = Portd.3 '' 1 Wire Port
Config Pinc.7 = Output '' LCD Invert
Config Pind.4 = Output
Config Scl = Portd.5
Config Sda = Portd.6
'config UART Interrupt
On Urxc Onrxd 'Interrupt-Routine setzen
Enable Urxc 'Interrupt URXC einschalten
Enable Interrupts 'Interrupts global zulassen '' LCD Backlight
Portc.7 = 0 '' LCD Invert ON
Portd.4 = 1 '' LCD Backlight ON
Dim Zaehler As Integer
Zaehler = 0
Dim I As Byte
Dim Settimedate As Byte
Dim Rs232 As Byte
I = 1
Dim Mystring As String * 11
Dim Mybytes(12) As Byte At Mystring Overlay
Dim Ds1307w As Byte
Dim Ds1307r As Byte
Ds1307w = &B11010000
Ds1307r = &B11010001
Dim _day As Byte
Dim _month As Byte
Dim _year As Byte
Dim _sec As Byte
Dim _min As Byte
Dim _hour As Byte
Dim _weekday As Byte
Dim Modus As Byte
Dim Test As Byte
Config Portb = Output
Portb = &B11111111
Do
Select Case Modus
Case 1 '' Set Date and Time
Print "Hour:"
Print _hour
Print "Minute:"
Print _min
Print "Sec:"
Print _sec
Print "Day:"
Print _day
Print "Month:"
Print _month
Print "Year:"
Print _year
Print "Weekday:"
Print _weekday
If Test = 1 Then
_sec = Makebcd(_sec)
_min = Makebcd(_min)
_hour = Makebcd(_hour)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cstop
_day = Makebcd(_day)
_month = Makebcd(_month)
_year = Makebcd(_year)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 3
I2cwbyte _weekday
I2cwbyte _day
I2cwbyte _month
I2cwbyte _year
I2cstop
End If
Modus = 0
Case 2 '' Get Date and Time
If Test = 1 Then
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstop
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte _weekday , Ack
I2crbyte _day , Ack
I2crbyte _month , Ack
I2crbyte _year , Nack
I2cstop
End If
Print "20332011076"
_day = Makedec(_day)
_month = Makedec(_month)
_year = Makedec(_year)
_sec = Makedec(_sec)
_min = Makedec(_min)
_hour = Makedec(_hour)
Print "Hour:"
Print _hour
Print "Minute:"
Print _min
Print "Sec:"
Print _sec
Print "Day:"
Print _day
Print "Month:"
Print _month
Print "Year:"
Print _year
Print "Weekday:"
Print _weekday
Modus = 0
End Select
Portb = &B00000000
Wait 1
Portb = &B11111111
Wait 1
Loop
End
'UART interrupt routine
Onrxd:
Dim Temp As String * 11
Dim T As Byte
If I = 1 Then
If Chr(udr) = "W"then
I = 2
Else
I = 1
End If
Elseif I = 2 Then
If Chr(udr) = "B" Then
I = 3
Else
I = 1
End If
Elseif I = 3 Then
If Chr(udr) = "1" Then
I = 4
Else
I = 1
End If
Elseif I = 4 Then
Select Case Chr(udr)
Case "S"
I = 5
Case "G"
Modus = 2
Case Else
I = 1
End Select
Elseif I = 5 Then
Incr Rs232
Mybytes(rs232) = Udr
If Rs232 = 11 Then
Rs232 = 0
I = 1
Temp = Mid(mystring , 1 , 2)
T = Val(temp)
_hour = T
Temp = Mid(mystring , 3 , 2)
T = Val(temp)
_min = T
_sec = 00
Temp = Mid(mystring , 5 , 2)
T = Val(temp)
_day = T
Temp = Mid(mystring , 7 , 2)
T = Val(temp)
_month = T
Temp = Mid(mystring , 9 , 2)
T = Val(temp)
_year = T
Temp = Mid(mystring , 11 , 1)
T = Val(temp)
_weekday = T
Modus = 1
End If
End If
Return
ich habe ein Verständnisproblem bei meinem Program. Es soll über die Rs232 ein Steuerbefehl empfangen und dann die Uhr stellen oder wieder zurückgeben. Dazu sende ich zum stellen der Uhr z.B. den Befehl "WB1S12101911071"
Das klappt ohne Probleme. Möchte ich die Uhrzeit wieder auslesen sende ich "WB1G" und hierbei ist das Problem. Egal was ich mache der Code in der Select Case wird nicht ausgeführt.
Kann mir bitte jemand sagen warum??? Wenn ich das gleich Programm in .NET progge geht das. Ich bitte um Tips.
Danke.
$regfile = "m8535.dat"
''$regfile = "m16def.dat"
$crystal = 8000000 ' used crystal frequency
$baud = 9600 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 6 , Mode = 6
'Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portc , Ce = 4 , Ce2 = 3 , Cd = 0 , Rd = 1 , Reset = 5 , Enable = 2
'Clear the screen will both clear text and graph display
Cls
Config 1wire = Portd.3 '' 1 Wire Port
Config Pinc.7 = Output '' LCD Invert
Config Pind.4 = Output
Config Scl = Portd.5
Config Sda = Portd.6
'config UART Interrupt
On Urxc Onrxd 'Interrupt-Routine setzen
Enable Urxc 'Interrupt URXC einschalten
Enable Interrupts 'Interrupts global zulassen '' LCD Backlight
Portc.7 = 0 '' LCD Invert ON
Portd.4 = 1 '' LCD Backlight ON
Dim Zaehler As Integer
Zaehler = 0
Dim I As Byte
Dim Settimedate As Byte
Dim Rs232 As Byte
I = 1
Dim Mystring As String * 11
Dim Mybytes(12) As Byte At Mystring Overlay
Dim Ds1307w As Byte
Dim Ds1307r As Byte
Ds1307w = &B11010000
Ds1307r = &B11010001
Dim _day As Byte
Dim _month As Byte
Dim _year As Byte
Dim _sec As Byte
Dim _min As Byte
Dim _hour As Byte
Dim _weekday As Byte
Dim Modus As Byte
Dim Test As Byte
Config Portb = Output
Portb = &B11111111
Do
Select Case Modus
Case 1 '' Set Date and Time
Print "Hour:"
Print _hour
Print "Minute:"
Print _min
Print "Sec:"
Print _sec
Print "Day:"
Print _day
Print "Month:"
Print _month
Print "Year:"
Print _year
Print "Weekday:"
Print _weekday
If Test = 1 Then
_sec = Makebcd(_sec)
_min = Makebcd(_min)
_hour = Makebcd(_hour)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cstop
_day = Makebcd(_day)
_month = Makebcd(_month)
_year = Makebcd(_year)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 3
I2cwbyte _weekday
I2cwbyte _day
I2cwbyte _month
I2cwbyte _year
I2cstop
End If
Modus = 0
Case 2 '' Get Date and Time
If Test = 1 Then
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstop
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte _weekday , Ack
I2crbyte _day , Ack
I2crbyte _month , Ack
I2crbyte _year , Nack
I2cstop
End If
Print "20332011076"
_day = Makedec(_day)
_month = Makedec(_month)
_year = Makedec(_year)
_sec = Makedec(_sec)
_min = Makedec(_min)
_hour = Makedec(_hour)
Print "Hour:"
Print _hour
Print "Minute:"
Print _min
Print "Sec:"
Print _sec
Print "Day:"
Print _day
Print "Month:"
Print _month
Print "Year:"
Print _year
Print "Weekday:"
Print _weekday
Modus = 0
End Select
Portb = &B00000000
Wait 1
Portb = &B11111111
Wait 1
Loop
End
'UART interrupt routine
Onrxd:
Dim Temp As String * 11
Dim T As Byte
If I = 1 Then
If Chr(udr) = "W"then
I = 2
Else
I = 1
End If
Elseif I = 2 Then
If Chr(udr) = "B" Then
I = 3
Else
I = 1
End If
Elseif I = 3 Then
If Chr(udr) = "1" Then
I = 4
Else
I = 1
End If
Elseif I = 4 Then
Select Case Chr(udr)
Case "S"
I = 5
Case "G"
Modus = 2
Case Else
I = 1
End Select
Elseif I = 5 Then
Incr Rs232
Mybytes(rs232) = Udr
If Rs232 = 11 Then
Rs232 = 0
I = 1
Temp = Mid(mystring , 1 , 2)
T = Val(temp)
_hour = T
Temp = Mid(mystring , 3 , 2)
T = Val(temp)
_min = T
_sec = 00
Temp = Mid(mystring , 5 , 2)
T = Val(temp)
_day = T
Temp = Mid(mystring , 7 , 2)
T = Val(temp)
_month = T
Temp = Mid(mystring , 9 , 2)
T = Val(temp)
_year = T
Temp = Mid(mystring , 11 , 1)
T = Val(temp)
_weekday = T
Modus = 1
End If
End If
Return