Showing posts with label avr-lcd. Show all posts
Showing posts with label avr-lcd. Show all posts

Sunday, January 5, 2014

Update: AVR-LCD Assembly Project

Well, my holiday break has been mostly uneventful, besides the fact that I received a Raspberry Pi (Model A) as a gift, so I'm looking forward to getting into that soon. In the meantime, though, I've finally had the chance to dig back into the AVR-LCD assembly project.
   After a couple weeks of on-and-off work, I'm pretty much at exactly the same place. Except that I've managed to switch the compiler to avr-gcc. Exciting! For a while, the conversion broke the code in ways that confounded me until I stopped being dumb and actually took a look at the listing produced by the compiler, which converts the register defines into plain hexadecimal. Apparently, avr-gcc doesn't do you the favor of subtracting the IO-memory-space-offset from special function register addresses used with IO-specific instructions while the Atmel compiler does. When using IN, OUT, SBI, CBI, etc., the _SFR_IO_ADDR() macro can be used to subtract the offset. Once that was inserted to all of the appropriate places, the program worked properly. Hello again, world!
   The online avr-libc manual became a valuable resource for me during the conversion by providing code samples and a Makefile template. I also took some time to play around with Simulavr. Since that simulator only supports a limited number of AVR devices (not including the ATMega328P), I needed to make my assembly compatible with the ATMega328. Fortunately, all this required was replacing the CALL instructions with RCALL. With the help of this page, I was then able to put together a command to run the simulator and output a VCD file to verify the functionality. The command is recorded in a script that is up on the project's GitHub page (avr-gcc branch) along with the updated assembly source and Makefile.

Sunday, September 22, 2013

AVR-LCD Assembly Project

So much for the two-week posting schedule. Let's see if we can fix that.
  I was actually holding off on another post until I had something of my own up and running. Well, it turns out that hardware is hard, so this seemingly simple project that I started at the beginning of the summer didn't reach a notable milestone until today. The milestone in question is one that is familiar to any programmer.
  The breadboard pictured above contains an Atmel AVR ATMega328P microcontroller (top) and a NewHaven Display NHD‐0216K1Z‐FL‐YBW LCD module (bottom). The goal of this project was to program the AVR with an assembly program to control the LCD module to print "Hello, World!" to the display. To the right of the AVR on the breadboard is a 7-segment LED display and BCD-converter chip that I started playing around with after being stymied by the LCD module for a few weeks.
   It's taken me a ridiculously long time to reach such a simple goal, but I've learned quite a bit about the AVR's internals, assembly syntax, and the Atmel Studio development environment in the process. One byproduct of this work is a Python script I wrote to convert output from Atmel Studio's built-in simulator to VCD format so data nearly any internal register can be collected and plotted as a digital waveform.
   The assembly code, simulation script, and schematic files for the test-bench circuit in the photo is available at this GitHub page. The included README contains some tips for setting up the development environment in Windows, such as using the simulator, converting the output, and programming the AVR with a USBTinyISP.
   My next steps will be to port this project to AVR-GCC, as Linux is my preferred development environment. SimulAVR seems like a promising replacement for the simulator in Atmel Studio, which was difficult to interface with external signals. Afterwards, I'll either work on reorganizing the code into a library that can be included with future assembly projects or add more code so that the functions can be exposed via a bus interface, so that a single AVR can be addressed by several other modules on a network to print out diagnostic data. I get excited about the possibilities just typing about it. I'm so easily amused.
   Oh, and another program to display a countdown on the 7-segment display is available here.