Du schreibst leider nicht, was für ein Display du hast, bzw. was für ein Controller drauf ist. Auch wird nicht klar warum du den 4-Bit Modus nimmst.
Für den Anfang tät ich normal 8Bit in einem Schritt rüberreichen, mit der selben Schaltung kannst du später immer noch auf 4Bit gehen.
Dein code ist für ein Standard LCD mit HD44780, so du bereit bist nochmal code von asm zu c zu portieren nimm das hier in 8Bit. Wartet immer nur solange bis das Display fertig ist und springt nicht soviel in der Gegend rum (machts auch irgendwie übersichtlicher, IMHO):
Sorry, hab irgendwie keinen Beispielcode in c...Code:lcdtxbytei: ; write single byte instruction to lcd ; rgtmp haelt instruction ; prepare to write instruction CBI portb, 6 ; rs to low ; write the byte RCALL lcdwritebyte RET lcdtxbyted: ; write single byte data to lcd ; rgtmp haelt databyte ; prepare to write data SBI portb, 6 ; rs to high ; write the byte RCALL lcdwritebyte RET lcdwritebyte: ; prepare for write SBI portb, 0 ; execute to high CBI portb, 7 ; rw to low ; portd to output (data bits) LDI rgtmp2, 0xff OUT DDRD, rgtmp2 ; copy byte to port OUT PORTD, rgtmp ; lower execute, exec instruction CBI portb, 0 ; execute to low ; --- check busy flag ; portd to input LDI rgtmp2, 0x00 OUT portd, rgtmp2 ; shut down pullups OUT DDRD, rgtmp2 ; switch to input ; prepare for busy read SBI portb, 7 ; rw to high CBI portb, 6 ; rs to low busyloop: ; if busy low, don't run in circles SBIS PIND, 7 RJMP busyend SBI portb, 0 ; execute to high RJMP busyloop ; end of busy busyend: RET lcdinit: ; config execute SBI DDRB, 0 ; PC0 is output SBI PORTB, 0 ; and set it to high ; config rw (read/write, low for write, high for data/status read) SBI DDRB, 7 ; PC1 is output SBI PORTB, 7 ; and set it to high ; config rs (register select, low for instruction, high for data) SBI DDRB, 6 ; PC2 is output SBI PORTB, 6 ; and set it to high ; init display ; - 8bit, 2 zeilen LDI rgtmp, 0x38 RCALL lcdtxbytei ; - 8bit, 2 zeilen LDI rgtmp, 0x38 RCALL lcdtxbytei ; - display an, cursor an, blink (?) LDI rgtmp, 0x0e RCALL lcdtxbytei ; - clear and home display LDI rgtmp, 0x01 RCALL lcdtxbytei ; - autoincrement LDI rgtmp, 0x06 RCALL lcdtxbytei RET







Zitieren

Lesezeichen