Path: Home => AVR-EN => Applications => LCD access with an AVR => Example 8 bit ATmega8
LCD small AVR Applications

LCD Access with an AVR in assembler

Example application of "lcd.inc" 8 bit
Logo

Example application of lcd.inc in 8 bit mode on an ATmega8

The assembler source code as shown here can be downloaded here in asm format.

;
; ************************************
; * Test of the LCD include routines *
; * (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
; **********************************
;
; Standard parameter set of properties/definitions
.equ clock = 8000000 ; Clock frequency of controller in Hz
; LCD size:
  .equ LcdLines = 4 ; Number of lines (1, 2, 4)
  .equ LcdCols = 20 ; Number of characters per line (8..24)
; LCD bus interface
  .equ LcdBits = 8 ; Bus size (4 or 8)
  ; If 4 bit bus:
    ;.equ Lcd4High = 1 ; Bus nibble (1=Upper, 0=Lower)
  .equ LcdWait = 0 ; Access mode (0 with busy, 1 with delay loops)
; LCD data ports
  .equ pLcdDO = PORTD ; Data output port
  .equ pLcdDD = DDRD ; Data direction port
; LCD control ports und pins
  .equ pLcdCEO = PORTB ; Control E output port
  .equ bLcdCEO = PORTB0 ; Control E output portpin
  .equ pLcdCED = DDRB ; Control E direction port
  .equ bLcdCED = DDB0 ; Control E direction portpin
  .equ pLcdCRSO = PORTB ; Control RS output port
  .equ bLcdCRSO = PORTB4 ; Control RS output portpin
  .equ pLcdCRSD = DDRB ; Control RS direction port
  .equ bLcdCRSD = DDB4 ; Control RS direction portpin
; If LcdWait = 0:
  .equ pLcdDI = PIND ; Data input port
  .equ pLcdCRWO = PORTB ; Control RW output port
  .equ bLcdCRWO = PORTB5 ; Control RW output portpin
  .equ pLcdCRWD = DDRB ; Control RW direction port
  .equ bLcdCRWD = DDB5 ; Control RW direction portpin
; If you need binary to decimal conversion:
  .equ LcdDecimal = 1 ; If defined: include those routines
; If you need binary to hexadecimal conversion:
  .equ LcdHex = 1 ; If defined: include those routines
; If simulation in the SRAM is desired:
  ;.equ avr_sim = 1 ; 1=Simulate, 0 or undefined=Do not simulate
;
; **********************************
;  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
;



Praise, error reports, scolding and spam please via the comment page to me.

To the top of that page

©2018 by http://www.avr-asm-tutorial.net