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

LCD Access with an AVR in assembler

Example application of "lcd.inc" 4 bit
Logo

Example application of lcd.inc in 4 bit mode on an ATtn24

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

;
; ************************************
; * Test of the LCD include routines *
; *   in 4 bit mode                  *
; * (C)2018 avr-asm-tutorial.net     *
; ************************************
;
.nolist
.include "tn24adef.inc" ; Define device ATtiny24A
.list
;
; **********************************
;        H A R D W A R E
; **********************************
;
; Device: ATtiny24A, Package: 14-pin-PDIP_SOIC
;            ________
;         1 /        |14
;  + 5 V o--|VCC  GND|--o 0 V
; LCD-RS o--|PB0  PA0|--o PA0
; LCD-E  o--|PB1  PA1|--o PA1
;  RESET o--|RES  PA2|--o PA2
; LCD-RW o--|PB2  PA3|--o PA3
; LCD-D7 o--|PA7  PA4|--o LCD-D4
; LCD-D6 o--|PA6  PA5|--o LCD-D5
;           |________|
;
; **********************************
;   A D J U S T A B L E   C O N S T
; **********************************
;
; Standard parameter set of properties/definitions
.equ clock = 1000000 ; 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 = 4 ; 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 = PORTA ; Data output port
  .equ pLcdDD = DDRA ; Data direction port
; LCD control ports und pins
  .equ pLcdCEO = PORTB ; Control E output port
  .equ bLcdCEO = PORTB2 ; Control E output portpin
  .equ pLcdCED = DDRB ; Control E direction port
  .equ bLcdCED = DDB2 ; Control E direction portpin
  .equ pLcdCRSO = PORTB ; Control RS output port
  .equ bLcdCRSO = PORTB0 ; Control RS output portpin
  .equ pLcdCRSD = DDRB ; Control RS direction port
  .equ bLcdCRSD = DDB0 ; Control RS direction portpin
; If LcdWait = 0:
  .equ pLcdDI = PINA ; Data input port
  .equ pLcdCRWO = PORTB ; Control RW output port
  .equ bLcdCRWO = PORTB1 ; Control RW output portpin
  .equ pLcdCRWD = DDRB ; Control RW direction port
  .equ bLcdCRWD = DDB1 ; 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 ; EXT_INT0
;	reti ; PCI0
;	reti ; PCI1
;	reti ; WATCHDOG
;	reti ; ICP1
;	reti ; OC1A
;	reti ; OC1B
;	reti ; OVF1
;	reti ; OC0A
;	reti ; OC0B
;	reti ; OVF0
;	reti ; ACI
;	reti ; ADCC
;	reti ; ERDY
;	reti ; USI_STR
;	reti ; USI_OVF
;
; **********************************
;  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:
  ldi rmp,Low(RAMEND)
  out SPL,rmp ; Init LSB stack pointer
  rcall LcdInit
  ldi ZH,High(2*Codezeichen)
  ldi ZL,Low(2*Codezeichen)
  rcall LcdSpec
  ldi ZH,High(2*InitText)
  ldi ZL,Low(2*InitText)
  rcall LcdText
; ...
  ;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 4-bit busy",0x0D,0xFF
.db "Display 4x20",0x0D,0xFF
.db "Spezialzeichen:",0x0D
.db 0x00,' ',0x01,' ',0x02,' ',0x03,' ',0x04,' ',0x05,' ',0x06,' ',0x07,0xFF
.db 0xFE,0xFF

;
; Table of code characters
Codezeichen:
.db 64,0,0,12,6,31,6,12,0,0 ; Z = 0, arrow right
.db 72,0,0,6,12,31,12,6,0,0 ; Z = 1, arrow left
.db 80,0,4,14,31,21,4,4,4,0 ; Z = 2, arrow up
.db 88,0,4,4,4,21,31,14,4,0 ; Z = 3, arrow down
.db 96,0,0,15,3,5,9,16,0,0 ; Z = 4, arrow right up
.db 104,0,0,16,9,5,3,15,0,0 ; Z = 5, arrow right down
.db 112,0,0,1,18,20,24,30,0,0 ; Z = 6, arrow left down
.db 120,0,0,30,24,20,18,1,0,0 ; Z = 7, arrow left up
.db 0,0 ; End of table
;

; 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