HAPSIM - Helmi's AVR Periphery Simulator V1.01
LCD (HD44780U), LEDs and Push-Buttons Simulator Extension for the AVR Simulator of Atmel's AVR Studio 4, Version 4.09 and 4.10
Table of content:
LCD features
How to use HAPSIM - Quickstart
Using LCDTest on 'real' Hardware
Using HAPSIM with other targets than ATMega128
Known Issues and restrictions
Thanks and Tribute
- works with Atmel AVR Studio 4, Version 4.09 and 4.10.
- simultaniously simulates one or more of each of the following components:
   - HD44780U compatible LC-Display with up to 24 x 2 characters.
   - Pushbuttons connected to Input Port Pins.
   - LEDs connected to Output Port Pins.
- easy configuration of the components.
LCD features:
- acts like a real HD44780U.
- 1 or 2 Display lines.
- 8 to 24 characters per line.
- 4bit AND 8bit I/O mode support.
- supports the complete original character set (5 x 8 dot)
   including all the 'weird' characters above 0x80 ;-)
- support for 8 user defined characters.
- supports blinking cursor, display shifting, cursor movement.
- selectable background color and display size (zoom factor).
How to use HAPSIM - Quickstart:
- Download and unzip Hapsim and LCDTest.
- Build the LCDTest project by executing 'Buildcoff.bat' (maybe edit the 'winavr' path first).
- Start AVR Studio 4
- In the Project Wizard select the 'lcdtest.cof' file and press 'next>>'
- Select Debug Platform: 'AVR Simulator' and Device: 'ATmega128'.
- Click 'Finish'.
- Start 'hapsim.exe'. It automatically detects the running AVR Studio and connects to it.
- Verify the connection to AVR Studio by clicking the Options menu:
   The 'AVRStudioHook' Option must be checked.
- An LCD1 Window with a 16 x 2 LCD appears per default.
- Now open the 'LCDTest.cfg' file in hapsim.
   An LCD, a Button window and a LEDs window appear.
   Each of them can be configurated by selecting it and then clicking the appropriate
   Settings button or select '...Settings' from the 'Options' menu.
   But that's not necessary now because they are already pre-configured for the LCDTest program.
- Hit the Run (F5) button in AVRStudio, sit back and watch as the LCD shows the welcome text.
   It's quite slow, I know, but that's the simulation speed of the AVR Simulator with a little
   slowdown by hapsim, of course...
- When the text display has finished, the first green LED in the LEDs window, named 'mode0' lights up.
   For explanation: the 4 green LEDs show the current mode of the Test program, I'll explain later.
   The red LEDs below show the state of the 4 buttons of the buttons window.
- First, let's test the cursor modes of the LCD:
   Press the first of the 4 buttons, the 'Cursor' button and hold it down. As you see the
   'Button1' LED lights up!
   Release the button. The underlined cursor appears at the current cursor position of the LCD which
   should be at the 'T' of "Test" if you have not pushed any other buttons yet.
   Press and release the 'Cursor' button once more and you get the blinking cursor with underline.
   Next time you get the blinking cursor without underline. Once more and the cursor disappears.
   Select a (visible) cursor of your choice for the following steps.
- Test mode 0: Press and release - slowly - the 'Right' button. On every edge of the button signal
   one (increasing) character code is written to the display while the cursor moves to the right.
   Note that you have to do it slowly, because the buttons are only polled by the AVR and the
   character display generates a little delay. When you click too quick, the AVR will loose some
   'button events'.
   When the cursor reaches the right edge, the display shifts to the left in order to keep the cursor
   visible at all time.
   With the 'Left' button the (still increasing) character codes are written from right to left and
   the display shifts to the right when the cursor reaches the left edge.
- Now switch to test mode 1 by pressing the 'Mode' button. (what a surprise ;-)
   The 2nd green LED 'mode1' lights up.
- Test mode 1: In this mode the cursor can be moved with the 'Left' and 'Right' button without writing
   characters and without shifting the display. So you can also move the cursor out of the visible
   display area.
- Press the 'Mode' button once more and you get to test mode 2: Now the display is shifted left and right
   without moving the cursor.
- Finally switch to test mode 3: This is a test for the user defined characters, the "CGRAM Test" which
   is displayed in the 2nd line. The first display line shows the character codes 0 to 15 which contains
   the 8 user defined characters twice; character 0-7 are the same as 8-15.
   At the first appearance you should see there random bit patterns (= the current content of the CGRAM)
   except for the Copyright (c) Symbol which was defined during display of the intro text.
   With the 'Left' and 'Right' button you can now write (increasing) bit patterns to increasing (right)
   or decreasing (left) CGRAM addresses and watch them on the display.
- That's all! Pressing the 'Mode' button once more leads to the mode0 again...
Using LCDTest on 'real' Hardware:
Note: If you want to run this LCDTest program on a 'real' AVR you have to remove the definition of
     FASTSIM in the first line of 'lcd.c'.
     This #define shortens out the delay() function and therefore speeds up the simulation!
Using HAPSIM with other targets than ATMega128:
HAPSIM internally uses the port names and port addresses of the ATMega128, see table below.
It can be used with any other AVR Target as long as the same port addresses are used!
Of course you can only use existing ports; for example PORTA to PORTD on a ATMega16!
HAPSIM does NOT check the correct port usage!
Port-Name Address Port-Name Address
PORTA 0x1b PINA 0x19
PORTB 0x18 PINB 0x16
PORTC 0x15 PINC 0x13
PORTD 0x12 PIND 0x10
PORTE 0x03 PINE 0x01
PORTF 0x42 PINF 0x00
PORTG 0x45 PING 0x43
Table of AVR Port addresses used by HAPSIM
Known Issues and restrictions:
- no timing conditions are checked or considered.
   e.g. the LCD even works if you don't wait for the busy bit to clear.
- DDR (data direction) programming of the AVR ports are neither checked nor considered.
- avoid double connections, e.g. connecting the same port pin to the enable pin of the LCD
   and to a LED will cause problems.
- don't change the port settings (of LCD, Buttons or LEDs) during a running Debug session.
   Hit the Break Button in the AVR Studio first! Anyway you don't have to stop the debugger completely.
- no memory mapped IO support for the LCD.
- although the LCD simulator should support 8bit I/O mode, I haven't really tested this!
   (The LCD library by Peter Fleury I used for the LCD Test program only supports 4bit I/O mode).
Thanks and Tribute to:
Peter Fleury for his LCD library, used by the LCDTest program, http://jump.to/fleury
Iuri Apollonio for the 'CoolMenu' Support, http://www.codeguru.com/Cpp/controls/menu/bitmappedmenus/article.php/c177/
Maurizio Pisano for the MessageBoxTimeout API, http://www.codeproject.com/cpp/MessageBoxTimeout.asp
hapsim101.zip, 28.8.2004
34.984 bytes
LCDTest program for AVR
lcdtest.zip, 23.8.2004
12.743 bytes
V1.01 - 28.8.2004
Update for AVR Studio 4.10.
V1.0 - 23.8.2004
First Release!
Please e-mail any suggestions, complaints and other feedback to

Helmut Wallner, 28.8.2004