PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : String funktoiniert nicht



Rene046
06.12.2006, 00:30
Hallo ich habbe folgendes stuck an code:



Dim Temp1 As String * 10
Dim Temp2 As String * 10
.
.
.
$eepromhex
$eeprom

Lights1on:
Data 21 , 09
Lights1off:
Data 21 , 10
Lights1_on:
Data 21 , 12
Lights1_off:
Data 21 , 14
$data
.
.
.
.
if X1 = 2 Then
Temp1 = "Lights1on "
Temp2 = "Lights1off"
Gosub T1
Elseif X1 = 1 Then
Enterdatetime

End If
End Sub

T1:
Cls
Locate 1 , 1
Lcd "SW1 aan progr 1"

Aa = 0
Gosub Lamp
Writeeeprom H1 , Temp1
Writeeeprom M1

Cls
Locate 1 , 1
Lcd "SW1 uit progr 1"

Aa = 0
Gosub Lamp
Writeeeprom H1 , Temp2
Writeeeprom M1
Return

Jezt siets so aus dass der Temp1 und temp2 nicht aceptiert werden.

muss man dass anders machen ?
wehn ich da normal Lights1on oder Lights1off hinter die writeeprom stelle
anstad dem temp1 oder 2 funktionierts richtig.

aber ich mochte genre ein variabel da nutzen um code su sparen.

bin mir ein aquarium timer ans machen
https://www.roboternetz.de/phpBB2/viewtopic.php?t=10441

BlueNature
06.12.2006, 02:11
Servus,

An deiner Stelle würde ich erst mal die EEPROM udn DATA ans Ende stellen, das ist so üblich. Die Programmausführung überläuft sonst den Datenbereich was nicht sonderlich gut ist und früher oder später einen sicheren Reset mit sich bringt. Den Rest deines Problems sowie den Sinn des Source habe ich aber bei bestem Willen nicht verstehen können. Kommt mir aber etwas chaotisch programmiert vor. Stell einfach nochmal geordnet und eindeutig deine Frage.

Grüße Wolfgang

Anbei noch der etwar korrgierte und übrholte Source:

Noch etwas wegen deinen permanenten WriteEeprom-Schreibweisen. Kannst das als ERAM definieren wie eine SRAM-Vriable auch, dann kannst darauf zugreifen wie auf eine normale SRAM-Variable, nur etwas langsamer. aber das ist bei deinem code sowas von unmerklich das es da eh nicht stört mit dem Zeitverlust.




$RegFile = "m8def.dat"
$Crystal = 8000000
$Baud = 9600
$Lib "ds1307rtc.lib" ' modified lib

Declare Sub GetTemp()
Declare Sub EnterDateTime()
Declare Sub GetKey()
Declare Sub GetKey2()
Declare Sub Menu()
'Declare Sub CheckLight()

' Port-Deklarationen
Lamp1 Alias PortD.6
Lamp2 Alias PortD.5
Lamp3 Alias PortB.7
Lamp4 Alias PortB.6
KeyEnter Alias PinC.1
KeyDown Alias PinC.2
KeyUp Alias PinC.3

'Dim Weekday As Byte
'Dim Ds1307w As Byte
'Dim Ds1307r As Byte
Dim ScrachPad(8) As Byte
Dim Tmp As Integer
Dim Wynik As Single
Dim Temp As String * 10
Dim Temp1 As String * 10
Dim Temp2 As String * 10
Dim LightsOnMin As Word ' light on time converted to minutes
Dim LightsOffMin As Word ' light off time converted to minutes
Dim CurrentMin As Word
Dim EventHrs As Byte ' event hrs
Dim EventMin As Byte ' event minutes
Dim OldMin As Byte
'Dim Gp1 As Byte ' general purpose variable
'Dim Gp2 As Byte ' general purpose variable
'Dim Gp3 As Byte ' general purpose variable
'Dim Gp4 As Byte ' general purpose variable
Dim J1 As Byte ' used by date and time subs
Dim M1 As Byte
Dim D1 As Byte
Dim H1 As Byte ' used by date and time subs
Dim Min1 As Byte
Dim Aa As Byte ' sw var
Dim X1 As Byte ' klok var
Dim Z1 As Byte
Dim Z2 As Byte

' Constants for DS18b20
Const Skip_Rom = &hCC
Const Convert = &h44
Const Read_Sp = &hBE
Const Write_Sp = &h4E
' address of ds1307
Const DS1307W = &hD0 ' Addresses of Ds1307 clock
Const DS1307R = &hD1


' Interrupt-Vektoren
'On Timer1 GetTemp 'verzweige bei Timer1 überlauf zu Isr_von_Timer1

