Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 30th October 2009, 12:47 PM   #121
Thumbs up

Hello Pommie, it is a great job writing a library like this. Your library is one of the best, most understandable and standard one I have ever come across on the net. Thank you very much for your hard work.


I've just started to learn embedded systems with PIC series. Yesterday I wrote my first "Hello World" application which is actually nothing bot blinking a LED. Now I want to put my effort into something bigger, like interfacing an LCD. I have a few question about your code, but first I want to introduce the relevant information I collected over internet...

Direct links to photos of my LCD (with KS108 controller):
Front, Back

Port mapping in you code:
Code:
#define GLCD_Data   PORTD
#define b_GLCD_GCS1 LATBbits.LATB4
#define b_GLCD_GCS2 LATCbits.LATC0
#define b_GLCD_RS   LATEbits.LATE0
#define b_GLCD_RW   LATEbits.LATE1
#define b_GLCD_E    LATEbits.LATE2
#define b_GLCD_On   LATAbits.LATA4
#define b_GLCD_BL   LATBbits.LATB3
Pin configuration of a KS108 controller LCD:
KS0108 Controller, at the bottom of the page.

Instruction set of the LCD:
http://www.stirve.com/storage/lcd_instruction_set_1.jpg


Now, the point which confuses me is,

Your code defines these 6 connections:
b_GLCD_GCS1
b_GLCD_GCS2
b_GLCD_RS
b_GLCD_RW
b_GLCD_E
b_GLCD_On


LCD has these 6 pins available:
D/I
R/W
E
CS1
CS2
RES


If you try to match these:
b_GLCD_GCS1 == CS1
b_GLCD_GCS2 == CS2
b_GLCD_RS == RES
b_GLCD_RW == R/W
b_GLCD_E == E
b_GLCD_On == ???


One can say that b_GLCD_On should match with D/I, but when you refer to the instruction set of the LCD, D/I pin is for specifying whether our output data at PIC pins is data or instruction. On the other hand, from my understanding (excuse me if I am wrong), b_GLCD_On is used for some other purpose like activating the LCD, I think you control power source of the LCD, by switching on and off a transistor with this pin.

Can you please specify what b_GLCD_On is for, and how you handle D/I pin?
Do you have any sample schematics and code?

Again, thank you for this wonderful project.
I will appreciate if you reply.
hkBattousai is online now  
Old 30th October 2009, 06:39 PM   #122
Thumbs up

Double post deleted, sorry for inconvenience...

Last edited by hkBattousai; 31st October 2009 at 11:31 AM. Reason: Double post
hkBattousai is online now  
Old 31st October 2009, 01:34 PM   #123
Default

I think it refers to the RES pin

Edited to be correct heh

Last edited by AtomSoft; 31st October 2009 at 01:52 PM.
AtomSoft is offline  
Old 31st October 2009, 01:38 PM   #124
Question

Quote:
Originally Posted by AtomSoft View Post
I think it refers to the backlight control
In that case, how do we control the D/I pin of the LCD?
We cannot leave it unconnected, can we?
hkBattousai is online now  
Old 31st October 2009, 01:46 PM   #125
Default

RS... is D/I

GLCD_on is RES

Last edited by AtomSoft; 31st October 2009 at 01:53 PM.
AtomSoft is offline  
Old 31st October 2009, 01:47 PM   #126
Default

If you look at his Data and Command code:
Code:
void GLCD_Write_Cmd(unsigned char data){
	Wait_Not_Busy();
	GLCD_Data = data;
	b_GLCD_RS=0;
	b_GLCD_RW=0;
	b_GLCD_E=1;
	Delay();
	b_GLCD_E=0;
}

void GLCD_Write_Data (unsigned char data){
	Wait_Not_Busy();
	GLCD_Data = data;
	b_GLCD_RS=1;
	b_GLCD_RW=0;
	b_GLCD_E=1;
	Delay();
	b_GLCD_E=0;
}
RS is the main item that changes meaning it controls Data or Command hence it has to be D/I
AtomSoft is offline  
Old 31st October 2009, 01:48 PM   #127
Lightbulb

