.include "m8def.inc" ;Atmega8
.DEF rd1lh = R0 ; LSB Divident Multiplikator 1 (8 Bit)
.DEF rd1l = R1 ; LSB Divident Multiplikator 1 (8 Bit)
.DEF rd1h = R2 ; MSB Divident Hilfsregister für Multiplikation
.DEF rd2h = R3 ; MSB Divident Hilfsregister für Multiplikation
.DEF rd3h = R4 ; MSB Divident Hilfsregister für Multiplikation
.DEF rd1u = R5 ; Hifsregister Multiplikator 2 (1-8 Bit)
.DEF rd2u = R6 ; Hifsregister Multiplikator 2 (9-16 Bit)
.DEF rd3u = R7 ; Hifsregister Multiplikator 2 (16-24 Bit)
.DEF rel = R8 ; LSB Ergebnis Ergebnis, LSB (16 Bit) = zehner und einer
.DEF reh = R9 ; MSB Ergebnis Ergebnis, MSB1 = tauserder und hunderter
.DEF reh2 = R10 ; Ergebnis, MSB2
.DEF rd2 = R11 ; Divisor
;.def disp = r12 ; Zähler für Sekundenausgabe
.def BCD0 = r13
.def BCD1 = r14 ;
.def BCD2 = r15 ;Speicherregister für Status des Hauptprogr.
.def temp0 = r16 ;da ein Verknüpfung mit
.def temp1 = r17 ;dem Infodisplay geplant ist.
.def temp2 = r18
.def temp3 = r19 ;Registerbezeichnung bleibt,
.def temp4 = r20
.def cnt = r21
.def sek = r22
.def WorkH = r23 ; Arbeitsregister für das Hauptprogramm
.def Count1= r24 ; Zähler der Interrupts
.def Count2= r25 ; Zählt die festgelegten sek runter
.equ abz =$0060 ;
.equ temperature_lsb =$0061 ;
.equ temperature_msb =$0062 ;
.equ TH_register =$0063 ;
.equ TL_register =$0064 ;
.equ res_byte4 =$0065 ;
.equ res_byte5 =$0066 ;
.equ count_remain =$0067 ;
.equ count_per_c =$0068 ;
.equ crc =$0069 ;
.equ halbeh =$006a
.equ halbel =$006b
.equ family1 =$006c ;
.equ abz2 =$006d
;;;;;;$0080 benutzt
;;;;;;$0081 benutzt
;;;;;;$0082 benutzt
;***************************Einsprungadressen***********************
.cseg
.org $0000
rjmp Reset
Reset: rjmp stack
reti
reti
reti
reti
reti
;***************************Init mit allem drumdran*****************
stack: ldi temp1,high(ramend) ;Stackpointer festlegen
out sph, temp1
ldi temp1,low(ramend) ;Stackpointer festlegen
out spl, temp1
ldi temp0,$3f
out ddrc,temp0
rcall lcd_init
rcall lcd_clear
clr temp0
out ddrb,temp0
ldi temp0,$70
out ddrd,temp0
rcall sram
ldi temp1,$01
sts abz2,temp1
rjmp main
;***************************Hauptprogramme****************************
main: sbic pinb,0
rcall ds18_t
sbic pinb,1
rcall ds18_rr
sbic pinb,2
rcall ds18_wm
sbic pinb,3
rcall ds18_cp
rjmp main
;*************************temp eines sensors lesen*********************
ds18_t: rcall ds_reset ;wer ist da???
rcall skip_rom
rcall convert_t
rcall ds_reset ;wer ist da???
rcall skip_rom ;
rcall read_scratchpad
rcall ds_reset
rcall ausgabe
ret
;****************adr auslesen eines einzelnen sensors****************
ds18_rr: rcall ds_reset ;wer ist
rcall read_rom
rcall ds_reset ;wer ist rcall ausgabe3
ret
;*******************temp lesen in abhängigkeit der adr****************
ds18_wm: rcall ds_reset
rcall match_rom
rcall s1_64bit
rcall convert_t
rcall ds_reset
rcall match_rom
rcall s1_64bit
rcall read_scratchpad
rcall ausgabe3
ret
;************************Th und Tl write******************************
ds18_thl:
rcall ds_reset
rcall skip_rom
rcall write_scratchpad
rcall write_thl
ds18_cp: rcall ds_reset
rcall skip_rom
rcall read_scratchpad
rcall ds_reset
rcall skip_rom
rcall copy_scratchpad
rcall ausgabe3
ret
;***************************unterprogramme****************************
sram: clr temp0
clr temp1
ldi r28,low($0060)
ldi r29,high($0060)
sram2: inc temp1 ;Masterclr des Sram's über
st y+,temp0 ;die indirekte Adressierung
cpi temp1,$40 ;anzahl der zellen zum löschen
breq sramstopp ;
rjmp sram2
sramstopp: ret
;*****************************RESETPULS*********************************
***
ds_reset:
sbi ddrd,0
cbi portd,0
rcall w500u
cbi ddrd,0
rcall w70u
wait_puls: sbic pind,0
rjmp wait_puls ;falls bus high zurück
wait_puls_end: sbis pind,0
rjmp wait_puls_end ;falls bus low zurück
ret
;*********ansprechen aller slave's, tempmessung auslösen aller
sensoren**
;***nachfolgend muss keine adr gesendet werden nur 1slave einfache *****
;***kommunikation ohne adr zu senden ***********************************
skip_rom:
ldi temp1,$cc
rcall write_command ;read or write
ret
match_rom: ldi temp1,$55
rcall write_command
ret
write_scratchpad: ldi temp1,$4E
rcall write_command
ret
write_thl: ldi temp1,$01 ;Tl
rcall write_command
rcall delay10ms
ldi temp1,$00 ;Th
rcall write_command
rcall delay10ms
ret
copy_scratchpad: ldi temp1,$48
rcall write_command
sbi ddrd,0
sbi portd,0
rcall delay10ms
rcall delay10ms
cbi ddrd,0
cbi portd,0
ret
;**************************read rom 64bits=8byte*********************
read_rom:
ldi temp1,$33
rcall write_command
rcall lesen ;daten empfangen und lesen
ret
;*******************read_scratchpad(auslesen der 9byte)****************
read_scratchpad: ldi temp1,$be
rcall write_command
rcall lesen
ret
;***********Convert---T temperaturmessung starten im ds*************
convert_t: ldi temp1,$44
rcall write_command
rcall w6u
cbi ddrd,0
rcall w9u
convert_t1: sbis pind,0
rjmp convert_t1
ret
;*********************auslesen*****************************************
lesen: rcall read_bit ;0
sts temperature_lsb,temp3
rcall read_bit ;1
sts temperature_msb,temp3
rcall read_bit ;2
sts TH_register,temp3
rcall read_bit ;3
sts TL_register,temp3
rcall read_bit ;4
sts res_byte4,temp3
rcall read_bit ;5
sts res_byte5,temp3
rcall read_bit ;6
sts count_remain,temp3
rcall read_bit ;7
sts count_per_c,temp3
rcall read_bit ;8
sts crc,temp3
ret
;************************Unterprogramme******************************
write_command: ldi temp2,$08
write_command1: sbrs temp1,0
rcall write_0
sbrc temp1,0
rcall write_1
ror temp1
dec temp2
rcall w1u
brne write_command1
ret
write_1: cbi portd,0
sbi ddrd,0
rcall w6u
cbi ddrd,0
rcall w64u
ret
write_0: cbi portd,0
sbi ddrd,0
rcall w60u
cbi ddrd,0
rcall w10u
ret
read_bit: clr temp3 ;datenwort in temp3
ldi temp4,$08
read_bit0: ror temp3
cbi portd,0
sbi ddrd,0
rcall w6u
cbi ddrd,0
rcall w9u
sbis pind,0
rjmp read_bit1
ldi temp2,$80
add temp3, temp2
rjmp read_bit2
read_bit1: ldi temp2,$00
add temp3,temp2
read_bit2: rcall w55u
dec temp4
brne read_bit0
ret
;********************adr s1******************************************
s1_64bit:
ldi temp1,$10 ;0016
rcall write_command
ldi temp1,$fa ;0250
rcall write_command
ldi temp1,$24 ;0036
rcall write_command
ldi temp1,$c0 ;0192
rcall write_command
ldi temp1,$01 ;0001
rcall write_command ldi temp1,$08 ;0008
rcall write_command
ldi temp1,$00 ;0000
rcall write_command
ldi temp1,$c7 ;0199
rcall write_command
ret
s2_64bit:
ldi temp1,$10 ;0016
rcall write_command
ldi temp1,$c2 ;0194
rcall write_command
ldi temp1,$23 ;0035
rcall write_command
ldi temp1,$a6 ;0166
rcall write_command
ldi temp1,$01 ;0001
rcall write_command
ldi temp1,$08 ;0008
rcall write_command
ldi temp1,$00 ;0000
rcall write_command
ldi temp1,$80 ;0128
rcall write_command
ret
s3_64bit:
ldi temp1,$10 ;0016
rcall write_command
ldi temp1,$8a ;0138
rcall write_command
ldi temp1,$24 ;0036
rcall write_command
ldi temp1,$68 ;0104
rcall write_command
ldi temp1,$01 ;0001
rcall write_command
ldi temp1,$08 ;0008
rcall write_command
ldi temp1,$00 ;0000
rcall write_command
ldi temp1,$52 ;0082
rcall write_command
ret
;***********************ausgabe*************************************
ausgabe3: lds temp0,temperature_lsb
sts abz,temp0
ldi temp1,0b10000000
rcall anzeige3
lds temp0,temperature_msb
sts abz,temp0
ldi temp1,0b10000100
rcall anzeige3
lds temp0,TL_register
sts abz,temp0
ldi temp1,0b10001000
rcall anzeige3
lds temp0,TH_register
sts abz,temp0
ldi temp1,0b10001100
rcall anzeige3
lds temp0,res_byte4
sts abz,temp0
ldi temp1,0b11000000
rcall anzeige3
lds temp0,res_byte5
sts abz,temp0
ldi temp1,0b11000100
rcall anzeige3
lds temp0,count_remain
sts abz,temp0
ldi temp1,0b11001000
rcall anzeige3
lds temp0,count_per_c
sts abz,temp0
ldi temp1,0b11001100
rcall anzeige3
rcall warte3s
rcall lcd_clear
lds temp0,crc
sts abz,temp0
ldi temp1,0b10000000
rcall anzeige3
rcall warte3s
ret
ausgabe: rcall div_2
ldi temp1,0b10000100
rcall point
lds temp0,halbeh
sts abz,temp0
ldi temp1,0b10000000
rcall anzeige3
lds temp0,halbel
sts abz,temp0
ldi temp1,0b10000101
rcall anzeige2
rcall warte3s
ret
;**********************ausgabe****************************************
anzeige2: rcall lcd_clearAX ;Ausgabe
lds temp1,abz
rcall Zahldezi ;Hex in Dezimal
rcall Zahlout2 ;DezimalWert 2 Stellen
ret
anzeige3: rcall lcd_clearAX ;Ausgabe
lds temp1,abz
rcall Zahldezi ;Hex in Dezimal
rcall Zahlout4 ;DezimalWert 2 Stellen
ret
div_2: lds temp0,temperature_lsb
cpi temp0,$00
breq ende
div_21: inc temp1
subi temp0,$02
cpi temp0,$01
breq div_22
cpi temp0,$00
brne div_21
sts halbeh,temp1
clr temp2
sts halbel,temp2
ret
ende: clr temp2
sts halbeh,temp2
sts halbel,temp2
ret
div_22: sts halbeh,temp1
ldi temp2,$32
sts halbel,temp2
ret
;************************Zeitunterprogramme*************************
w750ms: sbi ddrd,0
sbi portd,0
ldi temp0,$1f
w750ms2: ldi temp1,$80
w750ms3: ldi temp2,$fb
w750ms4: dec temp2
brne w750ms4
dec temp1
brne w750ms3
nop
nop
dec temp0
brne w750ms2
cbi portd,0
cbi ddrd,0
rcall w6u
ret
w500u: ldi temp0,$03
w500u1: ldi temp1,$dd
w500u2: dec temp1
brne w500u2
dec temp0
brne w500u1
ret
w410u: ldi temp0,$03
w410u1: ldi temp1,$b5
w410u2: dec temp1
brne w410u2
dec temp0
brne w410u1
ret
w70u: ldi temp0,$5a
nop
w70u1: dec temp0
brne w70u1
nop
nop
ret
w64u: ldi temp0,$54
w64u1: dec temp0
brne w64u1
ret
w60u: ldi temp0,$4e
w60u1: dec temp0
brne w60u1
ret
w55u: ldi temp0,$47
w55u1: dec temp0
brne w55u1
ret
w40u: ldi temp0,$33
w40u1: dec temp0
brne w40u1
ret
w15u: ldi temp0,$13
w15u1: dec temp0
brne w15u1
ret
w10u: ldi temp0,$0c
w10u1: dec temp0
brne w10u1
ret
w9u: ldi temp0,$0a
w9u1: dec temp0
brne w9u1
ret
w6u: ldi temp0,$06
w6u1: dec temp0
brne w6u1
ret
w1u: nop
ret
;***************************txtausgabe*********************************
;*************************ascIIwandlung*****************************
out1: .db"."
out2: .db" "
out3: .db"online"
;*************************weitere*includedata***********************
.include "lcd-rout.asm" ;LCD-Routinen
.include "ds18s20.asm"
;*************************ENDE**************************************