;pinbelegungen .equ wr = 0 .equ rd = 1 .equ ce = 2 .equ cd = 3 .equ re = 4 ;ports .equ ddrcon = ddrc .equ incon = pinc .equ outcon = portc .equ ddrdat = ddrb .equ indat = pinb .equ outdat = portb ;memory .equ texthomelow = 0x00 .equ texthomehigh = 0x00 .equ graphichomelow = 0x00 .equ graphichomehigh = 0x02 ;size .equ rows = 8 .equ columns = 40 lcd_init: push r16 ldi r16,0xff ; steuerleitungen alle ausgänge out ddrcon,r16 out outcon,r16 ;alle high cbi outcon,re ; display reset rcall delay50ms sbi outcon,re ldi r16,texthomelow ; texthome adresse einstellen rcall write ldi r16,texthomehigh rcall write ldi r16, 0x40 rcall command ldi r16,columns ; text area einstellen rcall write ldi r16,0x00 rcall write ldi r16,0x41 rcall command ldi r16,graphichomelow ; graphic adresse einstellen rcall write ldi r16,graphichomehigh rcall write ldi r16,0x42 rcall command ldi r16,columns ; graphic area einstellen rcall write ldi r16,0x00 rcall write ldi r16,0x43 rcall command ldi r16,0b10000000 ; or modus rcall command ldi r16,0b10011100 ; text on, graphic on rcall command rcall cleartext ; text löschen rcall cleargraphic ; graphic löschen pop r16 ret ;------------------------------------------------------------------------------ command: push r16 rcall check out outdat,r16 ; daten ausgeben ldi r16,0xff ; datenleitungen alle Ausgänge out ddrdat,r16 sbi outcon,cd ; command cbi outcon,wr sbi outcon,rd cbi outcon,ce nop ; warten nop nop nop sbi outcon,ce ; disable chip pop r16 ret ;------------------------------------------------------------------------------ write: push r16 rcall check out outdat,r16 ; daten ausgeben ldi r16,0xff ; datenleitungen alle Ausgänge out ddrdat,r16 cbi outcon,cd ; write cbi outcon,wr sbi outcon,rd cbi outcon,ce nop ; warten nop nop nop sbi outcon,ce ; disable chip nop nop pop r16 ret ;------------------------------------------------------------------------------ check: push r16 wait: rcall statusread andi r16, 0b000000011 cpi r16, 0x03 brne wait pop r16 ret ;------------------------------------------------------------------------------ statusread: ldi r16,0x00 ; datenleitungen alle eingänge out ddrdat,r16 ldi r16,0xff out outdat,r16 sbi outcon,cd ; status check sbi outcon,wr cbi outcon,rd cbi outcon,ce nop ; warten nop nop nop in r16,indat ; status read sbi outcon,ce ; disable chip ret ;------------------------------------------------------------------------------ cleartext: push r16 push r17 push r18 ldi r16,texthomelow ; Adresspointer rcall write ldi r16,texthomehigh rcall write ldi r16,0x24 rcall command clr r17 cleartext1: inc r17 clr r18 cleartext2: inc r18 ldi r16, ' ' rcall textsend cpi r18,columns brne cleartext2 cpi r17,rows brne cleartext1 pop r18 pop r17 pop r16 ret ;------------------------------------------------------------------------------ cleargraphic: push r16 push r17 push r18 ldi r16,graphichomelow ; Adresspointer rcall write ldi r16,graphichomehigh rcall write ldi r16,0x24 rcall command clr r17 cleargraphic1: inc r17 clr r18 cleargraphic2: inc r18 ldi r16, 0x00 rcall graphicsend cpi r18,columns brne cleargraphic2 cpi r17,rows*8 brne cleargraphic1 pop r18 pop r17 pop r16 ret ;------------------------------------------------------------------------------ graphicsend: push r16 rcall write ; in puffer schreiben ldi r16,0xc0 ; send and increase rcall command pop r16 ret ;------------------------------------------------------------------------------ textsend: push r16 subi r16,0x20 ; angleichen rcall write ; in puffer schreiben ldi r16,0xc0 ; send and increase rcall command pop r16 ret ;------------------------------------------------------------------------------ delay50ms: push r16 push r17 push r18 ldi r16, $5F delay0: ldi r17, $17 delay1: ldi r18, $79 delay2: dec r18 brne delay2 dec r17 brne delay1 dec r16 brne delay0 pop r18 pop r17 pop r16 ret