Init:
' Config LCD
Config LcdPin = Pin, Db4 = PortB.5, Db5 = PortB.4, Db6 = PortB.3, Db7 = PortB.2, _
E = PortB.1, Rs = PortD.7
Config Lcd = 20 * 4
Cursor Off

' Config I2C
Config SDA = PortC.4
Config SCL = PortC.5

' Config 1-Wire
Config 1Wire = PortB.0
Config Clock = User
Config Date = Dmy, Separator = -

Config PortB.6 = Output ' lamp4
Config PortB.7 = Output ' lamp3
Config PortD.6 = Output ' lamp1
Config PortD.5 = Output ' lamp2
Config PinC.1 = Input ' enter button & enter the menu
Config PinC.2 = Input ' down button
Config PinC.3 = Input ' up button
' Config Timer1
'Config Timer1 = Timer, Prescale = 256
'Enable Timer1
'Enable Interrupts
'Timer1 = 34285
' Pull-Up's der Eingänge aktivieren (Taster Low-Aktiv)
PortC.3 = 1
PortC.2 = 1
PortC.1 = 1
' Alle Lampen abschalten
Lamp1 = 0
Lamp2 = 0
Lamp3 = 0
Lamp4 = 0
' to watch the day changing value
Time$ = "21:08:40"
Date$ = "03-12-06"
WaitMs 100
Cls

Start:
Do
Locate 1 , 1
Lcd "Datum: "; Date$; " "
Locate 2 , 1
Lcd "Tijd: "; Time$; " "
If _min <> OldMin Then
GetTemp
Locate 3 , 1
Lcd "Temp: " ; Temp
End If
If _sec = 5 Then
GoSub CheckLights
End If
If KeyEnter = 0 Then
Menu
End If
'Wait 1
Loop
End

'called from ds1307clock.lib
GetDateTime:
I2Cstart ' Generate start code
I2CwByte Ds1307w ' send address
I2CwByte 0 ' start address in 1307

I2Cstart ' Generate start code
I2CWByte Ds1307r ' send address
I2CRByte _sec, ACK
I2CRByte _min, ACK ' Minutes
I2CRByte _hour, ACK ' Hours
'I2CRByte WeekDay, ACK ' Day of Week
I2CRByte _day , ACK ' Day of Month
I2CRByte _month , ACK ' Month of Year
I2CRByte _year , NACK ' Year
I2CStop

_sec = MakeDec(_sec)
_min = MakeDec(_min)
_hour = MakeDec(_hour)
_day = MakeDec(_day)
_month = MakeDec(_month)
_year = MakeDec(_year)
Return

SetDate:
_day = MakeBcd(_day)
_month = MakeBcd(_month)
_year = MakeBcd(_year)
I2CStart ' Generate start code
I2CWByte Ds1307w ' send address
I2CWByte 4 ' starting address in 1307
I2CWByte _day ' Send Data to SECONDS
I2CWByte _month ' MINUTES
I2CWByte _year ' Hours
I2CStop
Return

SetTime:
_sec = MakeBcd(_sec)
_min = MakeBcd(_min)
_hour = MakeBcd(_hour)
I2CStart ' Generate start code
I2CWByte Ds1307w ' send address
I2CWByte 0 ' starting address in 1307
I2CWByte _sec ' Send Data to SECONDS
I2CWByte _min ' MINUTES
I2CWByte _hour ' Hours
I2CStop
Return

' SUBS ************************************************** *****************

Sub EnterDateTime()
Cls
X1 = 05
Aa = 0
Do
If X1 > 99 Then X1 = 00
If X1 < 1 Then X1 = 99
WaitMs 300
Locate 1, 1
Lcd "Geef Het Jaar: "; X1; " "
GetKey
J1 = X1
Loop Until Aa = 1

Cls
Aa = 0
X1 = 06
Do
If X1 > 12 Then X1 = 01
If X1 < 1 Then X1 = 12
WaitMs 300
Locate 1, 1
Lcd "Geef de maand: "; X1; " "
GetKey
M1 = X1
Loop Until Aa = 1

Cls
Aa = 0
X1 = 15
Do
If X1 > 31 Then X1 = 01
If X1 < 1 Then X1 = 31
WaitMs 300
Locate 1, 1
Lcd "Geef de dag: "; X1; " "
GetKey
D1 = X1
Loop Until Aa = 1

_year = J1
_month = M1
_day = D1

GoSub SetDate

Cls
Aa = 0
X1 = 12
Do
If X1 > 24 Then X1 = 01
If X1 < 1 Then X1 = 24
WaitMs 300
Locate 1, 1
Lcd "Geef het uur: "; X1; " "
GetKey
H1 = X1
Loop Until Aa = 1

