SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Coinfree
#46047
I just received some of the new Nokia knock off LCDs with the red tab and X3 stamp over the connector. Turns out they don't have the Epson controller like the older LCDs they have the Phillips. Having just spent a few days reworking my code, I figured I would post up my results to help out anyone else doing the same thing.

When I attempted to use the new LCD in 8 bit color mode, everything looks washed out. I tried all the contrast settings and various color mapping settings as well as most of the other related commands in the spec sheet. I went to 12 bit and it came out nice and clear like the older LCDs. Unfortunately I had to modify the rest of my code to use 12 bit colors when using this LCD.

I would appreciate any thoughts or ideas especially about the washed out 8 bit mode, as if I would very much like to return my code to one unified color scheme.

The code is in Pic Basic, enjoy.





Code: Select all
'************************************************************
'* InitializeColors:
'*
'* Load up color variables with the values for the controller
'* in use.
'************************************************************
InitializeLCDColors:

	IF LCDType == PhillipsLCD Then
	
		Black    	= PBlack	
		White   	= PWhite
		Blue    	= PBlue
		Green   	= PGreen
		Red     	= PRed
		Cyan     	= PCyan 	
		Yellow   	= PYellow
		Magenta  	= PMagenta
		Orange	 	= POrange
		Chartruse 	= PChartruse
		
	
	Else ' Epson is default
	
		Black    	= EBlack	
		White   	= EWhite
		Blue    	= EBlue
		Green   	= EGreen
		Red     	= ERed
		Cyan     	= ECyan 	
		Yellow   	= EYellow
		Magenta  	= EMagenta
		Orange	 	= EOrange
		Chartruse 	= EChartruse	
	EndIF	

	Return

'************************************************************
'* SendCommand:
'*
'* Send a command byte to LCD controller
'************************************************************   
SendCommand:

	LCDSCLK  = 1
	Low LCDCS

   LCDSCLK  = 0
   LCDSData = 0
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.7
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.6
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.5
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.4
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.3
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.2
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.1
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.0
   LCDSCLK  = 1
   
   High LCDCS

   Return
 
 
'************************************************************
'* SendData:
'*
'* Send a data byte to LCD controller
'************************************************************      
SendData:

	LCDSCLK  = 1
	Low LCDCS
		
   LCDSCLK  = 0
   LCDSData = 1
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.7
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.6
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.5
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.4
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.3
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.2
   LCDSCLK  = 1
   
   LCDSCLK  = 0
   LCDSData = dat.1
   LCDSCLK  = 1

   LCDSCLK  = 0
   LCDSData = dat.0
   LCDSCLK  = 1

	High LCDCS

   Return


'************************************************************
'* InitLCD:
'* 
'* Decide which type of LCD to setup
'************************************************************
InitLCD:
	
	IF LCDType == PHILLIPSLCD Then
		GoSub InitLCDPhillips
	Else
		GoSub InitLCDEpson	
	EndIF	

Return


'************************************************************
'* InitLCDEpson:
'* 
'* Setup commands for and Epson LCD controller
'************************************************************
InitLCDEpson:

  Low LCDRst
  Pause 1
  LCDRst = 1
  Pause 20
  
  dat = $CA : GoSub SendCommand  ' DISCTL
  dat = $00 : GoSub SendData
  dat = $20 : GoSub SendData
  dat = $0A : GoSub SendData

  dat = $BB : GoSub SendCommand  ' COMSCN
  dat = $01 : GoSub SendData
  
  dat = $D1: GoSub SendCommand   ' OSCON
  dat = $94 : GoSub SendCommand  ' SLPOUT
  
  dat = $81 : GoSub SendCommand  ' VOLCTR
  'dat = $28 : GoSub SendData   
  dat = Contrast : GoSub SendData         
  dat = $03 : GoSub SendData
  
  dat = $82 : GoSub SendCommand  ' TMPGRD
  dat = $00 : GoSub SendData  
  
  dat = $20 : GoSub SendCommand  ' PWRCTR
  dat = $0F : GoSub SendData
  
  dat = $A7: GoSub SendCommand   ' DISINV
  dat = $A9: GoSub SendCommand   ' PTLOUT 
  
  dat = $BC : GoSub SendCommand  ' DATCTL
  dat = $00 : GoSub SendData
  dat = $00 : GoSub SendData
  dat = $01 : GoSub SendData
  
  dat = $CE : GoSub SendCommand  ' RGBSET8
  dat = $00 : GoSub SendData
  dat = $02 : GoSub SendData
  dat = $04 : GoSub SendData
  dat = $06 : GoSub SendData
  dat = $08 : GoSub SendData
  dat = $0A : GoSub SendData
  dat = $0C : GoSub SendData
  dat = $0F : GoSub SendData
  dat = $00 : GoSub SendData
  dat = $02 : GoSub SendData
  dat = $04 : GoSub SendData
  dat = $06 : GoSub SendData
  dat = $08 : GoSub SendData
  dat = $0A : GoSub SendData
  dat = $0C : GoSub SendData
  dat = $0F : GoSub SendData
  dat = $00 : GoSub SendData
  dat = $06 : GoSub SendData
  dat = $09 : GoSub SendData
  dat = $0F : GoSub SendData
  
  'dat = $25 : GoSub SendCommand ' NOP
  
  GoSub clearScreen

  Pause 300
    
  dat = $AF : GoSub SendCommand ' DISON	  

  Return

'************************************************************
'* InitLCDPhillips:
'* 
'* Setup commands for and Phillips LCD controller
'************************************************************ 
InitLCDPhillips:

 
	  Low LCDRst
	  Pause 20
	  High LCDRst
	  Pause 20
	  
	  dat = $11 : GoSub SendCommand  ' Sleep_Out
	  dat = $20 : GoSub SendCommand  ' INVON  maybe $20
	  	
	  dat = $3A : GoSub SendCommand  ' COLMOD 
	  dat = $03 : GoSub SendData	   ' 12 bits per pixel
		'dat = $02 : GoSub SendData	   ' 8 bits per pixel 
	 
	  dat = $36 : GoSub SendCommand  ' MADCTL
	  dat = $00 : GoSub SendData	   ' mirror x and y, reverse RGB
	    
	  dat = $25 : GoSub SendCommand  ' SETCON
	  dat = Contrast : GoSub SendData	   ' contast of 30
	    
	    
	  dat = $03 : GoSub SendCommand  ' BSTRON
        
	  dat = $BC : GoSub SendCommand  ' temp frame freq off
	    
	  dat = $BE : GoSub SendCommand  ' temp frame freq off           
	        
	  Pause 200 
	  
	  dat = $29 : GoSub SendCommand  ' DISPON	
	  
	  
	  color = white
	  GoSub clearscreen

  Return

  

'************************************************************
'* Plot:
'* 
'* Paint one pixel on the screen by calling apprioriate sub
'************************************************************ 
Plot:

	IF LCDType == PHILLIPSLCD Then
		GoSub PlotPhillips
	Else	

		GoSub PlotEpson
	
	EndIF		

	Return


'************************************************************
'* Plot:
'* 
'* Paint one pixel on the screen using Epson commands
'************************************************************
PlotEpson:

	  dat = $75   : GoSub SendCommand
	  dat = y + 2 : GoSub SendData
	  dat = 131   : GoSub SendData
	  dat = $15   : GoSub SendCommand
	  dat = x     : GoSub SendData
	  dat = 129   : GoSub SendData
	  dat = $5C   : GoSub SendCommand
	  dat = color : GoSub SendData	  
	  
  Return  

'************************************************************
'* Plot:
'* 
'* Paint one pixel on the screen using Phillips commands
'************************************************************
PlotPhillips:

	  dat = $2B      : GoSub SendCommand
	  'dat = y + 2    : GoSub SendData
	  dat = y        : GoSub SendData	  
	  dat = 132      : GoSub SendData
	  dat = $2A      : GoSub SendCommand
	  dat = x        : GoSub SendData
	  dat = 132      : GoSub SendData
	  dat = $2C      : GoSub SendCommand
	  dat = color>>4 : GoSub SendData
	  dat = color<<4 : GoSub SendData

  Return  
By Level1
#46118
Thanks Coinfree for your swift help!

Spark Fun engineers have also created header files and initialization code with an LPC2148 to work with both displays. The link for code that works with both controllers is on the Nokia product page:
http://www.sparkfun.com/commerce/produc ... cts_id=569

Level1
By Coinfree
#46121
I see you ran the phillips with 8 bit color and the default color mapping, did the colors look washed out on yours?
By Level1
#46124
Yes, there still are issues with the colors. This code will get most people started and we will update the file once we have good fixes.

Thanks for your help.

Level1