'--------------------------------------------------------------------------------------------------
'
'		GLCD_NOKIA.PBP User Reference Guide
'		===================================
'		Release: 1.0
'		Date: July 27, 2011
'		Author: Steve Monfette AKA Mister_e
'		Credits & inspirations: In no specific order
'				  						scalerobotics, 
'				  						Skimask, 
'				  						SKOLS1, 
'				 						Darrel Taylor,
'				  						Fratello, 
'				  						NavMicroSystems, 
'				  						BitManiac,
'				  						and everyone at the following PICBASIC forum thread
'				  						http://www.picbasic.co.uk/forum/showthread.php?t=327
'
'--------------------------------------------------------------------------------------------------
'
'		How to get Started
'		==================
'		Even if GLCD_NOKIA.PBP source looks impressive, it's still quite easy to use.  It's been
'		created with flexibility in mind.  This driver/wrapper will work with any PIC with sufficient
'		RAM, CodeSpace, EEPROM ressources.  Many 12F devices will be enough, but you may need more
'		I/O as the GLCD by itself require 5 I/O... still it's quite possible to do creative stuff
'		with it using some braincells and hardware twists.  
'
'		Ok so, to get started you just need to include the file and configure it the way you want.  
'		Bellow a short example of how to include it in your code using the defaults settings 
'		and assignement stated later in this document.  Assume a PIC16F877 if you feel better, but
'		at least it has to have sufficient codespace to store the whole set of character :s
'
'
@       __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF   
        DEFINE OSC 20
        TRISB = 0
        PORTB = 0   ' By default the Driver will use PORTB... all output to these then
        
        WordA 		VAR WORD 
        ByteA 		VAR BYTE
        CounterA	VAR BYTE
        MyCon   	CON 1234
        
        DEFINE GLCD_2DEC_USED	    ' include the Value to Decimal Conversion routine
        INCLUDE "GLCD_NOKIA.PBP"    ' Obviously add the Nokia Driver/Wrapper 

        WordA = 1024
        ByteA = 128	
        
START:
        ASM
        GLCDCLS ; Clear the screen (if not initialized yet, it will do automatically)
                                       
        GLCDOUT_AT?STR 0,0,"Hello World!"   ; Show String on Line 0
                                            ;
        GLCDOUT_AT?STR 0,1,"WordA = "       ; Show String on Line 1
        GLCDOUT_2DEC?W _WordA               ; And then display the value of WordA 
                                            ; next to.
                                            ;
        GLCDOUT_AT?STR 0,2,"ByteA = "       ; Well... hope 
        GLCDOUT_2DEC?B _ByteA               ; you can  
                                            ; figure out  
        GLCDOUT_AT?STR 0,3,"MyCon = "       ; the really 
        GLCDOUT_2DEC?C _MyCon       		; complicated stuff
                                            ; going on here :D
                                            ;
        GLCDOUT_AT?STR 0,4,"CounterA = "    ;
        ENDASM
DoItAgain:
        
		FOR CounterA = 0 TO 200 STEP 5
@				GLCDOUT_2DEC_AT?B 11,4, _CounterA   ; Display CounterA
				PAUSE 100                           ; zZzZzZz
@				GLCDOUT_AT?STR 11,4, "   "          ; Erase CounterA value area
				NEXT                                ; Done yet?
		GOTO DoItAgain                              ; Even if.. good stuff never die, do it again

