Program/Hardware Design

The software and hardware implementation of this project was divided into the following functions:

                         I.      Interface with Seiko Monochrome LCD

·        The Seiko G321D LCD comes equipped with a SED1330F LCD Controller. Graphics and characters are drawn and read by writing data to the LCD on PORTC and then sending commands via PORTA. The functions that were used are WriteCommand() and WriteData() to write and read to and from the ports. These functions were borrowed from David Li and Chirag Fifadra.  We also added a ReadData function to help implement drawing lines.

·        The initialization function for the LCD configured the LCD memory to map the first 1000 bytes of memory to character space and the remaining 8000 bytes to graphics space.

                      II.      Interface to DataFlash via SPI

·         The Atmel AT45D021 DataFlash has 2Mbits of nonvolatile memory. It consists of 1024 pages of Main Memory, with 264bytes per page. I also possess 2, 264byte buffers. It is Serial Peripheral Interface Compatible (SPI).

·        To interface with the DataFlash a message must be sent in the following format: 8bit opcode, 24 bit address, (8 or 32) bits of data. A list of opcodes may be viewed here. The first 5 address bits are reserved for larger density devices, so they were set to zero. The next 10 address bits specify the page address and the remaining 9 bits specify the starting byte address within the page. When we are reading from the DataFlash the message consists of 32 don't care data bits, but consists of 8 valid data bits when writing.

·        These messages are sent using SPI. Since SPI is synchronous, the DataFlash knows when it has successfully received all the bits from the message. Before a command is sent to the DataFlash it status is checked before new information is read or sent from the buffers to the page or vice versa.

·        We used code located in the public domain that contained functions that implemented this interface.

                   III.      Translate Illustrator to Vectors

·        Our friends at Communication and Marketing Services gave us the full campus map in Adobe Illustrator format.  After some careful editing, this was exported to a Scalable Vector Graphics (SVG) file.

·        A borrowed Java program from Ganesh Ramanarayanan allowed us to convert an SVG file to pure vectors. Ganesh’s code took various SVG constructs (rectangles, polygons, polylines, and lines), and converted them into sets of end points for vectors.  SVG also contained data to draw curves and these were approximated by line segments.

·        We copied the generated vectors into a hyperterm window to send the data to the MCU.

·        This function was one of our trickiest to implement. The SVG file contains thousands of lines of XML formatted code. The file when parsed needed to remove line thickness information, so that building lengths and widths would only be a pixel wide. Once this was done the file had to be broken into even smaller files, because when the file was too big the Java program would drop a lot of information. The vectors from all the separated files were then collected and placed in one vector file to be sent over hyperterm. These SVG parsing scripts were written in Perl.

                    IV.      Interface Hyperterm with MCU via RS232 to Send Map Data

·        A UART ISR was needed to get the map data from hyperterm. This data was then sent to the DataFlash via SPI. The format of the data sent was 2 pairs of vectors and a carriage return, and all information separated by commas. The start pixel and end pixel followed by a carriage return (x1, y1, x2, y2, ’\r’). The data set contained an (‘E’) to indicate the end of the map data information.  All of this information was converted to a binary data set, such that 33 vectors were stored in each page of DataFlash.

·        Since we have 2 different UART ISR routines, we program the MCU 2 times: once to store the DataFlash with the map data, and a second to with our complete device code.

·        The baud rate for the UART ISR was set to 4800 bits per sec. This was the fastest rate we could use without the DataFlash dropping vector points.

                       V.      Interface with GPS module via RS232

·        For the microcontroller to receive messages from the GPS module an UART ISR was needed. This service routine begins to store the message in a buffer once a ('\r') is detected because the following information is the start of a new sentence.  

·        With the GPS simulator we are sending new sentences every second, so we use time0 to check the UART buffer for new information every ¼ of a second. 

                    VI.      Drawing the Map on LCD

·        To draw a map that would have the ability to zoom in on a particular portion of the graph, we needed to use vector graphics. To do this we modified the Professor's video generation code. We needed one function that would draw a point and another that would be able to draw lines. The line drawing function takes two pixels, a start and end location, and draws a line connecting the two.

·        The data points read from DataFlash are in the range of (2552x1592). When we are the most zoomed out our window is (2552x1592), the next zoom level has a window of (1276x796), then (638x398), and the most zoomed in has a window of (319x199). Since the window for the most zoomed out is (2552x1592) and the first level of zoom is (1276x796), these values were scaled accordingly, shifted by 3 and 2, respectively, so that they would fit on the 320x200 LCD screen. 

·        When we are zoomed in we jump straight to the page that is holding the beginning data sets for that map location rather than searching through all the pages until we hit the first coordinates to draw. We did this by implementing a look up table. We scaled 2552 by 100, giving us 12 indices, and each index holds the page value that contains the X-pixel coordinate that starts with the index value multiplied by 100. That way if we want to start drawing at X-pixel, 600, we can start reading from that page first rather than searching from page 0 until we find X-pixel 600.

·        Jumping to a specific map page when zooming to speed up device response. When we zoom in, a starting pixel or an ending pixel may longer be on the page. But if we do not have both points that specific the line, the line not be drawn. To fix this problem, we calculated the slope of the line and used this to find the last pixel that would have been shown on the screen and make that pixel the new ending point.

                 VII.      Time0 ISR

·        We used a compare match ISR that was configured to run once every ¼ a second. We set the prescaler value to 1024, OCRS0 to 250, and t0 to 16.

·        This allowed us to check the UART buffer 4 times a sec for new information.

·        This timer was used to for the frequency of the blinking man.

·        Button push detection and debouncing also used this timer.

·        Location, time and date update used this timer as well.

              VIII.      Decode GPS message sentences

·        We know that the data from the sentences are separated by commas. So we parse the information from the UART buffer my counting out the commas in the message. For example we know that the next character after the third comma is the start of the time stamp. These characters are placed into a time stamp array. We know we have reached the end of the time stamp when we get to the next comma. This same analogy was used to parse the date, latitude and longitude values.

                    IX.      User Interface

·        We implemented button pushes that would allow the user to move the map in all directions.

o       Right – Button (0) =  PORTD.2

o       Down – Button (1) =  PORTD.3

o       Up – Button (2) =  PORTD.4

o       Left – Button (3) =  PORTD.5

·        The user has the option to zoom into the map.

o       Zoom – Button (5) =  PORTD.6

·        The user is allowed to look ahead without their position being necessarily present on that location of the map. To find your location after looking around there is a button that allows the screen to center around your location.

o       Center – Button (4) =  PORTD.7