Ja die Aller besten programierer sind immer die mit der großen klappe die können es ja, aber wehe es geht um einen der das noch nicht soch recht
drauf hat wird immer wieder gesagt oh mach doch wie willst.....
Nur zu infomation
ich habe nu ein 4x20LCD in 4Bit und den DS1307 An I2C Hängen und es läuft soweit ganz gut nur das die temparatur ab und zu bis zu
1200 springt und dann wieder die nomal Temparatur
hier der code noch mal wie er jetzt ist
CodeBox BascomAVR
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
'tasten
Portc.0 = 1
Portc.1 = 1
Portc.2 = 1
Portc.3 = 1
S1 Alias Pinc.0
S2 Alias Pinc.1
S3 Alias Pinc.2
S4 Alias Pinc.3
'LCD
Config Lcdpin = Pin , Db4 = Portd.2 , Db5 = Portd.3 , Db6 = Portd.4 , Db7 = Portd.5 , _
E = Portd.6 , Rs = Portd.7
Config Lcd = 20 * 4 , Chipset = St7032 'Type 20 x 4 Blau LCD ST7032 ', Chipset = St7032 'Ks077 'Einstellen des LCD 16x2 oder 20x4
Config Lcdbus = 4
Cls 'LCD Leeren
Cursor Off
'Adresse DS1307
'Adresse DS1307
Const Ds1307w = &HD0
Const Ds1307r = &HD1
I2cinit
'Config I2cdelay = 15 'delay von 15=20µs=50kHz,10=10µs=100kHz;5=5µs=200KHz
Config Scl = Portc.5 'I2C SCL Pin
Config Sda = Portc.4 'I2C SDA Pin
Deflcdchar 0 , 7 , 5 , 7 , 32 , 32 , 32 , 32 , 32 ' Punkt Oben Rechts
Config 1wire = Portb.0 'Pin fuer 1Wire festlegen
Config Timer1 = Timer , Prescale = 256 'Timer für Sekundentakt zum
On Timer1 Sectic 'abfragen der RTC
Const Ladetimer1 = 22336
Enable Timer1
Config Date = Dmy , Separator = . 'Trennzeichen Datumsformat einstellen
Config Clock = User
Dim Weekday As Byte
Dim L_sec As Byte , Print_lcd As Byte , Setmode As Byte
Dim Wert_aus_ds1820 As Integer 'Register 2 Byte lang auslesen
Dim Ganze_grad As Word , Halbegrad As Byte
Dim Temperatur As Single
Dim I As Byte
Cls
Locate 1 , 1
Lcd "UHR - TEMPARATUR"
Locate 2 , 1
Lcd "DS1307 & DS18S20"
Wait 2
Cls
Enable Interrupts
Do
Debounce S1 , 0 , Goto_setmode , Sub
If Setmode = 1 Then
Debounce S2 , 0 , Sethour , Sub
Debounce S3 , 0 , Setmin , Sub
Debounce S4 , 0 , Setsecond , Sub
End If
If Setmode = 2 Then
Debounce S2 , 0 , Setday , Sub
Debounce S3 , 0 , Setmonth , Sub
Debounce S4 , 0 , Setyear , Sub
End If
If Print_lcd > 0 And Setmode = 0 Then
Locate 1 , 1
Lcd Time$ ; " Uhr"
Locate 2 , 1
Lcd Date$ ; " Datum"
Print_lcd = 0
If Halbegrad = 1 Then Temperatur = Temperatur + 0.5
Locate 4 , 6
Lcd Temperatur ; " C" ; Chr(0)
Wait 1
End If
If Setmode = 2 Then
Upperline
Lcd Time$ ; " SET"
Lowerline
Lcd Date$ ; " >DATE<"
End If
If Setmode = 1 Then
Upperline
Lcd Time$ ; " SET"
Lowerline
Lcd Date$ ; " >TIME<"
End If
1wreset
1wwrite &HCC 'Bausteinauswahl ignorieren
1wwrite &H44 'Messvorgang anstossen
Waitus 80
1wreset
1wwrite &HCC 'Bausteinauswahl ignorieren
1wwrite &HBE 'Read Scratchpad
Wert_aus_ds1820 = 1wread(2) '2 Bytes lesen: MSB, LSB
1wreset
Halbegrad = Wert_aus_ds1820.0 'wenn 1: spaeter 0,5 addieren
Shift Wert_aus_ds1820 , Right 'Bit 0 rausschieben
If Wert_aus_ds1820.7 = 0 Then
' -- >= Null Grad
Temperatur = Wert_aus_ds1820
Else
' -- Minus-Temperatur
' -- Zweierkomplement bilden:
Wert_aus_ds1820 = Wert_aus_ds1820 And &B0000000011111111
Decr Wert_aus_ds1820 '1 subtrahieren
For I = 0 To 7 'jedes Bit invertieren
Toggle Wert_aus_ds1820.i
Next
Temperatur = -wert_aus_ds1820 'Vorzeichen setzen
End If
Loop
Goto_setmode:
Incr Setmode
If Setmode > 2 Then
Setmode = 0
End If
Cls
Return
Set_date_mode:
If Setmode = 0 Then
Setmode = 2
Else
Setmode = 0
Cls
End If
Return
Setday:
Incr _day
If _day > 31 Then _day = 1
Gosub Setdate
Return
Setmonth:
Incr _month
If _month > 12 Then _month = 1
Gosub Setdate
Return
Setyear:
Incr _year
If _year > 99 Then _year = 0
Gosub Setdate
Gosub Getdatetime
Return
Sethour:
Incr _hour
If _hour > 23 Then _hour = 0
Gosub Settime
Return
Setmin:
Incr _min
If _min > 59 Then _min = 0
Gosub Settime
Return
Setsecond:
_sec = 0
Gosub Settime
Return
Sectic:
If Setmode = 0 Then
Timer1 = Ladetimer1
Gosub Getdatetime
End If
If _sec <> L_sec Then
L_sec = _sec
Incr Print_lcd
End If
Return
'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
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
Kann man da was verbessern oder jemand dazu Tipps geben?
Vielen dank