'		Easy huh?  So now it's time for you to do some homework, One of the best way to learn more 
'		about this driver/wrapper is to: 
'				1) Read this document (yeah i'm too polite to say RTFM... even iiiiiiiff...)
'				2) Check the whole set of code example providen in the original .ZIP file
'				3) Open the source and see what's under the hood
'				4) Wash & rinse 'till you completely master the beast 
'
'		To the above statements, you could also add:
'				1) Conclude the author is a pretty bad teacher, but might help in case of trouble by using the PICBASIC forum.
'				2) Agreed the author have a life and may not answer to all request within minutes.
'				3) The Source code is providen for free AS-IS and the author take no responsibilities
'				   about anything bad happening related to it's use.  A monkey could get out of your butt,
'				   your nose could bleed popcorn, Barbara Streisand could give you a prank call using E.T.'s
'				   voice... still... the author DON'T CARE!  
'				   However he is enough open minded to share/split any cash YOU could do by using the source ;)
'
'		This said, hope you'll like it and find some good use for it.  In meantime, have fun.
'		For any Hair-pulling/head-banging complaints, please refer to your closest convenience store.
'		They sale beer, coffee and Tylenol... good luck with that!
'
'		Steve
'
'--------------------------------------------------------------------------------------------------
'		
'
'		Available DEFINEs
'		=================
		'
		'		GLCD Controller Configuration/Setting
		'		-------------------------------------
		DEFINE GLCD_CONTRAST 					
				Set the contrast ---------------- (Default = 65)
				
		DEFINE GLCD_TEMPERATURE_COEFFICIENT 	
				Set the temperature coefficient - (Default = 2)
				
		DEFINE GLCD_BIAS 						
				Set the bias -------------------- (Default = 3)
		'
		'		GLCD I/O Assignment
		'		-------------------
		DEFINE GLCD_SCE		
				SCE/Enable pin ------------	(Default = PORTB,0)
				
		DEFINE GLCD_RES		
				RES/RESET pin -------------	(Default = PORTB,1)
				
		DEFINE GLCD_DC		
				DC/Data Command pin -------	(Default = PORTB,2)
				
		DEFINE GLCD_SDO		
				SDO/Serial DataOut/In pin -	(Default = PORTB,3)
				
		DEFINE GLCD_CLK		
				CLK/Clock pin -------------	(Default = PORTB,4)
		
        DEFINE GLCD_OVERRIDE_CE
                This allow to not use the GLCD CE/Chip Enable pin and free one I/O
                handy for 12F devices...  
                Using this DEFINE you must make sure you tie the GLCD CE pin to GND
                Used with care it works fine.
		'
		'		Misc Features
		'		--------------
		DEFINE GLCD_CHAR_IN_EEPROM			
				This save the Font/CustomCharacter lookuptable in the internal EEPROM
									
		DEFINE GLCD_STRING_IN_EEPROM		
				This save the user strings in the internal EEPROM
				
		DEFINE GLCD_USE_SPECIFIC_CHARACTER	
				This allow to use/store a really specific character set.  Handy when dealing 
				with small memory amount or just to save some code/EEPROM space.  
				BTW... Do you really need/use ALL uppercase and lowercase characters?  
				How about the symbols ()[]{}-=*& ... etc?
				
				To do so, you'll need to use some of these
						CHARTABLESTART, 
						ADDCHAR, 
						ADDRANGE,
						ADDCUSTOMCHAR,
						CHARTABLEEND
				macros to define the characters/number/symbol/customchar you want to use.  
				ex:
						DEFINE  GLCD_USE_SPECIFIC_CHARACTER   
						INCLUDE "GLCD_NOKIA.INC"
						
						ASM
						CHARTABLESTART
								ADDCHAR 'T'
								ADDCHAR 'E'
								ADDCHAR 'X'
								ADDCHAR 'a'
								ADDCHAR 'b'
								ADDCHAR '!' 
								ADDCHAR CHR_NUMBERS
								ADDCUSTOMCHAR CHR_CUSTOM_0,0xff,0x80,0xff,0x01,0x01
								ADDCUSTOMCHAR CHR_CUSTOM_1,0xff,0xff,0xff,0xff,0xff
								ADDCUSTOMCHAR CHR_CUSTOM_2,0xFF,0x40,0x20,0x10,0x08
						CHARTABLEEND
						ENDASM
					
					So the above will let you use T,E,X,a,b,!, and all numbers from 0 - 9
					PLUS you also defined 3 custom characters (5x8).  Easy!
					Refer to ADDCHAR for more options

		DEFINE GLCD_CHAR_6X8
				This allow to use 6x8 fonts instead of regular 5x8
				You will use it if you want to generate custom char of 6x8 like 
						- Full squares
						- Corner
						- Gapless lines
						- Meter? 
						- Or more likely if you dump a whole graphic screen
						 
		DEFINE GLCD_2DEC_USED
				This will include the 2DEC routine, so you could display your variable
				value in Decimal representation.
				This define is there for convenience, when not defined, you'll save some codespace
'
'--------------------------------------------------------------------------------------------------				
'
'		Available Macros
'		================
'
'-----< GLCDOUT_AT?CHR x, y, Chr >-----------------------------------------------------------------
				Display a single Character to a specific x,y coordinate
						ex: GLCDOUT_AT?CHR 0,0, "C"
							GLCDOUT_AT?CHR 0,0, CHR_BACKSLASH

'-----< GLCDOUT?CHR MACRO Chr >--------------------------------------------------------------------
        		Display a single character to the current x,y coordinate
        				ex: GLCDOUT?CHR "C"
        					GLCDOUT?CHR 48
			
				You can also use it with the following constants		
						CHR_QUOTE = 39
						CHR_DOUBLE_QUOTE = 34
						CHR_BACKSLASH = 92
						
						ex: GLCDOUT?CHR CHR_BACKSLASH

'-----< GLCDOUT_2DEC_AT?B MACRO x, y, VarIn >------------------------------------------------------
				Display the decimal representationm of a BYTE variable to a specific x,y coordinate
						ex: GLCDOUT_2DEC_AT?B 0,0, _YourByteVar

'-----<	GLCDOUT_2DEC?B MACRO VarIn >---------------------------------------------------------------
				Display the decimal representation of a BYTE variable to the current x,y coordinate
						ex: GLCDOUT_2DEC?B _YourByteVar
		
'-----<	GLCDOUT_2DEC_AT?W MACRO x, y, VarIn >------------------------------------------------------
				Display the decimal representationm of a WORD variable to a specific x,y coordinate
						ex: GLCDOUT_2DEC_AT?W 0,0, _YourWordVar
							
