473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Drawing 2D Graphics on LCD Screen

Hello, everyone.
Today I will teach you to draw 2D graphics on DWIN screen by Keil c51 development.

First, I will introduce the basic touch control in the development guide of DGUS.
Note that a basic graphics display control can only draw one type of graphics.
Next, I'll describe the data storage format of the basic graphics control at vp.
The first word is CMD. It specifies what graphic the control will display. The drawing instructions are different for different graphics.
The second word specifies the number of graphics displayed by a control.
The third word is the shape's data package, such as the coordinates of the start point, the end point and the color.

Next, let's look at how many kinds of shapes CMD supports.
You can see that 0x0001 refers to a point; 0x0002 refers to a line;
0x0003 refers to a rectangle; and 0x0004 refers to a filled rectangle.
You can refer to the DGUS development guide for more details.

This part describes the format of the package.
That is, the color and the coordinates of the graphics. And if you set more than one graphic, you can write them down in order.

Next I'll introduce the properties of the basic graphic control.
The most important one is this vp, which can be set as from 0x1000 to 0xFFFF. Other properties basically do not need to be set.

Next, create a new folder named "Code".
Inside this folder, create two new folders named "C51" and "GUI".
Put the background image into the GUI folder.
In this tutorial, I use the model of EKT070B, its resolution is 800 * 600. Therefore the background image resolution is also 800 * 600.
Open DGUS, click NEW, set the saving path to the GUI folder we just created, and set the resolution to the same as the screen.

Import the image, click ICL TOOL, Select the image, click Generate ICL, name it 32.
Click on the Basic graphic control and resize the it.
Set the VP of this control to 2000.
Copy this control and set the vp of the second control to 3000.

Click save and generate.
Open the DWIN_SET folder, copy the configuration files to the SD card DWIN_SET folder.
Insert the SD card, power the screen on.
After the burning is finished, pull out the SD card and re-power the screen.
We can see the project has been download to the screen successfully.

Here we will use the code template.
First we wrap a function that draws 2D graphics under the file sys.c.
Make the function accept a formal parameter, so that we can draw different graphics by entering data.
Next part is function declaration.

Then define the graphics, I will demonstrate line and filling rectangle.
Open the DGUS development guide, and you can see that the CMD value of the line is 0x0002.
Similarly, the CMD value of the filling rectangle is 0x0004.

Next, encapsulate the structure data package.
Let's encapsulate the data of the line.
Since the DWIN screen is in words, I will define the data as u16.
First encapsulate the vp , which is used to qualify which basic graphics control the data is transferred to.
Then encapsulate the CDM, which is the shape type.
Then encapsulate the shape number.
Next part is the data package, including the color, the
xy coordinate of startpoint 0
xy coordinate of endpoint 1
Then encapsulate an end flag that marks the end of the encapsulation.

This above is the data structure of the line.
Copied them, and then modified on top of that to a filling rectangular data structure.
Basically it's all pretty much the same, according to the development guide, only the position of the Color data needs to be back-shifted.

Next, let's implement this function.
First define the shape number, here I set it to 1.
Then define the end flag as 0xFF00.
Then use switch to select the second element to judge the shape.
Divided into the case of drawing a line and a filling rectangle.
Let's fill the data first. Set the shape number to 1.
Then write the end flag.
We want to write the data at the vp, the value of which we have already given before.
Then the data written is the content after the vp. The length of the data is indeterminate and is represented here by a variable, using the length of the structure - 2, since the length of the vp address is 2 words.
The case of filling rectangle is similar, you just need to modify the corresponding place.

Then let's test the function.
We're going to draw a line and a filling rectangle.

Then just copy the structure and write the vp as it was set in our project.
The shape is set to line.
Data transfer is not necessary for the shape number, because the data is already set to 1 in the function.
Here we set the color to red.
Open the project and you can refer to the coordinates of the start point and the end point of the line.
After the structure data is written, we can call it directly.

The structure data for filling rectangle is similar, just move back the color data and then set the corresponding vp address and points coordinates of the rectangle.

Now we have completed the code section, click build.

Open download for 8051, download the generated hex file, and you can see the graphics displayed on the screen.
Aug 15 '22 #1
0 2929

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
1
by: Paul Hoad | last post by:
I'm trying to use MeasureString() to determine the length in pixels of a string However to do I need a System.Drawing.Graphics object to do this I need to create a System.Drawing.Graphics...
3
by: Jay | last post by:
Is there a something similar to initgraph in C#, or do I have to download the directx library? All I want to do is bring up a graphics screen and be able to recognize the mouse and color some...
2
by: Hai Ly Hoang | last post by:
Hi, I want to draw directly on to the screen. I think i should get the Graphics object of the screen. It's easy to get do it in C++ (by GetWindowDC(NULL)). But how to do that in C# ? Thanks
1
by: DBC User | last post by:
Hi Sharpies, This is a very basic question. I am using .Net IDE 2003 and System.Drawing.dll (1.1.4322). I wrote a simple program like this (ommitting the commons) using System.Drawing; .....
4
by: Peter Oliphant | last post by:
There doesn't seem to be any documentation on how to create and/or use an instance of System::Drawing::Graphics. On-line MSDN talks about this class, and says: " The Graphics class provides...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To...
3
by: Eduard Witteveen | last post by:
Hello list, I have code the draw MyDrawingObject information on a System.Drawing.Graphics object. The code is more/less the following: I now want to rotate / mirror the object i draw. I've...
7
by: Galen Somerville | last post by:
I have been converting a VB6 project to VB2005 for lo these many months. Most of my problems have been solved thanks to people like WanYuan Wang and Mattias Sjogren. But now the Graphics aspect is...
11
by: cty0000 | last post by:
I have some quiestion... I want to draw line,point,rectangles and etc... on the from So I code like this.. public update() { g = this.CreateGraphics(); g.FillRectangle(Brushes.White, x1,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.