Path:AVR-EN => Applications => ATtiny24 experimental board with LCD
tn24_lcd experimental board small Applications of
AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega
Experimental board with an ATtiny24/44/84 and an LCD
Logo

Experimental board with an ATtiny24/44/84 and a LCD

This page as PDF (19 pages, 1.1 MB)

tn24_lcd experimental board For those who need a small controller application with an LCD and need up to four I/O pins of the controller for own purposes, here is a tailored solution:

0 Overview

  1. Hardware
  2. Mounting
  3. Software

1 Hardware

1.1 Scheme of the board

tn24_lcd scheme With that scheme either an ATtiny24, an ATtiny44 or an ATtiny84, resp. the corresponding A types, can be used. The A types only differ in the supply current and in other electrical properties, different numbers differ by available flash and EEPROM memory.

The capacitor of 10 or 100 nF (ceramic type) and the reset pull-up resistor of 10 k are standard components.

The six pin plug “Bread6” provides the four pins PA0 to PA3 of the controller and the supply voltage pins GND and VCC for external use (e.g. on a breadboard).

The ISP6 pin plug serves as a standard programming interface to program the ATtiny in-circuit. When ISP programming the LCD can stay plugged in.

The LCD is attached via a 16 pin standard plug. If the LCD has no background light, pin 15 and 16 are unused and the 220 Ω resistor is not needed. If the backlight needs higher current, the resistor can be calculated with the formula
R (Ohm) = 1.000 * (UOp - ULED) / I (mA)

and can be smaller.

1.2 Parts list

tn24_lcd parts list The electronic parts are listed to the left. The LCD is not included because the type and size depends from your needs. For simple applications a single-line LCD is sufficient, for more info to be displayed a white-on-blue four line LCD can be used. For changing the LCD size only the two constants cLcdLines and cLcdColumns have to be changed in the LCD include routine, the output positions have to be adjusted, and the source code has to be re-assembled. The given price information in the list is of February 2018 and subject to changes.

1.3 Example applications

Several different applications are described in the chapters 11 to 14 of the microbeginner course. There the following applications are described in detail:
  1. here is an 8- and a 16-bit binary counter described that advances each time the controller is switched on, reads from/writes to EEPROM and displays the number in decimal format on LCD,
  2. here an infrared remote control receiver is described that analyses control signals with diverse tools, an Attiny13 remote control transmitter and an Attiny24 IR data receiver with LCD,
  3. here a frequency counter for digital and small-amplitude analog signals and for measuring inductivities is decribed,
  4. here a voltage meter for voltages of up to 20 V, for currents up to several amperes DC and for temperatures inside the controller is described.
The applications run without any changes on this experimental board and work with a 4x20 LCD. Source code for those applications and the needed include file Lcd4Busy.inc are provided for download.

Top of page 1 Hardware 2 Mounting 3 Software


2 Mounting

2.1 PCB

tn24_lcd PCB tn24_lcd component placement The components can be mounted on a 40*50 mm single-sided PCB (Soldering side as gif, Component placement as gif). Three connections have to be made with silver wire.

2.2 Mechanical mounting

tn24_lcd LCD plug from below tn24_lcd LCD plug from above The LCD connections are equipped with a 16 pin plug as shown here. If the LCD is plated-through, the contacts are soldered from above. If not: shift the 16 pin plug through the holes with the long side of the plug, but only as deep as necessary. Then solder the pins and after that shift the plastic holder upward. If you want to take the risk of twisted pins you can even remove that plastic holder entirely after soldering.

The pins fit perfectly into the socket of the PCB. With the advantage that you can exchange the LCD by another type at any time.


Top of page 1 Hardware 2 Mounting 3 Software



3 Software

For accessing the LCD two different versions of the software are available:
  1. A universal version, that handles all different connections of LCDs, including 8 bit versions, and
  2. a special version that is adapted only to this hardware and that handles only the ATtiny24 and this 4 bit version.
Note that all software versions provided here make extensive use of .IF, .IFDEF, .ELSE and .ENDIF directives. Therefore you'll have to use an assembler version that handles those. ATMEL's assembler version 2 is fine. If you are stuck with an older version or an old assembler you'll get error messages instead. In that case consider to use gavrasm instead.

3.1 Universal version lcd.inc

For not having to write LCD routines for each and every case, that differ only minor from each other, the universal version lcd.inc has been developed. It is extensively described here on this website. This version handles

3.1.1 Standard parameter set for tn24_lcd

Here is the standard set of parameters for the tn24_lcd, as adapted to this hardware setting (copied from lcd.inc and edited):

; 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
;

This parameter set does not support decimal and hex conversion. If you need those remove the two semicolons.

3.1.2 Standard routines of the include file

The routines that are provided are listed in the first lines of lcd.inc as follows:

