PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : DS 1307 - Time$ probleme



Peter P
10.12.2006, 02:02
Hallo, erst mal vielen dank fuer diese site und alle die hier posten. Echt interessant hier.

Mein Problemchen .. vieleicht kann mir ein Guru hier aushelfen :)

Aslo .. Die idee ist eine art kaffeemaschine . Ich will die temperatur messen, fuellstand und nach x minuten eine warnung geben lassen.
Fuellstand, temperatur ist alles am laufen aber mit dem warnen nach x minuten habe ich probleme.

Das Problem: Wenn zum beispiel 1 minute gewahlt wurde .. haelt das
program nur manchmal.. also nicht sehr zuverlaessig.. So habe ich mir gedacht den timer jede secunde die time$ zu checken.. aber das ging auch nicht. Was mache ich falsh hier ?

Habe den Temperature und Fuellstand code entfernt .. damit es nicht so lang ist ..

Weiter unten ist der code ..

Im voraus schon mal besten dank fuer einige tips


'One wire temp sensor Dallas PortB.0
'ADC for Pressure Port ADC 5
'Switch 1 -> PD0
'Switch 2 -> PD1
'Beeper - PD2
' Set Swich is on 2 -> PD0
' ok switch is on 3 -> PD1

$regfile = "m8def.dat"
$crystal = 8000000

$lib "DateTime.Lib"
Config 1wire = Portb.0


Ddrc = &B00000001
Ddrb = &B11111111
Ddrd = &B11111100

'Config Lcd
Config Lcdbus = 4
Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.2 , Db6 = Portb.3 , Db7 = Portb.4 , E = Portb.5 , Rs = Portc.0
Config Lcd = 16 * 2
Cursor Off

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc


'configure the scl and sda pins
Config Sda = Portd.7
Config Scl = Portd.6

'address of ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1


Config Clock = User ' we use I2C for the clock
Config Date = Mdy , Separator = -


Config Timer1 = Timer , Prescale = 256
Enable Timer1
On Timer1 Isr_von_timer1
Enable Interrupts
Timer1 = 34285
Config Debounce = 30

'-----------------------------------------------

Dim C(2) As Byte
Dim W As Word
Dim Bd(9) As Byte
Dim I As Byte , Tmp As Byte
Dim T As Word
Dim Thetemp As Single
Dim Qu As Word
Dim Theend As Bit

Declare Sub Temperature
Declare Sub Quantity
Declare Sub Showtime

Time$ = "00:00:00"

Dim Theminutes As Integer
Dim Minutestr As String * 8

Selectpin Alias Pind.0
Setpin Alias Pind.1

'------ Start from RST needs to set Timer time ---
'30 , 60 ,90,120,150,180,210,240 Minutes
'Set Theminutes to the desired timer countdown

'------------------------------------------------
Start Timer1
Cls
Lcd "SET TIME"
Theend = 0
Do
Debounce Pind.0 , 0 , 30minutes
Loop

30minutes:

Cls
Lcd "30 Min"
Do
Theminutes = 1
Minutestr = "00:01:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 60minutes
Loop

60minutes:
Cls
Lcd "60 Min"
Do
Theminutes = 60
Minutestr = "01:00:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 90minutes
Loop

90minutes:
Cls
Lcd "90 Min"
Do
Theminutes = 90
Minutestr = "01:30:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 120minutes
Loop

120minutes:
Cls
Lcd "120 Min"
Do
Theminutes = 120
Minutestr = "02:00:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 150minutes
Loop

150minutes:
Cls
Lcd "150 Min"
Do
Theminutes = 150
Minutestr = "02:30:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 180minutes
Loop

180minutes:
Cls
Lcd "180 Min"
Do
Theminutes = 180
Minutestr = "03:00:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 210minutes
Loop

210minutes:
Cls
Lcd "210 Min"
Do
Theminutes = 210
Minutestr = "03:30:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 240minutes
Loop

240minutes:
Cls
Lcd "240 Min"
Do
Theminutes = 240
Minutestr = "04:00:00"
Debounce Pind.1 , 0 , Main
Debounce Pind.0 , 0 , 30minutes
Loop



'------------------------------------------------------------
'Now we have the desired time in the TheMinutes variabe
'Proceed to the main loop
'------------------------------------------------------------







Main:
Do
Cls
Temperature
Quantity
Showtime

If Theend = 1 Then
Exit Do
End If

Loop
End



Sub Temperature

End Sub

'----------------------------------

Sub Quantity

End Sub

'-----------------------------------
Sub Showtime
Cls
Lcd Time$
Wait 1

End Sub

' -------- Da hier wird wohl von der lib gebraucht ..
Dim Weekday As Byte
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

Weekdays:
Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"


'--------- TIMER1 ISR -------------------

Isr_von_timer1:
Timer1 = 34285
Toggle Portd.2



If Time$ = Minutestr Then Set Portd.2
Cls
Lcd "END " ; Theminutes
Theend = 1
End If
Return

'--------- END TIMER 1 TSR ---------------