Cls
Aa = 0
X1 = 30
Do
If X1 > 59 Then X1 = 00
If X1 < 01 Then X1 = 59
Locate 1, 1
Lcd "Geef minuten: "; X1; " "
GetKey
Min1 = X1
Loop Until Aa = 1

_hour = H1
_min = Min1
_sec = 0

GoSub SetTime

End Sub

Sub GetKey()
WaitMs 300
If KeyUp = 0 Then Incr X1
If KeyDown = 0 Then Decr X1
If KeyEnter = 0 Then
Aa = 1
Else
Aa = 0
End If
End Sub

Sub GetKey2()
WaitMs 300
If KeyUp = 0 Then Incr Z1
If KeyDown = 0 Then Decr Z1
If KeyEnter = 0 Then
Aa = 1
Else
Aa = 0
End If
End Sub

Sub Menu()
Aa = 0
X1 = 0
Cls
Locate 1, 1: Lcd " Menu "
Locate 2, 1: Lcd "up/down voor keuze"
Do
Call GetKey()
Locate 4 , 1
Select Case X1
Case 1: Lcd "klok instellen "
Case 2: Lcd "SW1 programeren"
Case 3: Lcd "SW1-2 programeren"
Case 4: Lcd "SW2 programeren"
Case 5: Lcd "SW2-2 programeren"
Case 6: Lcd "SW3 programeren"
Case 7: Lcd "SW3-2 programeren"
Case 8: Lcd "SW4 programeren"
Case 9: Lcd "SW4-2 programeren"
Case 10: Lcd "menu verlaten "
Case Is > 10:
X1 = 1
Case Is < 1:
X1 = 10
End Select
Loop Until Aa = 1
Select Case X1
Case 10:
Cls
Exit Sub
Case 9:
GoSub T4s
Case 8:
GoSub T4
Case 7:
GoSub T3s
Case 6:
GoSub T3
Case 5:
GoSub T2s
Case 4:
GoSub T2
Case 3:
GoSub T1s
Case 2:
'Temp1 = "Lights1on "
'Temp2 = "Lights1off"
GoSub T1
Case 1:
EnterDateTime
End Select
End Sub

T1:
Cls
Locate 1, 1
Lcd "SW1 aan progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights1On
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW1 uit progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights1Off
WriteEeprom M1
Return

T1s:
Cls
Locate 1 , 1
Lcd "SW1 aan progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights1_On
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW1 uit progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights1_Off
WriteEeprom M1
Return

T2:
Cls
Locate 1, 1
Lcd "SW2 aan progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights2On
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW2 uit progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights2Off
WriteEeprom M1
Return

T2s:
Cls
Locate 1, 1
Lcd "SW2 aan progr 2"

Aa = 0
Gosub Lamp
WriteEeprom H1, Lights2_On
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW2 uit progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights2_off
WriteEeprom M1
Return

T3:
Cls
Locate 1, 1
Lcd "SW3 aan progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights3on
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW3 uit progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights3off
WriteEeprom M1
Return

T3s:
Cls
Locate 1 , 1
Lcd "SW3 aan progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights3_on
WriteEeprom M1

Cls
Locate 1 , 1
Lcd "SW3 uit progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights3_off
WriteEeprom M1
Return

T4:
Cls
Locate 1, 1
Lcd "SW4 aan progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights4on
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW4 uit progr 1"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights4off
WriteEeprom M1
Return

T4s:
Cls
Locate 1 , 1
Lcd "SW4 aan progr 2"

Aa = 0
Gosub Lamp
WriteEeprom H1, Lights4_on
WriteEeprom M1

Cls
Locate 1, 1
Lcd "SW4 uit progr 2"

Aa = 0
GoSub Lamp
WriteEeprom H1, Lights4_off
WriteEeprom M1
Return

Lamp:
Do
If Z1 > 24 Then Z1 = 01
If Z1 < 1 Then Z1 = 24
WaitMs 300
Locate 2 , 1
Lcd "Geef het uur: " ; Z1 ; " "
GetKey2
H1 = Z1
Loop Until Aa = 1
Do
If Z1 > 59 Then Z1 = 00
If Z1 < 01 Then Z1 = 59
WaitMs 300
Locate 2 , 1
Lcd "Geef de minuten: "; Z1 ;" "
GetKey2
M1 = Z1
Loop Until Aa = 1
Return

CheckLights:
ReadEeprom EventHrs, Lights1On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp1 = 1
Locate 4, 1
Lcd "sw1+" 'turn on light 1
End If
End If

ReadEeprom EventHrs, Lights1Off
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp1 = 0
Locate 4, 1
Lcd "sw1-" 'turn off light 1
End If
End If

