So, um das ganze auch mal lesen zu können...
CodeBox BascomAVR
$regfile = "m128def.dat"
$crystal = 12000000
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Config PortA = Output
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 3 , Cd = 0 , Wr = 2 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 8
Cls
Cursor Off
Config Sda = Portd.1 '##### I2C Bus konfigurieren
Config Scl = Portd.0
Const Ds1307w = &HD0 '##### Addresse der Ds1307 Uhr
Const Ds1307r = &HD1
Config Clock = User '##### Interne Time/Date Routinen für Bascom konfigurieren
Config Date = Dmy , Separator = .
Tast1 Alias Pinb.0 '##### Taster1, Zeit/Datum stellen, PullUp ein, schaltet gegen Minus
Tast2 Alias Pinb.1 '##### Taster2, Zahl hochzählen, PullUp ein, schaltet gegen Minus
Lichtan Alias Portd.7 '##### LCD licht
Const Pause = 150 '##### Wartezeit Taster
Config Portd.0 = Input
Config Portd.1 = Input
Config Portd.7 = Output
Portb.0 = 1
Portb.1 = 1
Portd.7 = 0 '##### LCD Licht
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Config 1wire = Porte.0 '##### eingang Temperaturen
Declare Sub Getdatetime
Declare Sub Settime_date
Dim Weekday As Byte
Dim Stunde As Byte
Dim Minute As Byte
Dim Tag As Byte
Dim Monat As Byte
Dim Jahr As Byte
'im Lichtzaeler As Byte
Dim Lichtzaeler As Byte
Dim Zeit As Byte
Dim Sekunde As Byte
Dim Milisekunde As Word
Dim Zielzeit As Word ' Temp -------------------------------------------------------------------------
Dim Ar1(9) As Byte
Dim Ar2(9) As Byte
Dim Ar3(9) As Byte
Dim Ar4(9) As Byte
Dim Ar5(9) As Byte
Dim Ar6(9) As Byte
Dim Temp1 As Single
Dim Temp2 As Single
Dim Temp3 As Single
Dim Temp4 As Single
Dim Temp5 As Single
Dim Temp6 As Single
Dim Tmp1 As Byte
Dim Tmp2 As Byte
Dim Tmp3 As Byte
Dim Tmp4 As Byte
Dim Tmp5 As Byte
Dim Tmp6 As Byte
Dim T1 As Integer
Dim T2 As Integer
Dim T3 As Integer
Dim T4 As Integer
Dim T5 As Integer
Dim T6 As Integer
Dim T7 As Integer
Dim T8 As Integer
Dim T9 As Integer
Dim T10 As Integer
Dim T11 As Integer
Dim T12 As Integer
Dim Tem1 As String * 10
Dim Tem2 As String * 10
Dim Tem3 As String * 10
Dim Tem4 As String * 10
Dim Tem5 As String * 10
Dim Tem6 As String * 10
Dim Dsid(48) As Byte
'--Test ds1820
Dsid(1) = &H10 : Dsid(2) = &Hc0 : Dsid(3) = &H8f : Dsid(4) = &Ha2 : Dsid(5) = &H03 : Dsid(6) = &H08 : Dsid(7) = &H00 : Dsid(8) = &Hfc '## Solar
Dsid(9) = &H10 : Dsid(10) = &H78 : Dsid(11) = &Hef : Dsid(12) = &H9e : Dsid(13) = &H03 : Dsid(14) = &H08 : Dsid(15) = &H00 : Dsid(16) = &H11 '## Brauchwasser SP1 Solar
dsid(17) = &H10 : Dsid(18) = &H5c : Dsid(19) = &H4b : Dsid(20) = &Ha5 : Dsid(21) = &H03 : Dsid(22) = &H08 : Dsid(23) = &H00 : Dsid(24) = &H8b '## Außen Temperatur
Dsid(25) = &H10 : Dsid(26) = &H72 : Dsid(27) = &H3f : Dsid(28) = &Ha5 : Dsid(29) = &H03 : Dsid(30) = &H08 : Dsid(31) = &H00 : Dsid(32) = &H5c '## Kessel Temperatur kontrolle Fußb.
Dsid(25) = &H10 : Dsid(26) = &H29 : Dsid(27) = &HA2 : Dsid(28) = &HDD : Dsid(29) = &H01 : Dsid(30) = &H08 : Dsid(31) = &H00 : Dsid(32) = &H2A
Dsid(33) = &H10 : Dsid(34) = &HC0 : Dsid(35) = &HEA : Dsid(36) = &HDB : Dsid(37) = &H02 : Dsid(38) = &H08 : Dsid(39) = &H00 : Dsid(40) = &HAF
Dsid(41) = &H10 : Dsid(42) = &H29 : Dsid(43) = &HA2 : Dsid(44) = &HDD : Dsid(45) = &H01 : Dsid(46) = &H08 : Dsid(47) = &H00 : Dsid(48) = &H2A
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 256
Enable Timer1
Enable Interrupts
Config Timer2 = Timer , Prescale = 1024
Enable Timer2
on Timer2 Isr_von_timer2
Enable Interrupts
'Time$ = "14:51:10"
'Programm ######################################################################
Do
Locate 2 , 3 : Lcd Time$
If Tast2 = 0 Then
Lichtan = 1
Lichtzaeler = 0
End If
' Lüftung-----------------------------------------------------------------------
Locate 5 , 2 : Lcd "Dusche"
Locate 7 , 2 : Lcd "Haube"
Locate 9 , 2 : Lcd "Rein "
Shift Ar1(1) , Right
Lcd Ar1(1) ; ".";
If Tmp4 = 1 Then
Lcd "5"
Else
Lcd "0"
End If
Locate 11 , 2 : Lcd "Raus"
Locate 13 , 2 : Lcd "Aussen"
'Solar -------------------------------------------------------------------------
Locate 5 , 17 : Lcd "Solarpannel"
Locate 7 , 17 : Lcd "So-Wasser"
'Line(0 , 0) -(240 , 0) , 255 ' horizontal upper line
'Line(0 , 127) -(239 , 127) , 255 'horizontal lower line
'Line(0 , 0) -(0 , 127) , 255 ' vertical left line
'Line(239 , 0) -(239 , 127) , 255 ' vertical right line
'Line(110 , 0) -(110 , 127) , 255 ' mitel line
Debounce Tast1 , 0 , Uhr , Sub
Call Getdatetime
Wait 1
Showpic 0 , 0 , Bild
Loop
End
Bild:
$bgf "test5.bgf"
'Stellen der Uhr Stunde ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Uhr:
Stunde = _hour
Cls
Locate 4 , 17 : Lcd "Set Stunde"
Bitwait Tast1 , Set
Do
Locate 5 , 17
If Stunde > 23 Then Stunde = 0
Lcd "Stunde " ; Stunde ; " "
If Tast2 = 0 Then
Incr Stunde
End If
Waitms Pause
Loop Until Tast1 = 0
'Stellen der Uhr minute
Minute = _min
Cls
Locate 4 , 17 : Lcd "Set Minute"
Bitwait Tast1 , Set
Do
Locate 5 , 17
If Minute > 59 Then Minute = 0
Lcd "Minute " ; Minute ; " "
If Tast2 = 0 Then
Incr Minute
End If
Waitms Pause
Loop Until Tast1 = 0
Bitwait Tast1 , Set
Cls
Bitwait Tast1 , Set
Call Settime_date
Waitms 300
Cls
Return
'-------------------------------------------------------------------------------
Temperatur:
1wreset
1wwrite &H55
1wwrite Dsid(1) , 8
1wwrite &H44
Waitms 200
1wreset
1wwrite &H55
1wwrite Dsid(1) , 8
1wwrite &HBE
Ar1(1) = 1wread(9)
1wreset
Tmp1 = Ar1(1) And 1
1wreset
1wwrite &H55
1wwrite Dsid(9) , 8
1wwrite &H44
Waitms 200
1wreset
1wwrite &H55
1wwrite Dsid(9) , 8
1wwrite &HBE
Ar2(1) = 1wread(9)
1wreset
Tmp2 = Ar2(1) And 1
1wreset
1wwrite &H55
1wwrite Dsid(17) , 8
1wwrite &H44
Waitms 200
1wreset
1wwrite &H55
1wwrite Dsid(17) , 8
1wwrite &HBE
Ar3(1) = 1wread(9)
1wreset
Tmp3 = Ar3(1) And 1
1wreset
1wwrite &H55
1wwrite Dsid(25) , 8
1wwrite &H44
Waitms 200
1wreset
1wwrite &H55
1wwrite Dsid(25) , 8
1wwrite &HBE
Ar4(1) = 1wread(9)
1wreset
Tmp4 = Ar4(1) And 1
' Zeit Daten++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sub Getdatetime
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
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
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
End Sub
Sub Settime_date
_hour = Stunde
_min = Minute
_day = Tag
_month = Monat
_year = Jahr
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cwbyte Weekday
I2cwbyte _day
I2cwbyte _month
I2cwbyte _year
I2cstop
End Sub
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cstop
Return
'imer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Isr_von_timer2:
Incr Milisekunde
If Milisekunde = 30 Then
Milisekunde = 0
Sekunde = Sekunde + 1
Incr Zeit
Incr Zielzeit
Incr Lichtzaeler
End If
If Zielzeit = 16 Then
Zielzeit = 0
End If
If Lichtzaeler = 60 Then
Lichtan = 0
Lichtzaeler = 0
End If
Return
Die Timer sind grundsätzlich erstmal unabhängig von den Ports, allerdings kannst Du einige Spezialfunktionen nutzen, die bei konventionellen AVR an bestimmte Beine gekoppelt sind (Waveform Generation, Input Capture, Takteingang usw).
Bascom verwendet für einige Sachen auch Timer.