'-----<	GLCDOUT_2DEC?W MACRO VarIn >---------------------------------------------------------------
				Display the decimal representationm of a WORD variable to the current x,y coordinate
						ex: GLCDOUT_2DEC?W _YourWordVar

'-----<	GLCDOUT_2DEC_AT?C MACRO x, y, VarIn >------------------------------------------------------
				Display the decimal representationm of a CONSTANT to a specific x,y coordinate
						ex: GLCDOUT_2DEC_AT?C 0,0, 1234
							GLCDOUT_2DEC_AT?C 0,0, Constant

'-----<	GLCDOUT_2DEC?C MACRO VarIn >---------------------------------------------------------------
				Display the decimal representationm of a CONSTANT to the current x,y coordinate
						ex: GLCDOUT_2DEC?C 1234
							GLCDOUT_2DEC?C Constant
		
'-----<	GLCDOUT_CMD?C MACRO Cin >------------------------------------------------------------------
        		Send a specific command to the GLCD
				Related Constants (Please refer to the GLCD Datasheet)
				-----------------------------------------------------
						_CLS = 0		    
						_POWER_DOWN = 0x0024
						_VERTICAL = 0x0022
						_EXTENDED_INSTRUCTION_SET = 0x0021
						_BASIC_INSTRUCTION_SET = 0x0020
						_WRITE_DATA = 0x0100
				                '       H = 0
				                '       -----
				                '       DISPLAY_CONTROL = 0x08 
						_BLANK = 0x0008 		 '
						_NORMAL = 0x000C         '
						_ALL_SEGMENT_ON = 0x0009 '
						_INVERSE_VIDEO = 0x000D  '
						                		 '              
						_SET_Y = 0x0040 		 ' Y<2:0> 0 <= Y <= 5
						_SET_X = 0x0080       	 ' X<6:0> 0 <= Y <= 83
				                '        	
				                '       H = 1
				                '       -----         
						_SET_TEMPERATURE_COEFFICIENT = 0x8004 ' (0 - 3) 
						_SET_BIAS = 0x8010                    ' (0 - 7)
						_SET_CONTRAST = 0x8080 
				-------------------------------------------------------		 
               		ex: GLCDOUT_CMD?C (_SET_CONTRAST + GLCD_CONTRAST) 
               			GLCDOUT_CMD?C _BLANK
               			
'-----<	GLCDOUT_CMD?CB MACRO Command, Parameter >---------------------------------------------------
				Send a specific command to the GLCD
				Almost the same as GLCDOUT_CMD?C but have 2 parameters
					ex:  GLCDOUT_CMD?CB _SET_CONTRAST, _ByteVariable
		
'-----<	GLCD_CLS MACRO >----------------------------------------------------------------------------
				Clear the whole GLCD screen

'-----<	GLCD_GOTOXY MACRO x,y >---------------------------------------------------------------------
				Move to a specific x,y coordinate
					ex: GLCD_GOTOXY 0,1
						GLCD_GOTOXY _PosX, _PosY
						
'-----< GLCD_INIT >-------------------------------------------------------------------------
                Initialize the GLCD
                    EX: GLCD_INIT
						
'-----< ADDCHAR MACRO CHR >-------------------------------------------------------------------------
  				Add single or range of ASCII character to the character/font Lookup Table
  		        Related constants  
  		        ------------------------------------------------------------------------------------
						CHR_ALL			Add all characters 		
						CHR_SYMBOLS  	Add all symbols ()8&^%\[]{} etc, those none alphanumeric	
						CHR_NUMBERS 	Add numbers (0-9)
						CHR_LETTERUP	Add UPPERCASE letters (A - Z) 
						CHR_LETTERLOW 	Add lowercase letters (a - z)
				------------------------------------------------------------------------------------
					ex: ADDCHAR 'B'
						ADDCHAR CHR_NUMBERS
						
'-----<	ADDRANGE MACRO RSTART, REND >---------------------------------------------------------------
        		Used to add a range of ASCII Character to the Character LookupTable
        			ex: ADDRANGE 'a', 'm'

'-----<	ADDCUSTOMCHAR   MACRO ChrNum, a,b,c,d,e >---------------------------------------------------		
		ADDCUSTOMCHAR   MACRO ChrNum, a,b,c,d,e,f
				Define user custom character.
				If you add DEFINE GLCD_CHAR_6X8 to your code, you'll be able to generate 6x8 custom
				characters. 
	
'-----<	CHARTABLESTART MACRO >----------------------------------------------------------------------
        		Define the Start Address of the Character LookupTable
        CHARTABLEEND MACRO      
				Define the End Address of the Character LookupTable
		
				Those two above works together with DEFINE GLCD_USE_SPECIFIC_CHARACTER 
				Refer to DEFINE GLCD_USE_SPECIFIC_CHARACTER for an example of how to use it
                                                                                              
'---------------------------------------------------------------------------------------------------
