![]() |
AVR-Anwendungen LCD-Ansteuerung mit AVR in Assembler Beispielanwendung von "lcd.inc" 8-Bit |
;
; *********************************
; * Test der LCD include routinen *
; * (C)2018 avr-asm-tutorial.net *
; *********************************
;
.nolist
.include "m8def.inc" ; Define device ATmega8
.list
;
; **********************************
; H A R D W A R E
; **********************************
;
; Device: ATmega8, Package: 28-pin-PDIP
;
; _________
; 1 / |28
; RESET o--|RES PC5|--o Key6-Ch4
; LCD-D0 o--|PD0 PC4|--o Key5-Ch3
; LCD-D1 o--|PD1 PC3|--o Key4-Ch2
; LCD-D2 o--|PD2 PC2|--o Key3-Ch1
; LCD-D3 o--|PD3 PC1|--o Key2-Start/Stop
; LCD-D4 o--|PD4 PC0|--o Key1-Reset
; VCC o--|VCC GND|--o GND
; GND o--|GND AREF|--o NC
; XTAL o--|XTAL1 AVCC|--o NC
; 8.0 MHzo--|XTAL2 PB5|--o LCD-RW/SCK
; LCD-D5 o--|PD5 PB4|--o LCD-RS/MISO
; LCD-D6 o--|PD6 PB3|--o PB3/MOSI
; LCD-D7 o--|PD7 PB2|--o LED-RED-Cath
; LCD-E o--|PB0 PB1|--o LSP
; |__________|
;
; **********************************
; A D J U S T A B L E C O N S T
; **********************************
;
; Parameter-Satz der Einstellungen
.equ clock = 8000000 ; Taktfrequenz Prozessor in Hz
; LCD-Groesse:
.equ LcdLines = 4 ; Anzahl Zeilen (1, 2, 4)
.equ LcdCols = 20 ; Anzahl Zeichen pro Zeile (8..24)
; LCD-Ansteuerung
.equ LcdBits = 8 ; Busbreite (4 oder 8)
; Wenn 4-Bit-Ansteuerung:
;.equ Lcd4High = 1 ; Busnibble (1=Oberes, 0=Unteres)
.equ LcdWait = 0 ; Ansteuerung (0 mit Busy, 1 mit Warteschleifen)
; LCD-Datenports
.equ pLcdDO = PORTD ; Daten-Ausgabe-Port
.equ pLcdDD = DDRD ; Daten-Richtungs-Port
; LCD-Kontrollports und -pins
.equ pLcdCEO = PORTB ; Control E Ausgabe-Port
.equ bLcdCEO = PORTB0 ; Controll E Ausgabe-Portpin
.equ pLcdCED = DDRB ; Control E Richtungs-Port
.equ bLcdCED = DDB0 ; Control E Richtungs-Portpin
.equ pLcdCRSO = PORTB ; Control RS Ausgabe-Port
.equ bLcdCRSO = PORTB4 ; Controll RS Ausgabe-Portpin
.equ pLcdCRSD = DDRB ; Control RS Richtungs-Port
.equ bLcdCRSD = DDB4 ; Control RS Richtungs-Portpin
; Wenn LcdWait = 0:
.equ pLcdDI = PIND ; Daten-Input-Port
.equ pLcdCRWO = PORTB ; Control RW Ausgabe-Port
.equ bLcdCRWO = PORTB5 ; Control RW Ausgabe-Portpin
.equ pLcdCRWD = DDRB ; Control RW Richtungs-Port
.equ bLcdCRWD = DDB5 ; Control RW Richtungs-Portpin
; Wenn Dezimalwandlung:
.equ LcdDecimal = 1
; Wenn Hexwandlung:
.equ LcdHex = 1
; Wenn nur Simulation im SRAM:
;.equ avr_sim = 1 ; 1=Simulieren, 0 oder ndef=Nicht simulieren
;
; **********************************
; F I X & D E R I V. C O N S T
; **********************************
;
;
; **********************************
; R E G I S T E R S
; **********************************
;
.def rmp = R16
;
; **********************************
; S R A M
; **********************************
;
.dseg
.org SRAM_START
.byte 16
;
; **********************************
; C O D E
; **********************************
;
.cseg
.org 000000
;
; **********************************
; R E S E T & I N T - V E C T O R S
; **********************************
rjmp Main ; Reset vector
reti ; INT0
reti ; INT1
reti ; OC2
reti ; OVF2
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
reti ; OVF0
reti ; SPI
reti ; URXC
reti ; UDRE
reti ; UTXC
reti ; ADCC
reti ; ERDY
reti ; ACI
reti ; TWI
reti ; SPMR
;
; **********************************
; I N T - S E R V I C E R O U T .
; **********************************
;
; Add all interrupt service routines
;
; **********************************
; M A I N P R O G R A M I N I T
; **********************************
;
Main:
.ifdef SPH
ldi rmp,High(RAMEND)
out SPH,rmp
.endif
ldi rmp,Low(RAMEND)
out SPL,rmp ; Init LSB stack pointer
rcall LcdInit
ldi ZH,High(2*InitText)
ldi ZL,Low(2*InitText)
rcall LcdText
ldi ZH,2
ldi ZL,5
rcall LcdPos
ldi ZH,High(12345)
ldi ZL,Low(12345)
rcall LcdDec5
ldi ZH,3
ldi ZL,5
rcall LcdPos
ldi ZH,High(12345)
ldi ZL,Low(12345)
rcall LcdHex4
; ...
;sei ; Enable interrupts
;
; **********************************
; P R O G R A M L O O P
; **********************************
;
Loop:
rjmp loop
;
; Include LCD-Routinen
.include "lcd.inc"
;
InitText:
.db "lcd.inc 8-bit busy",0x0D,0xFF
.db "Display 4x20",0x0D,0xFF
.db "Dec5=",0x0D
.db "Hex4=",0x0D
.db 0xFE,0xFF
;
;
; End of source code
;