; ***********************************************
; *  L C D   I N T E R F A C E  R O U T I N E S *
; ***********************************************
;
; +-------+----------------+--------------+
; |Routine|Function        |Parameters    |
; +-------+----------------+--------------+
; |LcdInit|Inits the LCD   |Ports, pins   |
; |       |in the desired  |              |
; |       |mode            |              |
; +-------+----------------+--------------+
; |LcdText|Displays the    |Z=2*Table     |
; |       |text in flash   |  address     |
; |       |memory starting |0x0D: Next    |
; |       |with line 1     |      line    |
; |       |                |0xFF: Ignore  |
; |       |                |0xFE: Text end|
; +-------+----------------+--------------+
; |LcdSram|Display the text|Z=SRAM-Address|
; |       |in SRAM         |R16: number of|
; |       |                |    characters|
; +-------+----------------+--------------+
; |LcdChar|Display charac- |R16: Character|
; |       |ter on LCD      |              |
; +-------+----------------+--------------+
; |LcdCtrl|Output control  |R16: Control  |
; |       |byte to LCD     |     byte     |
; +-------+----------------+--------------+
; |LcdPos |Set position on |ZH: Line 0123 |
; |       |the LCD         |ZL: Col 0..   |
; +-------+----------------+--------------+
; |LcdSpec|Generate special|Z: 2*Table    |
; |       |characters      |   address    |
; +-------+----------------+--------------+
; |    S W I T C H   L C D D E C I M A L  |
; +-------+----------------+--------------+
; |LcdDec2|Convert to two  |R16: Binary   |
; |       |decimal digits  |     8 bit    |
; +-------+----------------+--------------+
; |LcdDec3|Convert to three|R16: Binary   |
; |       |decimal digits, |     8 bit    |
; |       |supp. leading 0s|              |
; +-------+----------------+--------------+
; |LcdDec5|Convert to five |Z: Binary     |
; |       |decimal digits, |   16 bit     |
; |       |supp. leading 0s|              |
; +-------+----------------+--------------+
; |      S W I T C H   L C D H E X        |
; +-------+----------------+--------------+
; |LcdHex2|Convert to two  |R16: Binary   |
; |       |digits in hex   |     8 bit    |
; +-------+----------------+--------------+
; |LcdHex4|Convert to four |Z: Binary     |
; |       |digits in hex   |   16 bit     |
; +-------+----------------+--------------+
;

Some renaming has been done here as compared with the include file tn24_lcd_busy.inc (see the next chapters). But changing from tn24_lcd_busy.inc to lcd.inc should not cause too much trouble, so I recommend to move to the more universal include.

3.1.3 Used flash memory

By including the lcd.inc the following memory sizes are occupied:
VersionSize
Words
Accumulated
Minimal version (1 MHz, 8 bit, wait mode, w/o Dec/Hex) 138-
Wait ==> Busy+9147
1 MHz ==> 20 MHz+20158
8 bit ==> 4 bit+44182
LcdDecimal+86224
LcdHex+14152
Maximum version (20 MHz, 4 bit, busy mode, decimal and hex conversion) +197335
The version adapted to tn24_lcd with the above configuration requires 200 words.

3.2 Special version tn24_lcd_busy.inc

All necessary subroutines for accessing the LCD in the experimental board are part of the include file (see the include source code or the html-formatted include listing). By calling the following subroutines the following tasks can be performed: Prior to using the routines the following has to be assured:

3.2.1 Number conversion and display routines

tn24_lcd Optional number display on the LCD Optionally routines for displaying binary numbers on the LCD can be switched on. The binaries can be displayed in binary format (8 or 16 bits), as hexadecimal (eight or sixteen bits) or as decimal (eight or sixteen bits). If you want to use those routines in your source code, you can switch them on by setting switches (sLcdDecN, sLcdHexN, sLcdBinN with N=8 or N=16).

By calling the subroutines LcdDecN, LcdHexN or LcdBinN those binary values in register rmp (8 bit) resp. ZH:ZL (16 bit) are displayed at the currect position on the LCD (decimal format suppresses leading zeros). All number conversion routines are programmed with the directive ".ifdef" so that those only produce executable code, if the respective switch sLcdDecN, sLcdHexN and sLcdBinN (with N=8 or 16) is defined. Please be aware that some of the switches are set automatically inside the include routine (e.g. setting sLcdHex16 also sets sLcdHex8). Conflicts can be avoided by using the directive “.set” instead of “.equ” for those switches.

Closer details on the registers that are used inside the subroutines are given in the include file. The term “Used” means that the register is used, but its content is saved on the stack and restored when leaving the subroutine.

3.2.2 Example application of the code without Interrupts

The source file tn24_lcd_lin.asm (HTML formatted here) demonstrates the application of the include routines and the optional conversion and display of binary numbers.

The file can be used as template. The therein included file "tn24_lcd_busy_4x20.inc" has the constants adjusted to cLcdLines=4 and cLcdColumns=20. The clock has been set to clock=1000000 at 1 MHz. The code also uses and demonstrates the generation and use of special characters.

Special character display on the LCD The software template also demonstrates the display of special characters on the LCD. Those were designed With the Open-Office-Tool resp. with the M$-Office-Tool. The table, that was generated with those tools, was copied to the source code, undefined characters were removed and the table was transferred to the LCD with the routine LcdChars.

3.2.3 Example application with interrupts

For interrupt-driven programs the template in tn24_lcd_int.asm (HTML formatted here) can be used, Tzhis includes the interrupt vectors of the ATtiny24. For the example program a single-line LCD with eight characters was chosen. The clock frequency of the ATtiny24 was elevated to 8 MHz by clearing the CLKDIV8 fuse. The pictures demonstrate initiation and display of hexadecimal and decimal numbers.

1x8 LCD init 1x8 LCD number display

3.2.4 Required flash storage

The following table lists the storage requirements of the example programs with the include routines and with the diverse options cleared or set. Percentages are for the ATtiny24 with a flash memory size of 1,024 words.

Options selected Without interrupts With interrupts
Words%Words%
None29729.031530.8
Decimal38037.139838.9
Decimal+Hex41440.443242.3
Decimal+Hex+Bin45244.147045.9
Decimal+Hex+Bin+Special characters49047.950849.6


In all cases the remaining space allows for own needs.

To the top of that page 1 Hardware 2 Mounting 3 Software




Praise, error reports, scolding and spam please via the comment page to me. Spammers: please note that behind this is not a dump standard script but I personnally select the entries to be published.

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