Simple signal drawing on graphical LCD routines

During spare time I have been playing with graphical LCD. This time I decided to display simple signals that are stored in microcontroller memory. The idea was to read signal values from look-up table and display waveform on Graphical LCD. To make things more interesting I divided LCD screen in to smaller four screens so I could activate them separately and draw signals in them.

Graphical LCD is the same old HQM1286404 with KS0108 controller. I have used Proteus simulator 128×64 graphical LCD(LGM12641BS1R) which is based on KS0108. How to implement and connect LCD there was a blog post (Simulate KS0108 graphical LCD with Proteus simulator

)about it. I am just going to show main program routine.

As I mentioned I have split 128×64 in to four smaller screens like this:

so I get four smaller 32x63 screens where I can put different information. To do this you can think of many ways of implementation. I have chosen simple solution. I have created a simple structure which holds current active window position and size:

 

//structure of window coordinates

struct window{

uint8_t xmin;

uint8_t ymin;

uint8_t xmax;

uint8_t ymax;

} win;

 

And I wrote a function which changes the active window.

 

void setWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)

{

//clear previous window frame

ks0108DrawRect(win.xmin, win.ymin, win.xmax-win.xmin, win.ymax-win.ymin, WHITE);

//set new window position and size

win.xmin=x0;

win.ymin=y0;

win.xmax=x1;

win.ymax=y1;

//draw frame on active window

ks0108DrawRect(win.xmin, win.ymin, win.xmax-win.xmin, win.ymax-win.ymin, BLACK);

}

 

It just assigns new coordinates of new window. Also it draws a rectangle around active window. When changing window position to new, old rectangle is deleted. So this makes pretty cool effect.

After window setting is done, it is time to write signal drawing function which takes values from pointed look-up table and draws it on LCD active window. Function is really simple, the only thing you have to take care is correct proportions:

 

void drawSignal(uint8_t X0, uint8_t Y0, uint8_t A, uint8_t R,const uint8_t *FlashLoc)

{

uint8_t tval, prx=X0, pry=Y0, x=X0, y, i;

//read first point value

tval=pgm_read_byte(&FlashLoc[0]);

//calculate y position

y=(int)((float)(tval-(win.xmax+1))/256*A)+Y0;

//set dot in calculated position

ks0108SetDot(x++, y, BLACK);

//repeat until end of frame reached

for(i=R; ((i<=(255-R))&&(x<=win.xmax)); i+=R)

{

tval=pgm_read_byte(&FlashLoc[i]);

y=(int)((float)(tval-(win.xmax+1))/256*A)+Y0;

//draw line

ks0108DrawLine(prx, pry, x++, y, BLACK);

//remember last point coordinates

prx=x;

pry=y;

}

}

 

Drawing function has several parameters. X0 and Y0 are signal starting coordinates on LCD. A is an amplitude, R is resolution. Resolution allows to squeeze or expand signal. And of course pointer to signal table.

Now what you have to do in main() program stream is to set active window size and draw signal.

 

//set active window area

setWindow(0,0,63,31);

//draw signal

drawSignal(win.xmin, win.ymin+(uint8_t)((win.ymax-win.ymin)/2), 10, (uint8_t)(256/(win.xmax-win.xmin)), sinewave);

 

Here is a results of my efforts.

First thing what I can think of is a signal generator where signal can be selected visually by walking through sub-windows. Changing resolution would result in signal frequency change obviously amplitude to amplitude. Another thing of several windows usage may be reading and displaying graphical information of several sensors like temperature. Each window could update in sequence. Hope this example will give some ideas to someone.

File: 

Comments

thank you very much for the above project.it has helped me a lot in understanding glcd interfacing. i am working on a project that displays a continuous graph on the glcd from a sensor input. how do i clear the screen so that the lcd can display different values according to the sensor input?

Try to look at http://winavr.scienceprog.com/temperature-sensor-with-time-and-date-disp...

This is where live graph is displayed with refreshing sensor values. If you'll need more help, drop a note here.

Hello I ma working on A glcd based project. i have interfaced GLCD which is JHD12864E. I have connected as you mentioned here and code is also same. it worked on Proteus but not on real Hardware. please tell me what can be the reason?

hi
thanks for the program,in fact its the one im looking for ,but in CVAVR not in WINAVR.please if you could,help me.its about my final project.