Quote:
Originally Posted by AtomSoft View Post
RS... is D/I

The real RS Pin is tied low i think
Hmm, I was wondering the difference between RS and RST...
Now the whole thing is complete in my mind. I will give it a try soon...
hkBattousai is online now  
Old 31st October 2009, 01:48 PM   #128
Default

#define b_TRIS_On TRISAbits.TRISA4 //RST

so b_GLCD_On is the RS pin on GLCD
AtomSoft is offline  
Old 31st October 2009, 01:51 PM   #129
Default

Heh i confuse people maybe so here is the code commented to clarify what i mean:
Code:
#define GLCD_Data   PORTD  //DB0 to DB7
#define b_GLCD_GCS1 LATBbits.LATB4  //Chip Select 1
#define b_GLCD_GCS2 LATCbits.LATC0  //Chip Select 2
#define b_GLCD_RS   LATEbits.LATE0  //GLCD D/I
#define b_GLCD_RW   LATEbits.LATE1  //GLCD R/W
#define b_GLCD_E    LATEbits.LATE2  //GLCD E
#define b_GLCD_On   LATAbits.LATA4  //GLCD RES
#define b_GLCD_BL   LATBbits.LATB3  //GLCD Backlight

#define TRIS_Data    TRISD  //TRIS for DB0 to DB7
#define b_TRIS_GCS1  TRISBbits.TRISB4 //GCS1
#define b_TRIS_GCS2  TRISCbits.TRISC0 //GCS2 
#define b_TRIS_RS    TRISEbits.TRISE0 //D/I 
#define b_TRIS_RW    TRISEbits.TRISE1 //RW 
#define b_TRIS_E     TRISEbits.TRISE2 //E 
#define b_TRIS_On    TRISAbits.TRISA4 //RES
#define b_TRIS_BL    TRISBbits.TRISB3 //backlight

Last edited by AtomSoft; 31st October 2009 at 01:52 PM.
AtomSoft is offline  
Old 31st October 2009, 01:55 PM   #130
Default

^ This comments explain everything

But now, there is this new term: "RES".
Correct me if I'm wrong,
RS == D/I
RES == RST == Reset
Is that right?
hkBattousai is online now  
Old 31st October 2009, 02:08 PM   #131
Default

YES heh you got it now

Code:
#define GLCD_Data   PORTD  //DB0 to DB7
#define b_GLCD_GCS1 LATBbits.LATB4  //Chip Select 1
#define b_GLCD_GCS2 LATCbits.LATC0  //Chip Select 2
#define b_GLCD_RS   LATEbits.LATE0  //GLCD RS,D/I
#define b_GLCD_RW   LATEbits.LATE1  //GLCD R/W
#define b_GLCD_E    LATEbits.LATE2  //GLCD E
#define b_GLCD_On   LATAbits.LATA4  //GLCD RES,RST,RESET
#define b_GLCD_BL   LATBbits.LATB3  //GLCD Backlight

#define TRIS_Data    TRISD  //TRIS for DB0 to DB7
#define b_TRIS_GCS1  TRISBbits.TRISB4 //GCS1
#define b_TRIS_GCS2  TRISCbits.TRISC0 //GCS2 
#define b_TRIS_RS    TRISEbits.TRISE0 //RS, D/I
#define b_TRIS_RW    TRISEbits.TRISE1 //RW 
#define b_TRIS_E     TRISEbits.TRISE2 //E 
#define b_TRIS_On    TRISAbits.TRISA4 //RES,RST,RESET
#define b_TRIS_BL    TRISBbits.TRISB3 //backlight

Last edited by AtomSoft; 31st October 2009 at 02:09 PM.
AtomSoft is offline  
Old 31st October 2009, 10:47 PM   #132
Unhappy Doesn't work... :(

