Path:
Home =>
AVR-EN =>
Applications => ATtiny24 experimental board with LCD
Diese Seite in Deutsch:
 |
Applications of
AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega
Experimental board with an ATtiny24/44/84 and an LCD
|
Experimental board with an ATtiny24/44/84 and a LCD
This page as PDF (19 pages, 1.1 MB)
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:
- An ATtiny24/44/84 with an attached standard LCD and base routines in assembler make
the rest of the development a simple matter.
- Based on your needs up to four I/O pins can be used for the following purposes:
- as normal in- or out-put pins, or
- as AD converter input pins, or
- as analog comparators, or
- as PCINT inputs to generate PCINT interrupts, or
- as counter input pin for the 8 bit timer/counter TC0.
- The small 40-by-50 mm PCB can be connected with a 6 pin flat ribbon cable with
external parts on e.g. a breadboard. The power supply of 5.0 or 3.3 V (depending
from the LCD's needs) can be provided via the cable or can be attached to two pins.
- As LCD all types with 1, 2 or four lines by 8, 16, 20 or 24 characters can be
used and can be configured by changing software constants.
- The LCD include routines provide ready-to-use software for initiation, for
displaying text and binary numbers, either as 8- or 16-bit binary, in hexadecimal
or in decimal format. The two routines work with a clock frequency of up to 20
(lcd.inc) resp. 8 MHz (tn24_lcd_busy.inc).
The LCD routines, that are described here, have been
improved and a better suited version is available
here. These provide a universally applicable
routine that can be easily adjusted to the hardware described on this page.
Adjusting the new routine is decribed below.
0 Overview
- Hardware
- Mounting
- Software
1.1 Scheme of the board
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
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:
- 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,
- 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,
- here a
frequency counter for digital and small-amplitude analog signals and for
measuring inductivities is decribed,
- 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.
2.1 PCB
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
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.
For accessing the LCD two different versions of the software
are available:
- A universal version, that handles all different
connections of LCDs, including 8 bit versions, and
- 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.
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
- LCD access with 8- or 4-bit data bus (define with
the constants LcdBits=8 or LcdBits=4),
- when using a 4 bit data bus select whether the bus
is connected to the upper or lower nibble of the port
(with the constant Lcd4High=0 for the lower
or Lcd4High=1 for the upper nibble),
- automatic adaption to clock frequencies above
1 MHz (define the constant clock in Hz),
- access either with waiting for the LCD's busy flag
or with wait cycles (define the constant LcdWait=0
for busy or LcdWait=1 for wait cycles),
- the control pins of the LCD {E, RS, RW} can be tied
to whatever port and portpins and do not have be within
the same port (define those with the constants
pLcdCnnO, pLcdCnnD, bLcdCnnO and
bLcdCnnD, with nn={E, RS, RW}),
- can be adapted to LCD sizes of 1x{8, 16, 20, 24}
or 2x{16, 20, 24} or 4x{16, 20, 24} (define this with
the constants LcdLines={1, 2, 4} and
LcdColumns={8, 16, 20, 24}).
- all constants that are required for the selected
operating mode are checked by the assembler if those
are defined and correct (simplified debugging),
- for the list of constants and for the design of
text masks of all above mentioned LCD sizes templates
are given in the include file that can be copy-and-pasted
to the source code, and after editing, semicolons can be
removed to activate those lines,
- optional conversion and display of binary numbers as
- decimals with two, three or five digits (define
the constant LcdDecimal),
- hexa decimals with two or four digits (define the
constant LcdHex).
- protecting and restoring of registers used (except
R16 and ZH:ZL) by PUSH and POP,
- Time and code size optimized by extensive use of
conditional assembling (.IF and .IFDEF
directives).
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.
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.
By including the lcd.inc the following memory sizes are
occupied:
Version | Size Words | Accumulated |
Minimal version (1 MHz, 8 bit, wait mode, w/o Dec/Hex) |
138 | - |
Wait ==> Busy | +9 | 147 |
1 MHz ==> 20 MHz | +20 | 158 |
8 bit ==> 4 bit | +44 | 182 |
LcdDecimal | +86 | 224 |
LcdHex | +14 | 152 |
Maximum version (20 MHz, 4 bit, busy mode,
decimal and hex conversion) |
+197 | 335 |
The version adapted to tn24_lcd with the above configuration
requires 200 words.
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:
- LcdInit: The I/O pins of the LCD and the LCD is
initiated. Application is demonstrated here with a 4 line by
20 characters per line LCD. A start message is shown (left
picture),
and, following an adjustable delay time (constant cLcdDelay
in the main source code in multiples of 250 ms) an output mask
is displayed (right picture, in German).
- LcdText, LcdTextC: A text in a flash table, for
which the doubled address is given in the register pair ZH:ZL,
is displayed from line 1 on (LcdText) or starting at the current
LCD address (LcdTextC) until the selected line count (1, 2 or 4)
is exceeded or an end marker is reached. The control characters
0x0D (Carriage return plus linefeed) and 0xFE (End of text) control
the output). As you always have to adjust the text in the .db
directive to hold an even number of characters you can add 0xFF as
ignored dummy character. Output ends on exceeding the number of
lines or triggered by 0xFE.
- LcdSram: The text im SRAM, for which the address is given
in register pair XH:XL, with the number of characters to be
displayed is handed over in register rmp (R16), is displayed at the
LCD position handed over in register pair ZH:ZL (ZH: Line 0..3, ZL:
Column 0..cLcdColumns-1).
- LcdLine, LcdLine1, LcdLine2, LcdLine3,
LcdLine4: LcdLine adjusts the LCD's position to the beginning
of the line that is handed over in register rmp (R16, 0..cLcdLines-1).
When calling LcdLine1, LcdLine2, ..., the same happens without
parameter handing-over.
- LcdPos: Adjusts the position of the LCD to the line given in
register ZH (0..cLcdLines-1) and the column in register ZL
(0..cLcdColumns-1).
- LcdChar: The ASCII character (0x20..0x7F) or the special
character (0x00..0x07) given in register rmp (R16) is displayed on
LCD at the current LCD position.
- LcdCtrl: The control byte in register rmp (R16) is written
to the control register of the LCD.
- LcdChars: The table in flash memory, on which the doubled
address in ZH:ZL points, and which holds a table with encoded special
characters is written to the character generator in the LCD. Up to
eight special characters (0..7) can be defined.
Prior to using the routines the following has to be assured:
- The main source code has to init the stack (in ATtiny24 and ATtiny44
SPL, in ATtiny84 SPH and SPL), because calling and diverse push and
pops inside the routines would otherwise fail).
- In the main source code the constant clock should be set to the
correct controller clock frequency in Hz (up to 8000000 Hz), because the
I/O interface to the LCD depends from that (specified duration of the
LCD Enable pulse).
- In the main source code set the constant cLcdDly to the desired delay
between the opening screen and the output mask. Otherwise assembling
fails with an error message.
- When the program is interrupt-driven make sure that initiating the
LCD happens prior to interrupt enabling. The lengthy delays during LCD
init would conflict with interrupt handling if the interrupt sets
handling flags to be reacted on.
- In the main source code define the register rmp as R16 (or above).
- Make sure that the temporarily used registers R0, R1, R2 and ZH:ZL
(plus XH:XL when using text display from SRAM) are not used inside
interrupt service routines.
3.2.1 Number conversion and display routines
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.
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.
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 | % |
None | 297 | 29.0 | 315 | 30.8 |
Decimal | 380 | 37.1 | 398 | 38.9 |
Decimal+Hex | 414 | 40.4 | 432 | 42.3 |
Decimal+Hex+Bin | 452 | 44.1 | 470 | 45.9 |
Decimal+Hex+Bin+Special characters | 490 | 47.9 | 508 | 49.6 |
In all cases the remaining space allows for own needs.
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