Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic and graphic lcd

Status
Not open for further replies.

IZACH

New Member
hi guys

i am having some problems getting a graphics lcd display k0108 to interface with a pic 16f887

maye someone can help me here

i am using asembler language as this i am an old timer and dont understand c as well as i dont have any compilers for c so asembly language it is.

here are my problems
1) i seem to be able to reset the display and switch it on when i do this part of the routine i get all the pixels on this is not to much of a problem as i can send a couple of commands to clear the screen so i can turn on the pixels that i want. but according to all the datasheets i have been able to get hld of on the internet if you do a reset then the display should return to position 0. i would think that it should aslo clear the screen.

this is not happening what appears to be happening is that the glcd has some type of memory in it so when a reset is done it goes back to the place it already is at and does not clear the display.

2) also there seems to be a problem with the adresses as if i point to position 1 page 0 z=0 then the display goes to seven pixels across, so if i put in a y adress of 58 then it starts at the beginging of the line.

3) also if i try to write to cs1 and cs2 together then the lcd does not respond
to any changes after the first write i gather therefore you have to access the one then the other.


please could someone look at my code and then let me know where i am going wrong if at all
 

Attachments

  • GLCDTEST.asm
    9.2 KB · Views: 288
You appear to be doing something strange with the Enable line. The Enable line should be low all the time and pulsed high to read/write to the display.

These are specific to my hardware but should give you some idea.
Code:
InitLCD		bsf	b_LCD_CS1
		bsf	b_LCD_CS2
		movlw	0x3f
		call	WriteCMD
		movlw	0xc0
		call	WriteCMD
		movlw	0x40
		call	WriteCMD
		movlw	0xb8
		call	WriteCMD
		return

WaitNotBusy	call	SetInput
		bsf	b_LCD_RW
		bcf	b_LCD_RS  
		btfss	b_LCD_CS1
		goto	Skip_CS1
		bcf	b_CS2
		btfsc	b_LCD_CS2
		bsf	b_CS2
		bcf	b_LCD_CS2
WNB1_Loop	bsf	b_LCD_E
		btfsc	PORTB,7
		goto	WNB1_Loop
		bcf	b_LCD_E
		btfsc	b_CS2
		bsf	b_LCD_CS2
Skip_CS1	btfss	b_LCD_CS2
		goto	Skip_CS2
		bcf	b_CS1
		btfsc	b_LCD_CS1
		bsf	b_CS1
		bcf	b_LCD_CS1
WNB2_Loop	bsf	b_LCD_E
		btfsc	PORTB,7
		goto	WNB2_Loop
		bcf	b_LCD_E
		btfsc	b_CS1
		bsf	b_LCD_CS1
Skip_CS2
SetOutput	bsf	STATUS,RP0
		clrf	TRISB
		bcf	STATUS,RP0
		return

SetInput	bsf	STATUS,RP0
		movlw	0xff
		movwf	TRISB
		bcf	STATUS,RP0
		return

ReadLCD		bsf	b_LCD_E
		movfw	PORTB
		bcf	b_LCD_E
		return

WriteCMD	movwf	LCDTemp
		call	WaitNotBusy
		movfw	LCDTemp
		movwf	PORTB
		bcf	b_LCD_RW
		bcf	b_LCD_RS
		bsf	b_LCD_E
		bcf	b_LCD_E
		return

WriteData	movwf	LCDTemp
		call	WaitNotBusy
		movfw	LCDTemp
		movwf	PORTB
		bcf	b_LCD_RW
		bsf	b_LCD_RS	;rs=1 rw=0
		bsf	b_LCD_E
		bcf	b_LCD_E
		return

Cls		bsf	b_LCD_CS1
		bsf	b_LCD_CS2
		movlw	0x08
		movwf	ForI
ClsLoopI	movlw	0x40
		movwf	ForJ
		call	WriteCMD
		decf	ForI,W
		iorlw	0xb8
		call	WriteCMD
ClsLoopK	movlw	0x00
		call	WriteData
		decfsz	ForJ,F
		goto	ClsLoopK
		decfsz	ForI,F
		goto	ClsLoopI
		clrf	XPos
		clrf	YPos
		return

The WaitNotBusy routine is a little convoluted as I test both displays dependant on if the CS lines are high. Sorry about the lack of comments.:eek:

HTH

Mike.
 
On the GLCD I owned, there is no RESET command one can send to the GLCD. When powered up, the GLCD enters a RESET state and user can check if the reset operation has finished via reading the STATUS byte and testing a bit in it.

The reset operation will not clear what was displayed on the LCD. In fact, on mine the previous data still remains even if I remove the main power for a few seconds and power it up again. Therefore user must be pro-active to clear the display by writing to every pixel to switch it off. This can be easily done via a loop.

With regard to the pixel addressing, you need to check the datasheet. I offer an image to help you along in understanding the addressing scheme.

You simply cannot write to both GLCD Controllers at the same time, similar to one cannot write to two memory locations at once.
 

Attachments

  • GLCD.gif
    GLCD.gif
    29.3 KB · Views: 392
I just looked at the **broken link removed**and reset only sets Z=0 not X & Y and doesn't clear the display.
One other thing, in the above data sheet it does not mention the fact that to read data from the display, you have to do a dummy read first.

Mike.
 
eblc1388 said:
You simply cannot write to both GLCD Controllers at the same time, similar to one cannot write to two memory locations at once.

Oh yes you can. My clear screen routine above does exactly that.

You cannot read from both at the same time, hence my convoluted TestNotBusy routine.

Mike.
 
Pommie said:
Oh yes you can. My clear screen routine above does exactly that.

You cannot read from both at the same time, hence my convoluted TestNotBusy routine.

Mike.

Thanks Mike. That's very useful to know. Can save half the time in clearing the display.
 
pic to glc

thanks pommie

seems that i was reading the datasheet incorrectly as after you gave me that code and i repaired mine it works.

thanks if you would like to see the finished code i will post it it might be interesting for someone else????

thanks
 
If anyone is interested I use two 'LS164's to interface to my KS0108 display so I can drive it with two I/O pins only. You can't read the diaplay status but sometimes that is not as important as saving pins I/O :) so you can use the display with say, a 12F675.
 
blueroomelectronics said:
It appears to be some kind of PIC users disease. I dislike glue logic unless I have a good reason for it.

Basically it's 30 year old thinking - adding extra chips to make a micro-processor useable. The whole point of a micro-controller is that it's mainly a single chip solution - although there are obvious occasions when 'glue' chips may be useful, but starting off with a chip you know is far too small isn't really one of them.
 
There are times when offloading some functions onto 'glue' hardware is a valid/justifiable design option.

Might actually be better in some cases than the "throw a bigger PIC at the problem" disease (grin)...

Mike

**broken link removed**
**broken link removed**
 
Last edited:
Of course some people are very good coders, and have never needed to debug like I have had to... And starting off with a device with to low a pin count or producing a design requiring glue logic can be a trap. But on the occasions where I have been fortunate enough to escape these mistakes I found it to be a very useful 'trick' to borrow two spare I/O, minimal code overhead and a good way of getting info such as register values, A/D values etc. from low pincount projects. In one project which was 'cost sensitive' but had to have a 'field diagnostic display' which could be plugged into the DUT, the price break was enough to ensure I got the contract.

But back to the origional theme, the KS0108 display is two seperate units sharing one LCD so there are two CS lines and as mentioned the reset points the 'print' position to 0,0 but does not clear the display ram. However, I have found that the EN strobe can be critical with some brands. As a matter of interest, I have a unit that I purchased off e-bay that has provision for adding a second 7660 voltage invertor in cascade mode which I am hoping will allow me to power the unit comfortably from 3 volts. I would be interested if anyone else has seen/tried this ?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top