Below are the pieces of code which I modified or appended:

glcd.h
Code:
#include <p18f2550.h>

#define GLCD_Data   PORTB
#define b_GLCD_GCS1 LATCbits.LATC7
#define b_GLCD_GCS2 LATCbits.LATC6
#define b_GLCD_RS   LATCbits.LATC0
#define b_GLCD_RW   LATCbits.LATC1
#define b_GLCD_E    LATAbits.LATA5
#define b_GLCD_On   LATCbits.LATC2
#define b_GLCD_BL   LATAbits.LATA4	// Not used in my project

#define TRIS_Data    TRISB
#define b_TRIS_GCS1  TRISCbits.TRISC7 //GCS1
#define b_TRIS_GCS2  TRISCbits.TRISC6 //GCS2 
#define b_TRIS_RS    TRISCbits.TRISC0 //RS 
#define b_TRIS_RW    TRISCbits.TRISC1 //RW 
#define b_TRIS_E     TRISAbits.TRISA5 //E 
#define b_TRIS_On    TRISCbits.TRISC2 //RST
#define b_TRIS_BL    TRISAbits.TRISA4 //backlight
glcd.c
Code:
void Delay(void){
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
	_asm	NOP	_endasm
}
(Tried single NOP, five NOPs, and this 10-NOPed one, non worked.
I didn't change any other function in this file (Except for replacing "#include <p18f4550.h>" with "#include <p18f2550.h>").)


main.c
Code:
#include <p18f2550.h>
#include "glcd.h"
#pragma config WDT	= OFF
#pragma config MCLRE	= ON
#pragma config DEBUG	= OFF
#pragma config LVP	= OFF
#pragma config PLLDIV	= 5		// need 5 for 20MHz xtal
#pragma config CPUDIV	= OSC1_PLL2	// CPU Clock = 96 MHz/2 = 48 MHz
#pragma config USBDIV	= 2		// 96MHz PLL/2 = 48 MHz for USB clock 
#pragma config FOSC	= HSPLL_HS	// High Speed Crystal / Resonator with PLL enabled

void main (void)
{
	while (1)	// Nothing changes if I remove this infinite loop
	{
		Init_GLCD();
		
		PutMessage((rom char*)"\x16\x24\x08 Blueroom\x16\x20\x10 Electronics\n Title:\n Author:\n Date:\n Hardware:");
		PutMessage((rom char*)"\x16\x38\x18Graphic demo.");
		PutMessage((rom char*)"\x16\x38\x20Mike Webb.");
		PutMessage((rom char*)"\x16\x38\x28June 20 2007.");
		PutMessage((rom char*)"\x16\x38\x30Unicorn.");
		
		box(1,1,126,62);
	}
	
	while (1);
	
	// Working "Hello World" example
	/*unsigned char i, j;
	TRISB = 0;
	while (1)
	{
		PORTB = 0x00;
		Delay1KTCYx(i);
		PORTB = 0xFF;
		Delay1KTCYx(255-i);
	}*/
}
Below are the photos of my circuit:
Front, Up

I checked signal levels at PIC pins with an oscilloscope and everything looks alright. OSC1 and OSC2 has clock pulses; data port, and other relevant LCD pins have meaningful pulses. I think it is likely that there has to be mistake in my code.

And, I found a new datasheet (uploaded as an attachment) for my LCD, and after reading it I realized that the pin configurations in my first post in this thread was wrong. I rebuilt the circuit by refering to this new datasheet; yet it still isn't working...

I'm totally stuck!
Attached Files
File Type: pdf CFAG12864BWGHV.pdf (1.52 MB, 36 views)

Last edited by hkBattousai; 31st October 2009 at 10:52 PM.
hkBattousai is online now  
Old 31st October 2009, 10:55 PM   #133
Default

Move the init out the while loop first of all I'll take a look at it closer in a minute

...can u post a schematic for me just for fun
AtomSoft is offline  
Old 31st October 2009, 11:08 PM   #134
Default

Quote:
Originally Posted by AtomSoft View Post
Move the init out the while loop first of all I'll take a look at it closer in a minute
Did so, but it is still the same. The screen is blank. Back-light is on, and I can adjust the contrast, but nothing else.


Quote:
Originally Posted by AtomSoft View Post
...can u post a schematic for me just for fun
Unfortunately I didn't use any schematics, actually I couldn't find any schematics. I built up the circuit on a bread-board (the one you see in the link in my previous message) just by looking at PIC and LCD datasheet.
hkBattousai is online now  
Old 1st November 2009, 03:05 PM   #135
Angry Need more information...

I read some datasheet about "xG12864x-xxx-x" LCD unit. I realized a point, pin configuration differs for every product. Even if the you manage to catch the rightful pin locations and match them perfectly between PIC and LCD, you system could not work because some pins may be complemented on the LCD side.

For example,
In "Crystalfontz America" model (CFAG12864B-WGH-V) CS1 and CS2 bits are complemented, while in "Winstar" model (WG12864B) CS1 and CS2 bits are not complemented.
This was just an example, there are more that CSx bits that differ. For example E (Enable) is complemented in some LCDs, and not complemented in others.

I really need a detailed pin configuration from one of you who succeeded in this project.
I need to know:
  1. Your LCD model (pin configuration, and which bits are complemented on the LCD side)
  2. If you made any modifications in the original code Pommie gave

************

Quote:
Originally Posted by AtomSoft View Post
YES heh you got it now

Code:
#define GLCD_Data   PORTD  //DB0 to DB7
#define b_GLCD_GCS1 LATBbits.LATB4  //Chip Select 1
#define b_GLCD_GCS2 LATCbits.LATC0  //Chip Select 2
#define b_GLCD_RS   LATEbits.LATE0  //GLCD RS,D/I
#define b_GLCD_RW   LATEbits.LATE1  //GLCD R/W
#define b_GLCD_E    LATEbits.LATE2  //GLCD E
#define b_GLCD_On   LATAbits.LATA4  //GLCD RES,RST,RESET
#define b_GLCD_BL   LATBbits.LATB3  //GLCD Backlight

#define TRIS_Data    TRISD  //TRIS for DB0 to DB7
#define b_TRIS_GCS1  TRISBbits.TRISB4 //GCS1
#define b_TRIS_GCS2  TRISCbits.TRISC0 //GCS2 
#define b_TRIS_RS    TRISEbits.TRISE0 //RS, D/I
#define b_TRIS_RW    TRISEbits.TRISE1 //RW 
#define b_TRIS_E     TRISEbits.TRISE2 //E 
#define b_TRIS_On    TRISAbits.TRISA4 //RES,RST,RESET
#define b_TRIS_BL    TRISBbits.TRISB3 //backlight
Can you please specify which of these bits were complemented in your implementation, and what model LCD did you use?

This would help greatly if you answer this question.
Attached Files
File Type: pdf WG12864A.pdf (275.6 KB, 4 views)
File Type: pdf WG12864B.pdf (463.1 KB, 35 views)
hkBattousai is online now  
Reply

Tags
demo, glcd, unicorn

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Unicorn Oscilloscope running GLCD 128x64 & Photo blueroomelectronics Micro Controllers 8 18th June 2007 03:06 PM
Help understanding the Unicorn Kyle-s4h Micro Controllers 2 5th June 2007 07:09 PM
Open MultiSim DEMO Files mayo General Electronics Chat 1 3rd May 2007 04:52 PM
mcuStudio an Eclipse based IDE for PIC: flash demo available octal Micro Controllers 0 23rd August 2006 06:44 AM
Honeywell HMR3000 DEMO KIT shermaine General Electronics Chat 5 26th May 2005 09:35 AM



All times are GMT. The time now is 05:22 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker