CODE


All of the drivers and other code associated with this project were written in C and compiled for the AVR using version 3.0 of AVR-gcc. You can download a .zip file of the code here

Additional headers that are required include: interrupt.h, io8515.h, iomacros.h, pgmspace.h, and sig-avr.h. These should be included with AVR-gcc.

Difficulties

Lack of memory turned out to be a major hurdle. I initially chose the 8515 without considering the limited memory. I probably should have chosen a processor with more memory like the mega163 but didn't realize this until I was too far along.

Once I had the individual pieces (keyboard, memory, LCD, etc) working by themselves it was time for integration. The LCD came up OK, but everytime I typed on the keyboard the processor would reset. I tried to insert some debug strings into the program that would print messages to the LCD at key points but then the compiler complained that I was using up all of the data memory.

I have two large data structures that needed to be put into the 512 bytes of RAM available on the 8515. The first is a 3 x 50 array that is used as a lookup table to convert keyboard scancodes to upper and lower case ASCII. The second is a screen buffer that I originally sized to hold 16 lines of 21 characters. This already adds up to 486 bytes. Throw in a random assortment of other variables and a stack and I had a big problem.

The first part of the solution was to move the scancode to ASCII translation table to program memory. It only takes a few cycles to access but uses no RAM space. Unfortunately I could not do the same for the screen buffer because it also needed to be written. I made a design compromise and reduced the screen buffer to 12 lines. These two steps restored 234 bytes of RAM.

The third step was to reduce the nesting of function calls. Originally I wrote my code with lots of functions and reuse. For example I had a function WriteBufferToLCD() that would go through each byte of the buffer and call WriteCharToLCD(). I also had functions like LCDIsBusy() that would return a number indicating if the LCD was busy. While I've been taught that this is good programming practice it also makes the stack unnecessarily large. Sacrificing larger code size (I have plenty of program memory) I cut and pasted many functions and manually inlined them.





Written by Mike Lombardo. 12/12/01