1 Lab 3: LCD Display Objective In this lab, you will learn how to control the MTDS Pmod display connected to our Zybo development board. We’ll be using this display throughout the rest of...

To use C code get what it want


1 Lab 3: LCD Display Objective In this lab, you will learn how to control the MTDS Pmod display connected to our Zybo development board. We’ll be using this display throughout the rest of the semester, including for the final project, so it’s important that we start to learn how to interface to the display now. We’ll start by drawing a simple shape in the center of the screen. Your job will be to then move the shape around the screen so that it bounces off the edges, similar to a simple screensaver. Deliverables Lab start: Week of 3/13. Lab Assignment: • Square moving on the screen, bouncing off the edges of the display, colors changing with the pushbutton. Demo due: Week of 3/27 by the end of your lab session (2-week lab) Lab due: Friday 4/7, 11:59PM – submit a Zip file with your code and design document. Lab Contents Objective ....................................................................................................................................................... 1 Deliverables................................................................................................................................................... 1 Part A: LCD Colors ......................................................................................................................................... 2 Part B: Drawing on the LCD Display .............................................................................................................. 3 Part C: Moving the shape .............................................................................................................................. 6 Part D: Lab Assignment: Screen Saver .......................................................................................................... 6 Part E: Submission ......................................................................................................................................... 6 Part F: Extra Credit ........................................................................................................................................ 7 2 Part A: LCD Colors The Pmod MTDS (Multi Touch Display System) has a 320x240 pixel Graphic LCD display. We can interface to the display using the MyDisp.h library, which is provided by Xilinx. Let’s open up the provided library files to understand some of the relevant defines and functions. Create a new Vitis project called Lab3 using the same EE379S22_BSP platform we used in Labs 0 and 2. Refer to previous lab documentation if you forgot how to configure the project. Include the provided lab3.cc file in your project under the src folder as we did in Lab 0 and Lab 2. The MYDISP wrapper class implements the interface to the display and provides an API for us to use to set colors and draw shapes on the screen. Let’s first start off by taking a look at the default colors that are already defined for us. Hold the Control key, and then click on the clrWhite constant that is being passed as the argument to the clearDisplay function (You may have to build the project first): By holding Control and clicking on any function or constant, we will be taken to the file that defines that item. First, we see colors defined as shown: 3 In computer graphics, colors are often represented in terms of the primary additive (light) colors red, green, and blue. The 24-bit color scheme used by the MTDS LCD display uses 8 bits for red, 8 bits for green, and 8 bits for blue (The colors are actually 32 bit values but the MSB is just 0x00). To make your own color, Google HTML Color Picker and find the 24-bit color you want to use. For example, we find that pink is 0xFFC0CB, which means the color pink is mostly made of red, with lesser, similar intensities of green and blue. We could add this color to our own Lab3.cc file to use (don’t modify the MtdsDefs.h file): Feel free to try out defining your favorite colors and using them in the rest of the lab! Part B: Drawing on the LCD Display Let’s take a look at the different drawing functions in MyDisp.h. To find them, Control+Click on the clearDisplay function in Lab3.cc and pick the first option. We’re going to make use of the following functions: Function Parameters Description begin none Called to set up the display setPixel int x, int y, uint32_t clr Set the pixel at (x,y) to the provided color. setForeground uint32_t clr Set the foreground color, which will be the color of shapes drawn by the shape drawing functions. 4 drawRectangle bool fill, int x1, int y1, int x2, int y2 Draw a rectangle with upper left corner at (x1, y1), bottom right corner at (x2, y2). Rectangle will be filled in if the first argument is true. The color of the rectangle will be the Foreground color. clearDisplay uint32_t color Clear the screen and set the background color. drawText char *txt, int x, int y Draw string on the screen starting at the given (x,y) position A few things to note: • The display is 240x320 px. The coordinate system is assuming portrait orientation with the (0, 0) point being the top left corner with the Pmod header on the bottom (You should orient the display like this so you don’t confuse yourself!) • The bool type consists of two possible literal values true and false and is a C++ type. • The uint32_t type is an unsigned integer guaranteed to consist of 32 bits. Remember that the default int type may be a different size based on the architecture we’re using. Let’s use these functions to draw a square centered on the screen with a side length of 50 pixels. Rather than using magic numbers in our code, let’s set ourselves up for later by defining integer variables for the centerpoint of the square, called (cx, cy). Drawing the square is simple – First, call the setForeground function to set the color you want your square to be. Next, calculate the center point of the display and initialize the cx, cy, and w variables appropriately. Next, calculate the coordinates of the upper left and bottom right corners of the square in terms of cx, cy, and w. Finally, call the drawRectangle function. Draw this out on paper first! Nifty trick: While typing in Vitis (or any Eclipse-based IDE) you can press Control + Space to auto- complete your code. For example, try typing “display.” and then press Control + Space. You should get a list of all the functions available for you! 5 Connect the MTDS display to the JC Pmod header on the Zybo board. Build your project and program to the board as usual. Make sure you see the square centered on the screen as you expect. Do NOT move on to the next step until you get this working and you fully understand it! 6 Part C: Moving the shape Let’s move our square around the screen! First, let’s create our infinite while(true) loop. Then, let’s try starting the square in the center of the screen, and moving it down to the bottom by changing cy until it hits the bottom of the screen and stops. I’ve included these steps as comments below • Do you understand the line of code if (cy < 320-w/2)… ? • remember that we need some delay in each iteration of our infinite loop. otherwise, the square will move too quickly! make sure you can get your square to move to the bottom of the screen and then stop. make sure you fully understand this behavior before moving on to the lab assignment! part d: lab assignment: screen saver your assignment for the lab is to implement a simple screen saver. the square should start off moving in some direction, and bounce off the four corners of the display. we will also use the btn0 pushbutton to change the color of the square, cycling through at least 4 colors. the idea is to use velocity variables in the x and y direction. for example: the idea is that every time we go through the loop, we 320-w/2)…="" •="" remember="" that="" we="" need="" some="" delay="" in="" each="" iteration="" of="" our="" infinite="" loop.="" otherwise,="" the="" square="" will="" move="" too="" quickly!="" make="" sure="" you="" can="" get="" your="" square="" to="" move="" to="" the="" bottom="" of="" the="" screen="" and="" then="" stop.="" make="" sure="" you="" fully="" understand="" this="" behavior="" before="" moving="" on="" to="" the="" lab="" assignment!="" part="" d:="" lab="" assignment:="" screen="" saver="" your="" assignment="" for="" the="" lab="" is="" to="" implement="" a="" simple="" screen="" saver.="" the="" square="" should="" start="" off="" moving="" in="" some="" direction,="" and="" bounce="" off="" the="" four="" corners="" of="" the="" display.="" we="" will="" also="" use="" the="" btn0="" pushbutton="" to="" change="" the="" color="" of="" the="" square,="" cycling="" through="" at="" least="" 4="" colors.="" the="" idea="" is="" to="" use="" velocity="" variables="" in="" the="" x="" and="" y="" direction.="" for="" example:="" the="" idea="" is="" that="" every="" time="" we="" go="" through="" the="" loop,="">
Mar 29, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here