;************************************************
; Bei Taktänderung (Quarz) nicht vergessen die ;
; Wartezeiten und nop Befehle an zu passen ;
; nop und Wartebefehle sind in diesem Skript ;
;willkürlich gewählt und performence orientiert.;
; ;
; Chip: ATmega8 ;
; BD0 = PORTC,0 ;
; BD1 = PORTC,1 ;
; BD2 = PORTC,2 ;
; BD3 = PORTC,3 ;
; RS = PORTD,4 ;
; RW = GND ;
; E = PORTD,5 ;
; ;
;************************************************
.include "m8def.inc"
;Alias Namen erstellen
.def temp1 = r16
.def temp2 = r17
.def temp3 = r18
.def temp4 = r19
.def Sekunde = r20
.def Minute = r21
.def Stunde = r22
.org 0
rjmp Programmstart
.org OVF0addr
rjmp Timer0_overflow
Programmstart:
;Stack Initialisieren
ldi temp1, LOW(RAMEND)
out SPL, temp1
ldi temp1, HIGH(RAMEND)
out SPH, temp1
;Ausgänge definieren
LDI temp1,0b11111111
Out DDRD,temp1
LDI temp1,0b00000000
out DDRC,temp1
LDI temp1,0b11111111
out DDRB,temp1
;Zeit laden
LDI Sekunde,0
LDI Minute,0
LDI Stunde,0
;Untere Register laden
LDI temp1,60
mov r2,temp1
LDI temp1,24
mov r3,temp1
;Display Initialisieren
rcall Display_ini
;Timer Initialisieren
LDI temp1, (1<<cs02) | (1<<cs00) ;Teiler=1024
out TCCR0,temp1
LDI temp1,(1<<TOIE0)
out TIMSK,temp1
sei
; rcall Timer0_Overflow
rcall Loop
;Hauptmenü
;****************************************************
Menue:
rcall LCD_löschen
;Stunden schreiben:
;*******************
push temp2 ;Temp1,2, Sichern
mov temp1,Stunde ;Temp1 mit der Sekundenzahl laden
clr temp2
;Zehner
ldi temp2,'0'-1
LCD_Nummer1:
inc temp2
subi temp1,10
brcc LCD_Nummer1
subi temp1,150 ;<------ Hier liegt das Geheimnis! 150 abzihen,
push temp1 ;dann klapts neben ASCII auch mit Binärzahlen!?
rcall Print
;Einer
LCD_Nummer2:
clr temp2
pop temp2
subi temp2,'0'
rcall Print
LDI temp2,':'
rcall Print
;Minuten schreiben
;******************
mov temp1,Minute ;Temp1 mit der Sekundenzahl laden
clr temp2
;Zehner
ldi temp2,'0'-1
LCD_Nummer3:
inc temp2
subi temp1,10
brcc LCD_Nummer3
subi temp1,150 ;<------ Hier liegt das Geheimnis! 150 abzihen,
push temp1 ;dann klapts neben ASCII auch mit Binärzahlen!?
rcall Print
;Einer
LCD_Nummer4:
clr temp2
pop temp2
subi temp2,'0'
rcall Print
LDI temp2,':'
rcall Print
;Sekunden schreiben
;*******************
mov temp1,Sekunde ;Temp1 mit der Sekundenzahl laden
clr temp2
;Zehner
ldi temp2,'0'-1
LCD_Nummer5:
inc temp2
subi temp1,10
brcc LCD_Nummer5
subi temp1,150 ;<------ Hier liegt das Geheimnis! 150 abzihen,
push temp1 ;dann klapts neben ASCII auch mit Binärzahlen!?
rcall Print
;Einer
LCD_Nummer6:
clr temp2
pop temp2
subi temp2,'0'
rcall Print
pop temp2 ;Temp1,2 wider beschreiben
reti
Loop:
rjmp Loop
;*************************************************************************************************************
Flug:
rjmp Menue
Timer0_overflow:
INC Sekunde
CP Sekunde,r2
BRLO Flug
Minute:
CLR Sekunde
INC Minute
CP Minute,r2
BRLO Flug
Stunde:
CLR Minute
INC Stunde
CP Stunde,r3
BRLO Flug
Neuer_Tag:
CLR Sekunde
CLR Minute
CLR Stunde
rjmp Flug
; Display Installieren
;*********************************************************************************************************************
Display_ini:
rcall Waitms20
ldi temp3,3
Widerholung:
LDI temp2,0b00000011
Out portd,temp2
rcall send
dec temp3
brne Widerholung
LDI temp2,0b00000010
OUT Portd,temp2
rcall send
LDI temp2,0b00101000
rcall Send_Befehl
LDI temp2,0b00001100
rcall Send_Befehl
LDI temp2,0b00000100
rcall Send_Befehl
ret
;LCD Löschen
;*********************************
LCD_Löschen:
ldi temp2,0b00000001
rcall Send_Befehl
ret
;Aufs LCD schreiben
;********************************
Print:
Mov temp3,temp2
swap temp2
andi temp2,0b00001111
sbr temp2,0b00010000
out PortD,temp2
rcall send
andi temp3,0b00001111
sbr temp3,0b00010000
OUT Portd,temp3
rcall Send
ret
;Instruktionen ans LCD
;*************************************************
Send_Befehl:
Mov temp3,temp2
swap temp2
andi temp2,0b00001111
out PortD,temp2
rcall send
andi temp3,0b00001111
OUT Portd,temp3
rcall Send
ret
;Warteschleifen
;************************************************
Waitms5:
LDI temp1,50
Waitms5_1:
LDI temp2,255
Waitms5_2:
dec temp2
brne waitms5_2
dec temp1
brne Waitms5_1
ret
Waitms20:
LDI temp1,200
Waitms20_1:
LDI temp2,255
Waitms20_2:
dec temp2
brne waitms20_2
dec temp1
brne Waitms20_1
ret
;Sendefreigabe
;************************************************
Send:
SBI portd,5
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
CBI portd,5
rcall waitms5
ret