|
|
View previous topic :: View next topic |
Author |
Message |
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Graphics for dummies |
Posted: Tue Mar 27, 2012 7:38 pm |
|
|
How does one get started in driving a 128x64 dot graphics display.
This is a ST7920.
Is there a graphics library for CCS C?
How do you mix graphics and alphanumerics?
Do I have to write this from scratch? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Mar 28, 2012 5:34 am |
|
|
1) read the datasheet.Knowledge is power!
2) constuct a breadboard with both PIC,GLCD AND ALL support devices.
3) cut code to confirm it works in simple text mode.
4) read datasheet again, google GLCD device for more info.
If you can't locate someone else's code you have 2 options
a) cut the code yourself.It is a simple device,should take maybe a week at most depending on how complex a driver you want,your level of programming and how well you type.
b) pay someone to do the driver.Be prepared to supply 4-6 samples of the device and wait until it it done.How soon it gets done is directly proportional to the cash you're willing to pay.
option 'b' is easy
do option 'a' and you'll learn |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Graphics for dummies |
Posted: Wed Mar 28, 2012 12:52 pm |
|
|
I said graphics for dummies.
Is there software, what is GLCD?
I assume graphics is done as an x-y matrix but how are the arrays loaded?
How does one insert a character?
How does one get started?
It would be stupid to start programming in machine language and 'invent' an assembler only to find out that there are assemblers and compilers and MPLAB for free.
I have extensive experience in electronics hardware and am not too bad at C but I have never used a graphics display. I have used alpha-numeric LCD displays. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: Graphics for dummies |
Posted: Wed Mar 28, 2012 1:04 pm |
|
|
rovtech wrote: | I said graphics for dummies.
Is there software, what is GLCD?
I assume graphics is done as an x-y matrix but how are the arrays loaded?
How does one insert a character?
How does one get started?
It would be stupid to start programming in machine language and 'invent' an assembler only to find out that there are assemblers and compilers and MPLAB for free.
I have extensive experience in electronics hardware and am not too bad at C but I have never used a graphics display. I have used alpha-numeric LCD displays. |
GLCD is a software library.
Yes, graphics are done X-Y... and arrays are loaded in one data chunk at a time. (I say chunk because depending on the type of display, a chunk can be a bit, byte word or more... it depends on the display)
Char's in Char LCD's are done usually one byte per char.
In Graphic LCD's, they are done by pixel maps (arrays) with a depth that corresponds to the color support desired.
If you already know C, then stick with it. If you want to play with microcontrollers, you should learn their ASM at some point so when 'C' code doesn't work, you can look at the disassembly to see if it's something the compiler is doing wrong. Ultimately, if you DON'T eventually learn the ASM for these pups, you will be at a disadvantage.
As already stated, "Knowledge is Power!"
Cheers,
-Ben
p.s. Yes, Microchip has a free IDE. (I use it) But their compilers will bend more of your brain with a learning curve much steeper than CCS. I have both CCS and C18/30/32 and I can tell you, it's much easier to whip stuff out in CCS than C18. Period. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Mar 28, 2012 6:11 pm |
|
|
hmm.. graphics for Dummies. is a HUGE book though you seem to want a set of drivers for a specific GLCD.
GLCD means Graphics Liquid Crystal Display,at least to me.
The common 'text' or alpha-numeric LCD units are in fact a subset of GLCDs.They of course can be used for graphics though 'low resolution' or low pixel count compared to a 'graphics LCD'.
As for learning how to cut 'graphics' code,some of the best information was done 30 years ago for the TRS80s and Model100 computers.Very tight,efficient code written in BASIC none the less,with calls to small machine language subroutines.PSET,PCLR,PLINE,PCIRCLE,PCHAR were all 'commands' used back then.Even the IBM tehnical reference book has a wealth of graphical display information.
With respect to 'graphics for Dummies' you should specify what you need.First off monocolour or RGB display. Simple text..obviously easy, 'basic graphics' like circles,lines,rectangles, or multiple screens on one GLCD similar to 'Windows'. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Graphics for dummies |
Posted: Wed Mar 28, 2012 7:14 pm |
|
|
Thanks for the helpful replies.
I bought a 128x64 LCD display, monochrome. There seems to be software that drives this from an Arduino but I am not about to abandon the PIC and CCS C (lazy).
I was hoping to get a link to someone's code that displays graphics on a similar LCD.
I would like to think that a function could be displayed. Say a straight line with slope and offset to start, or a sine wave.
For a complex colour display it seems easiest to just use an old laptop, however I want a lower resolution display for projects.
I started programming the Intel 8008 in machine language with programs on paper tape loaded by Teletype, and yes I know PIC assembly language. I have also programmed plots on the HP9820 calculator + plotter. However I am not a programmer, I prefer hardware. |
|
|
W4GNS
Joined: 28 Sep 2010 Posts: 14 Location: Virginia, USA
|
Re: Graphics for dummies |
Posted: Wed Mar 28, 2012 7:30 pm |
|
|
rovtech wrote: | Thanks for the helpful replies.
I was hoping to get a link to someone's code that displays graphics on a similar LCD.
. |
Using the forum search function showed several hits ex: http://www.ccsinfo.com/forum/viewtopic.php?t=32819&highlight=st7920 _________________ PCWH 4.14 |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Graphics for dummies |
Posted: Fri Mar 30, 2012 8:36 am |
|
|
To answer my own question so I may help others viewing this thread;
CCS has two routines as a starting point. They are graphics.c and GLCD.C and can be found in C:\progrm files\PICC\drivers if you have PIC C loaded on your computer. Also look in the \examples folder. I wish someone had pointed that out to me at the start.
What is needed as a starter for graphics is a function that plots a point and a function that draws a line between two points. These and several others are in these files.
If you know nothing about graphics then "Graphics primer for the IBM PC" Osborne/McGraw Hill ISBN 0-931988-99-3 is a good place to start. It is 1985 vintage but may be possible to find. It assumes a DOS system and BASICA but the descriptions and examples are applicable to modern graphics LCDs and can be adapted to C. You may even be able to find an old computer with Windows 3 and DOS with BASIC to try the examples.
There are programs in the CCS Code Library but they may cause confusion. If they don't include the CCS files but use functions beginning with GLCD_xxx then these are routines that are defined in that program and are not the CCS library functions. I can see a few reasons that one may want to write their own routines. The CCS routines seem to use quite a few ports (B, C, & D) but the LCD may have options such as serial, 4 or 8 bit communications. The 4 bit mode can do everything on one port with the other 4 bits used for the control (CS etc) bits. The CCS LCD.C does this for common alphanumeric LCDs.
I am not sure if a generic graphics program can be written since there are so many variables to the LCDs. Size, colour selection, built-in character generators, etc. This is another eason for a custom program. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: Graphics for dummies |
Posted: Fri Mar 30, 2012 10:23 am |
|
|
rovtech wrote: |
I am not sure if a generic graphics program can be written since there are so many variables to the LCDs. Size, colour selection, built-in character generators, etc. This is another eason for a custom program. |
That is usually the case with micro controllers.
I know companies that spend countless hours trying to "library-ize" everything they write so that some code can be used for another micro.
Heck, microchip does this...
But then the code usually bloats or becomes hard to read or the wrong programmer gets his fingers in and makes a mess.
All those hours invested, and then:
You WILL want to edit for performance and ultimately, you WILL tweak the code for compatibility with some new part.
Once you do those things, it becomes quickly apparent how hard it is to really make a "once and for all" universal driver.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Please help! |
Posted: Mon Apr 09, 2012 1:22 pm |
|
|
I found example software in many places but almost all suffer from a lack of comments so it is very difficult for a novice to understand what is being done. The calling software was seldom included so it was impossible to determine which microprocessor was intended, or how to use the functions. Much of it was aimed at the Arduino and Atmel so the C was different from CCS C. What is worse it seems riddled with mistakes.
My display is the Digole 12864ZW module using the ST7920 connected to a PIC16F722.
I understand DDRAM, GDRAM, CGRAM, CGROM and HCGROM. OK, but how is each loaded. The Address Counter is a pointer to the address of all of these, but how do you know what is being addressed. I think it depends on the value loaded. I cannot find an overview of how the chip is used.
There are scary hints that individual pixels cannot be controlled, that the matrix is made up of 16x16 blocks, that the screen is split in two, and that only two of the four lines of characters can be used. All very confusing.
I have managed to get characters displayed but cannot get the welcome message displayed that is in HCGROM. I will post this progress separately.
Another example of a driver seems to need more than 1024 bytes of RAM on the PIC. This is to get around the problems by refreshing the screen from a cache. It looks like it might work but my 16F722 does not have enough RAM to compile. Why do the 16F chips have so little RAM? Can anyone suggest a PIC with 40 pins or less? Not surface mount. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Progress |
Posted: Mon Apr 09, 2012 1:34 pm |
|
|
I connected the Digole 12864ZW module to a PIC16F722 and got some functions working that INITIALIZE THE DISPLAY, WAIT FOR BUSY TO CLEAR, WRITE A COMMAND TO THE INSTRUCTION REGISTER, and WRITE TO THE DATA REGISTER. I can now display a character string.
I am unable to find working software. Can someone explain the following statements.
Code: | rom char *position_lcd = {0x80, 0x90, 0x88, 0x98}; |
I understand that ‘position_lcd’ is a pointer of type ‘char’ but what is rom, and is ‘position_lcd’ an array? Is it initialized to four different addresses? Should there not be [4] after it to define an array of 4? It may be Atmel code for the Arduino. I think the 0x80 points to a welcome message in CGROM but is outside the range of HCGROM which appears to be an error in the data sheet.
position_lcd is used thus:
Code: | void set_addres(char row, char column)
{
WriteCmd(position_lcd[row]+column);
} |
Why does this not have four arguments? Why is the indirection operator or ampersand not required (* and &)? Is this pointer arithmetic like incrementing a pointer? Which of the four arguments are being used and how is this determined? Why does this even compile without errors? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Mon Apr 09, 2012 2:33 pm |
|
|
The "rom" means the values are placed into program memory and cannot be changed (as opposed to RAM, where most variables are located normally).
It looks like he is allocating an array of 4 values, which are the character positions command values of the 4 rows. To be honest, I don't know 100% sure the line you've posted will actually work, but I will assume it does (I don't typically allocate arrays that way).
The normal way you do that line is:
Code: |
rom char position_lcd[] = {0x80, 0x90, 0x88, 0x98};
|
or
Code: |
rom char position_lcd[4] = {0x80, 0x90, 0x88, 0x98};
|
Remember, an array is pretty much a pointer, so both pointer arithmetic and [] notation will work (be careful with rom pointers though...those are actually tricky...pointers usually point to a location in RAM rather than ROM, so you have to treat them more carefully usually).
As for the function, it only needs the 2 parameters and since the array he is using is global, he doesn't have to pass it in with the row and col values. The * or & doesn't need to be used because of how he is using them. * is for derefercing, but he is using [] to dereference instead. & is for getting the address, but all he needs are the values for row and column, not the addresses.
position[row] is very similar to pointer math, but tends to be the safer way to work with ROM pointers. Assume row is "1", then that is similar to incrementing the pointer address and dereferencing it.
If row=1 and column=4, then you get 0x90+4 = 0x94, which is the value WriteCmd() uses after the math is done. |
|
|
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
Re: Graphics for dummies |
Posted: Mon Apr 09, 2012 3:47 pm |
|
|
rovtech wrote: | I said graphics for dummies.
Is there software, what is GLCD?
I assume graphics is done as an x-y matrix but how are the arrays loaded?
How does one insert a character?
How does one get started?
It would be stupid to start programming in machine language and 'invent' an assembler only to find out that there are assemblers and compilers and MPLAB for free.
I have extensive experience in electronics hardware and am not too bad at C but I have never used a graphics display. I have used alpha-numeric LCD displays.
|
Yes, you have demonstrated ! _________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Mon Apr 09, 2012 6:17 pm |
|
|
Thank you for the replies. The Nuts&Volts article is interesting but it is for a different display. My friend has one of these (Digole) displays working with the Arduino and it seems to do the things others are having trouble with, including writing to a single pixel without having a large RAM cache. However the software is not well commented and is in Atmel C so it is hard to understand.
I don't think drawing to this display is as simple as mapping to x-y.
Perhaps dezso could explain exactly how one would do this - not the software, just explain the steps. Easier yet, how would one display the first character at address 80H in the CGROM? Why does the display go from line 1 to 3 to 2 to 4 with a long string? How do you start a new line? It does not respond to standard escape characters.
The software example I started with does not work with the Digole display but I am getting there. The scary things I mentioned may not be true. I can display 4 lines so I don't know what the spec sheet means by two lines of characters.
CCS has a (GLCD.C) driver for the HDM64GS12 display which is different from the ST7920. I suppose I could buy one and chuck mine but then I would not learn anything.
If I can get the basic drivers written then I can use the (graphics.c) CCS code to draw the graphics. I would like to keep this thread for the Digole display, or at least for the ST7920 driver chip. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|