Microcontroller Code
 
 

 Our microcontroller code receives the coordinates of the user’s touch and then sends this data to FPGA 1, using our simplified Xbus interface.  Touch screen coordinates are sent to our microcontroller serially, using the RS-232 protocol at a baud rate of 9600.
To receive the touch screen data, the serial port control register (SCON) on our microcontroller is set to mode 1, which allows for asynchronous transfer of 10 bits (1 start, 8 data, 1 stop).  Timer 1, the timer that controls the frequency of serial interrupts, is set to operate in 8-bit auto-reload mode.  When the timer goes off, we take the byte that we’ve received and store it in a global queue so that we can process the byte later in our program.  To generate a baud rate of 9600 with a 24 MHz clock oscillator, Timer 1 is set to automatically reload with a value of 243.
In the main body of our microcontroller code, there is an infinite loop that grabs a character (a byte) from the global queue and then calls the function getTouch() with this character.  In the getTouch() function, our microcontroller checks to see if the byte it received is a header byte, either 0xC0 or 0xC2.  If the byte is a header byte, then getTouch() grabs the x- and y-coordinates the touch screen sent the microcontroller by grabbing the next two, three, or four bytes in accordance to the scheme described in the subsection titled “Touch Screen Interface.”
After grabbing the necessary bytes that define the location of the user’s touch, getTouch() does two things:

1) getTouch() takes the low order byte of touch screen data (for both the x and y coordinates), shifts these bytes left 1 bit, effectively multiplying these bytes by a factor of two, and then, if the x- and/or y-coordinate requires more than one byte, getTouch() concatenates these shifted low order bytes with the corresponding high order byte.  If the x- and or y-coordinate only require one byte, the shifted low order byte is concatenated with a leading 0x00.

2) getTouch() then takes these numbers, scales them down by a factor of four (i.e. these coordinates get shifted right 2 bits), and then sends these numbers (represented as two bytes each) as x- and y-coordinates to FPGA 1 via our simplified Xbus interface

The getTouch() function performs step (1) above because for some unknown reason, we were not receiving the MSB of the low order byte.  Not receiving the MSB of the low order byte essentially prevented us from touching parts of our touch screen.  This behavior was seen as we tried to drag a stylus across the touch screen.  As we dragged the stylus across the touch screen, we noticed regions our cursor (used to indicate where we were touching on the touch screen) would “skip” over.  Shifting the bits in the low order byte resolved this problem.
The getTouch() function performs step (2) because the resolution of the touch screen is many times greater than the resolution of the VGA monitor (approximately 1900 x 1900 on the touch screen to 512 x 480 on our VGA monitor).  Our microcontroller scales the touch screen coordinates down by a factor of four before sending this data to FPGA 1.  Doing this allows FPGA 1 to tell FPGA 2 where to draw the crosshairs indicating the location of the user’s touch and the location of where the air hose is currently targeting.
 
 
 

Back to Report