; 1509051043 ; Testprogramm gemaess Schaltplan 1509032228 .include "tn26def.inc" .equ f_CPU = 1000000 ; cave: nicht fuer wait2ms .def tmp0 = r16 .def tmp1 = r17 .equ DDR_LCDrs = DDRA .equ PORT_LCDrs = PORTA .equ LCDrs = 4 .equ DDR_LCDen = DDRA .equ PORT_LCDen = PORTA .equ LCDen = 5 .equ DDR_LCDd7 = DDRA .equ PORT_LCDd7 = PORTA .equ LCDd7 = 7 .equ DDR_LCDd6 = DDRA .equ PORT_LCDd6 = PORTA .equ LCDd6 = 6 .equ DDR_LCDd5 = DDRA .equ PORT_LCDd5 = PORTA .equ LCDd5 = 2 .equ DDR_LCDd4 = DDRA .equ PORT_LCDd4 = PORTA .equ LCDd4 = 1 ;====================== .org 0 ldi tmp0,RAMEND out SP,tmp0 rcall wait2ms rcall LCDinit rcall flash_to_LCDbyte .db 11,"Anfang&Ende" rjmp pc ;====================== LCDinit: cbi PORT_LCDen,LCDen cbi PORT_LCDrs,LCDrs sbi DDR_LCDen,LCDen sbi DDR_LCDrs,LCDrs sbi DDR_LCDd7,LCDd7 sbi DDR_LCDd6,LCDd6 sbi DDR_LCDd5,LCDd5 sbi DDR_LCDd4,LCDd4 ; in den 4-bit-Modus schalten unabhaengig von der Vorgeschichte: ldi tmp0,$03 ; dreimal: sicher in den 8-bit-Modus kommen rcall LCDn rcall wait2ms ldi tmp0,$03 rcall LCDn rcall wait2ms ldi tmp0,$03 rcall LCDn rcall wait2ms ldi tmp0,$02 ; 4-bit-mode rcall LCDn ldi tmp0,$28 ; 4-bit-mode, 2 lines, 5*7 dots rcall LCDcmd ldi tmp0,$06 ; increase, no shift rcall LCDcmd ldi tmp0,$0C ; display on, cursor on, blinking off rcall LCDcmd LCDclear: ldi tmp0,$01 rjmp LCDcmd LCDcmd: ; command byte cbi PORT_LCDrs,LCDrs push tmp0 rcall LCDb pop tmp0 andi tmp0,$FC ; displayclear oder returnhome ? breq pc+2 ret rjmp wait2ms ; > 1.64 ms LCDbyte: ; data byte sbi PORT_LCDrs,LCDrs LCDb: push tmp0 swap tmp0 rcall LCDn pop tmp0 LCDn: ; nibble sbi PORT_LCDen,LCDen cbi PORT_LCDd7,LCDd7 sbrc tmp0,3 sbi PORT_LCDd7,LCDd7 cbi PORT_LCDd6,LCDd6 sbrc tmp0,2 sbi PORT_LCDd6,LCDd6 cbi PORT_LCDd5,LCDd5 sbrc tmp0,1 sbi PORT_LCDd5,LCDd5 cbi PORT_LCDd4,LCDd4 sbrc tmp0,0 sbi PORT_LCDd4,LCDd4 cbi PORT_LCDen,LCDen ldi tmp0,f_CPU/100000 ; >46us warten rjmp pc+1 dec tmp0 brne pc-2 ret flash_to_LCDbyte: ; ! tmp0,tmp1,ZL,ZH ! ;.db 7,'Muster ' nach rcall pop ZH pop ZL lsl ZL rol ZH lpm tmp1,z adiw ZL,1 lpm tmp0,z adiw ZL,1 rcall LCDbyte dec tmp1 brne pc-4 adiw ZL,1 lsr ZH ror ZL ijmp wait2ms: ; fest fuer 1 MHz push tmp0 ldi tmp0,200 rcall return dec tmp0 brne pc-2 pop tmp0 return: ret