Readeeprom Eventhrs, Lights1_on
Readeeprom Eventmin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp1 = 1
Locate 4, 1
Lcd "sw1s+" 'turn on light 1 second
End If
End If

ReadEeprom Eventhrs, Lights1_off
ReadEeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Lamp1 = 0
Locate 4, 1
Lcd "sw1s-" 'turn off light 1 second
End If
End If

ReadEeprom EventHrs, Lights2On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp2 = 1
Locate 4, 7
Lcd "sw2+" 'turn on light 2
End If
End If

ReadEeprom Eventhrs, Lights2off
ReadEeprom Eventmin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp2 = 0
Locate 4, 7
Lcd "sw2-" 'turn off light 2
End If
End If

ReadEeprom Eventhrs, Lights2_on
ReadEeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Lamp2 = 1
Locate 4, 7
Lcd "sw2s+" 'turn on light 2 second
End If
End If

ReadEeprom Eventhrs , Lights2_off
ReadEeprom Eventmin
If Eventhrs = _hour Then
If Eventmin = _min Then
Lamp2 = 0
Locate 4, 7
Lcd "sw2s-" 'turn off light 2 second
End If
End If

ReadEeprom EventHrs, Lights3On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp3 = 1
Locate 4, 13
Lcd "sw3+" 'turn on light 3
End If
End If

ReadEeprom Eventhrs, Lights3off
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp3 = 0
Locate 4, 13
Lcd "sw3-" 'turn off light 3
End If
End If

ReadEeprom EventHrs, Lights3_On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp3 = 1
Locate 4, 13
Lcd "sw3s+" 'turn on light 3 second
End If
End If

ReadEeprom EventHrs, Lights3_Off
ReadEeprom EventMin
If Eventhrs = _hour Then
If Eventmin = _min Then
Lamp3 = 0
Locate 4, 13
Lcd "sw3s-" 'turn off light 3 second
End If
End If

ReadEeprom EventHrs, Lights4On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp4 = 1
Locate 3, 13
Lcd "sw4+" 'turn on light 4
End If
End If

ReadEeprom EventHrs, Lights4Off
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp4 = 0
Locate 3, 13
Lcd "sw4-" 'turn off light 4
End If
End If

ReadEeprom EventHrs, Lights4_On
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp4 = 1
Locate 3, 13
Lcd "sw4s+" 'turn on light 4 second
End If
End If

ReadEeprom EventHrs, Lights4_Off
ReadEeprom EventMin
If EventHrs = _hour Then
If EventMin = _min Then
Lamp4 = 0
Locate 3, 13
Lcd "sw4s-" 'turn off light 4 second
End If
End If

Return


Sub GetTemp()
1wReset
1wWrite Skip_rom
1wWrite Write_sp
1wWrite 0
1wWrite 0
1wWrite &H7F

1wReset
1wWrite Skip_rom
1wWrite Convert
WaitMs 800

1wReset
1wWrite Skip_Rom
1wWrite Read_Sp

ScrachPad(1) = 1wRead()
ScrachPad(2) = 1wRead()
Tmp = ScrachPad(2) * 256
Tmp = Tmp + ScrachPad(1)
Wynik = Tmp
Wynik = Wynik / 16
Temp = Fusing(Wynik, "#.##")
OldMin = _min
End Sub





' assigning the time will call the SetTime routine

$EepromHex 'tell compiler to write in Intel hex format
$Eeprom

Lights1On: Data 21, 9
Lights1Off: Data 21, 10
Lights1_On: Data 21, 12
Lights1_Off: Data 21, 14
Lights2On: Data 21, 10
Lights2Off: Data 21, 15
Lights2_On: Data 21, 16
Lights2_Off: Data 21, 17
Lights3On: Data 21, 10
Lights3Off: Data 21, 15
Lights3_On: Data 21, 16
Lights3_Off: Data 21, 17
Lights4On: Data 21, 09
Lights4Off: Data 21, 10
Lights4_On: Data 0 , 0
Lights4_Off: Data 0 , 0

$Data

Rene046
06.12.2006, 19:11
Hallo habe dass mal im Bascom laufen lassen was sie geschrieben haben aber dan finded dass program alle daten nicht mehr.


Also mussen die oben drin stehen.
und im format :

Lights1on: Data 21 , 9
Lights1off: Data 21 , 10

nimt bascom aug nicht.

mfg Rene leider dass wahr shon etwas nutter gewesen wehn dass hier funktioniete.

mfg Rene

BlueNature
07.12.2006, 04:37
Servus,

Schau nach der Variante

"...Kannst das als ERAM definieren wie eine SRAM-Vriable auch, dann kannst darauf zugreifen wie auf eine normale SRAM-Variable..."
und lass das mit dem EEprom einfach weg

Grüße Wolfgang