ST7565R GLcd Component

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

ST7565R GLcd Component

Post by Nico595 »

Hi,

I have a Flowcode V5.5 ARM and I search ST7565R GLcd Component. I try with old version of Custom.c but I have many problem.

Code: Select all

t.c:6080: error: 'portd' undeclared (first use in this function)
t.c:6080: error: (Each undeclared identifier is reported only once
t.c:6080: error: for each function it appears in.)
t.c: At top level:
t.c:6090: error: conflicting types for 'MX_Write_Command'
t.c:6071: error: previous declaration of 'MX_Write_Command' was here
t.c: In function 'MX_Write_Command':
t.c:6091: error: 'portd' undeclared (first use in this function)
t.c:6094: error: 'trisb' undeclared (first use in this function)
t.c:6095: error: 'portb' undeclared (first use in this function)
t.c: In function 'MX_WriteData':
t.c:6129: error: 'portd' undeclared (first use in this function)
t.c:6132: error: 'trisb' undeclared (first use in this function)
t.c:6142: error: 'portb' undeclared (first use in this function)
t.c: In function 'MX_ReadData':
t.c:6170: error: 'portb' undeclared (first use in this function)
t.c:6171: error: 'trisb' undeclared (first use in this function)
t.c:6172: error: 'portd' undeclared (first use in this function)
t.c: In function 'FCD_Custom0_LCD_Init':
t.c:6199: error: 'trisb' undeclared (first use in this function)
t.c:6200: error: 'portb' undeclared (first use in this function)
t.c:6203: error: 'trisd' undeclared (first use in this function)
t.c:6209: error: 'portd' undeclared (first use in this function)

and 

t.c:6050: error: syntax error before 'char'
...
Custom.c for ST7565R

Code: Select all

/*********************************************************************
 *                    Flowcode Custom Component Code
 *
 * File: Custom_Code.c
 *
 * (c) 2008 Matrix Multimedia Ltd.
 * http://www.matrixmultimedia.com
 *
 * Software License Agreement
 *
 * The software supplied herewith by Matrix Multimedia Ltd (the
 * “Company”) for its Flowcode graphical programming language is
 * intended and supplied to you, the Company’s customer, for use
 * solely and exclusively on the Company's products. The software
 * is owned by the Company, and is protected under applicable
 * copyright laws. All rights are reserved. Any use in violation
 * of the foregoing restrictions may subject the user to criminal
 * sanctions under applicable laws, as well as to civil liability
 * for the breach of the terms and conditions of this licence.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Changelog:
 *
 *  date  | by | description
 * -------+----+-----------------------------------------------------
 * 050508 | BR | Created
 *
 *
 *
 ********************************************************************/

/*********************************************************************

 Return & parameter types:
   void
   char
   short
   char*

 Pin directions:
   0 = OUTPUT
   2 = INPUT
   3 = BIDIRECTIONAL

 Macro substitutions:
   %a = ??
   %b = ??
   %c = ??
   %d = ??
   %e = ??
   %f = ??
   %g = ??
   %h = ??
   %i = ??
   %j = ??

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

[Settings]
CLSID={4B174520-75AB-4B14-A0F7-2AA6C203F1DC}
IsAnalogue=0
MultipleAllowed=0
Description=Custom Flowcode Component

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

[Port]
DesiredPort=0
PortMandatory=0
SamePortAsID=0

[Pins]
Count=0

[PinPort]
# PORTA = 0
# PORTB = 1
# PORTC = 2
# PORTD = 3
# PORTE = 4

[PinDesiredBit]

[PinDirection]
# DIR_INPUT = 2
# DIR_OUTPUT = 0
# DIR_BIDIRECTIONAL = 3

[PinMustUsePort]
# char

[SamePortAsPinX]
# -1 = any pin
# otherwise, the pin number

[PinMustUsePin]
# char

[PinValue]
# char (0 = off, 1 = on)

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

[MacroNames]
Count=9
1=GetDefines
2=LCD_Init
3=LCD_Clear
4=LCD_PlotPixel
5=LCD_Draw_Line
6=LCD_Draw_Rect
7=LCD_Print_String
8=LCD_Print_Number
9=LCD_Invert_Rect

[MacroReturns]
1=void
2=void
3=void
4=void
5=void
6=void
7=void
8=void
9=void

[MacroIsPrivate]
1=1
2=0
3=0
4=0
5=0
6=0
7=0
8=0
9=0

[MacroParameters_GetDefines]
Count=0

[MacroParamTypes_GetDefines]


[MacroParameters_LCD_Init]
Count=0

[MacroParamTypes_LCD_Init]


[MacroParameters_LCD_Clear]
Count=0

[MacroParamTypes_LCD_Clear]


[MacroParameters_LCD_PlotPixel]
Count=3
1=x
2=y
3=colour

[MacroParamTypes_LCD_PlotPixel]
1=char
2=char
3=char

[MacroParameters_LCD_Draw_Line]
Count=5
1=x
2=y
3=x2
4=y2
5=colour

[MacroParamTypes_LCD_Draw_Line]
1=char
2=char
3=char
4=char
5=char

[MacroParameters_LCD_Draw_Rect]
Count=5
1=x
2=y
3=width
4=height
5=colour

[MacroParamTypes_LCD_Draw_Rect]
1=char
2=char
3=char
4=char
5=char

[MacroParameters_LCD_Print_String]
Count=6
1=String
2=X
3=Y
4=Font
5=Transparent
6=Colour

[MacroParamTypes_LCD_Print_String]
1=char*
2=char
3=char
4=char
5=char
6=char

[MacroParameters_LCD_Print_Number]
Count=6
1=Number
2=X
3=Y
4=Font
5=Transparent
6=Colour

[MacroParamTypes_LCD_Print_Number]
1=short
2=char
3=char
4=char
5=char
6=char

[MacroParameters_LCD_Invert_Rect]
Count=4
1=x
2=y
3=width
4=height

[MacroParamTypes_LCD_Invert_Rect]
1=char
2=char
3=char
4=char


 ********************************************************************/

/********************************************************************
 * ADDITIONAL CODE
 ********************************************************************/

/*InitialisationCode_Start*/
/*InitialisationCode_End*/

/*InterruptCode_Start*/
/*InterruptCode_End*/


/********************************************************************
 * FUNCTIONS
 ********************************************************************/

void GetDefines()
{
/*Macro_GetDefines_Start*/

}  //Dummy end of function to allow defines to be added correctly

//Flowcode Defines
#define MX_DATA_PORT 			portb	//%a
#define MX_DATA_TRIS 			trisb	//%b
#define MX_CONTROL_PORT			portd	//%c
#define MX_CONTROL_TRIS			trisd	//%d
#define MX_CS1					0		//%e    - CS1
#define MX_CON_RES				3		//%f	- /RST
#define MX_DAT_INST				4		//%g	- A0
#define MX_READ_WRITE			5		//%h	- /WR
#define MX_ENABLE				6		//%i	- /RD


//Static defines
#define MX_BLACK			0xFF
#define MX_WHITE			0x00


//ASCII Pixel data
rom char* ASCII1 = {0x00 , 0x00 , 0x00 , 0x00 , 0x00,       // space // 32  - 43
					0x00 , 0x06 , 0x5F , 0x06 , 0x00,       // !
					0x07 , 0x03 , 0x00 , 0x07 , 0x03,       // ''
					0x24 , 0x7E , 0x24 , 0x7E , 0x24,       // #
					0x24 , 0x2B , 0x6A , 0x12 , 0x00,       // $
					0x63 , 0x13 , 0x08 , 0x64 , 0x63,       // %
					0x36 , 0x49 , 0x56 , 0x20 , 0x50,       // &
					0x00 , 0x07 , 0x03 , 0x00 , 0x00,       // '
					0x00 , 0x3E , 0x41 , 0x00 , 0x00,       // (
					0x00 , 0x41 , 0x3E , 0x00 , 0x00,       // )
					0x08 , 0x3E , 0x1C , 0x3E , 0x08,       // *
					0x08 , 0x08 , 0x3E , 0x08 , 0x08};      // +
rom char* ASCII2 = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00,       // , // 44 - 55
					0x08 , 0x08 , 0x08 , 0x08 , 0x08,       // -
					0x00 , 0x60 , 0x60 , 0x00 , 0x00,       // .
					0x20 , 0x10 , 0x08 , 0x04 , 0x02,       // /
					0x3E , 0x51 , 0x49 , 0x45 , 0x3E,       // 0
					0x00 , 0x42 , 0x7F , 0x40 , 0x00,       // 1
					0x62 , 0x51 , 0x49 , 0x49 , 0x46,       // 2
					0x22 , 0x49 , 0x49 , 0x49 , 0x36,       // 3
					0x18 , 0x14 , 0x12 , 0x7F , 0x10,       // 4
					0x2F , 0x49 , 0x49 , 0x49 , 0x31,       // 5
					0x3C , 0x4A , 0x49 , 0x49 , 0x30,       // 6
					0x01 , 0x71 , 0x09 , 0x05 , 0x03};      // 7
rom char* ASCII3 = {0x36 , 0x49 , 0x49 , 0x49 , 0x36,       // 8 // 56 - 67
					0x06 , 0x49 , 0x49 , 0x29 , 0x1E,       // 9
					0x00 , 0x6C , 0x6C , 0x00 , 0x00,       // :
					0x00 , 0xEC , 0x6C , 0x00 , 0x00,       // ;
					0x08 , 0x14 , 0x22 , 0x41 , 0x00,       // <
					0x24 , 0x24 , 0x24 , 0x24 , 0x24,       // =
					0x00 , 0x41 , 0x22 , 0x14 , 0x08,       // >
					0x02 , 0x01 , 0x59 , 0x09 , 0x06,       // ?
					0x3E , 0x41 , 0x5D , 0x55 , 0x1E,       // @
					0x7E , 0x09 , 0x09 , 0x09 , 0x7E,       // A
					0x7F , 0x49 , 0x49 , 0x49 , 0x36,       // B
					0x3E , 0x41 , 0x41 , 0x41 , 0x22};      // C
rom char* ASCII4 = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E,       // D // 68 - 79
					0x7F , 0x49 , 0x49 , 0x49 , 0x41,       // E
					0x7F , 0x09 , 0x09 , 0x09 , 0x01,       // F
					0x3E , 0x41 , 0x49 , 0x49 , 0x7A,       // G
					0x7F , 0x08 , 0x08 , 0x08 , 0x7F,       // H
					0x00 , 0x41 , 0x7F , 0x41 , 0x00,       // I
					0x30 , 0x40 , 0x40 , 0x40 , 0x3F,       // J
					0x7F , 0x08 , 0x14 , 0x22 , 0x41,       // K
					0x7F , 0x40 , 0x40 , 0x40 , 0x40,       // L
					0x7F , 0x02 , 0x04 , 0x02 , 0x7F,       // M
					0x7F , 0x02 , 0x04 , 0x08 , 0x7F,       // N
					0x3E , 0x41 , 0x41 , 0x41 , 0x3E};      // O
rom char* ASCII5 = {0x7F , 0x09 , 0x09 , 0x09 , 0x06,       // P // 80 - 91
					0x3E , 0x41 , 0x51 , 0x21 , 0x5E,       // Q
					0x7F , 0x09 , 0x09 , 0x19 , 0x66,       // R
					0x26 , 0x49 , 0x49 , 0x49 , 0x32,       // S
					0x01 , 0x01 , 0x7F , 0x01 , 0x01,       // T
					0x3F , 0x40 , 0x40 , 0x40 , 0x3F,       // U
					0x1F , 0x20 , 0x40 , 0x20 , 0x1F,       // V
					0x3F , 0x40 , 0x3C , 0x40 , 0x3F,       // W
					0x63 , 0x14 , 0x08 , 0x14 , 0x63,       // X
					0x07 , 0x08 , 0x70 , 0x08 , 0x07,       // Y
					0x71 , 0x49 , 0x45 , 0x43 , 0x00,       // Z
					0x00 , 0x7F , 0x41 , 0x41 , 0x00};      // [
rom char* ASCII6 = {0x02 , 0x04 , 0x08 , 0x10 , 0x20,       // \ // 92 - 103
					0x00 , 0x41 , 0x41 , 0x7F , 0x00,       // ]
					0x04 , 0x02 , 0x01 , 0x02 , 0x04,       // ^
					0x80 , 0x80 , 0x80 , 0x80 , 0x80,       // _
					0x00 , 0x03 , 0x07 , 0x00 , 0x00,       // `
					0x20 , 0x54 , 0x54 , 0x54 , 0x78,       // a
					0x7F , 0x44 , 0x44 , 0x44 , 0x38,       // b
					0x38 , 0x44 , 0x44 , 0x44 , 0x28,       // c
					0x38 , 0x44 , 0x44 , 0x44 , 0x7F,       // d
					0x38 , 0x54 , 0x54 , 0x54 , 0x18,       // e
					0x08 , 0x7E , 0x09 , 0x09 , 0x00,       // f
					0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C};      // g
rom char* ASCII7 = {0x7F , 0x04 , 0x04 , 0x78 , 0x00,       // h // 104 - 115
					0x00 , 0x00 , 0x7D , 0x00 , 0x00,       // i
					0x40 , 0x80 , 0x84 , 0x7D , 0x00,       // j
					0x7F , 0x10 , 0x28 , 0x44 , 0x00,       // k
					0x00 , 0x00 , 0x7F , 0x40 , 0x00,       // l
					0x7C , 0x04 , 0x18 , 0x04 , 0x78,       // m
					0x7C , 0x04 , 0x04 , 0x78 , 0x00,       // n
					0x38 , 0x44 , 0x44 , 0x44 , 0x38,       // o
					0xFC , 0x44 , 0x44 , 0x44 , 0x38,       // p
					0x38 , 0x44 , 0x44 , 0x44 , 0xFC,       // q
					0x44 , 0x78 , 0x44 , 0x04 , 0x08,       // r
					0x08 , 0x54 , 0x54 , 0x54 , 0x20};      // s
rom char* ASCII8 = {0x04 , 0x3E , 0x44 , 0x24 , 0x00,       // t // 116 - 126
					0x3C , 0x40 , 0x20 , 0x7C , 0x00,       // u
					0x1C , 0x20 , 0x40 , 0x20 , 0x1C,       // v
					0x3C , 0x60 , 0x30 , 0x60 , 0x3C,       // w
					0x6C , 0x10 , 0x10 , 0x6C , 0x00,       // x
					0x9C , 0xA0 , 0x60 , 0x3C , 0x00,       // y
					0x64 , 0x54 , 0x54 , 0x4C , 0x00,       // z
					0x08 , 0x3E , 0x41 , 0x41 , 0x00,       // {
					0x00 , 0x00 , 0x7F , 0x00 , 0x00,       // |
					0x00 , 0x41 , 0x41 , 0x3E , 0x08,       // }
					0x02 , 0x01 , 0x02 , 0x01 , 0x00};      // ~


//Global Variables
char mx_page;
char mx_currentx;
char mx_currenty;


//Internal Prototypes
void MX_LCD_Enable (void);
void MX_Write_Command(char cmd, char chip);
void GotoXY(char x, char y);
void MX_WriteData(char data);
char MX_ReadData(void);


//Internal Functions
void MX_LCD_Enable (void)
{
	set_bit(MX_CONTROL_PORT, MX_ENABLE);
	nop();
	nop();
	clear_bit(MX_CONTROL_PORT, MX_ENABLE);
	nop();
	nop();
}


void MX_Write_Command (char cmd)
{
	clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);	//Write Command
	clear_bit(MX_CONTROL_PORT, MX_DAT_INST);	//Instruction code
	clear_bit(MX_CONTROL_PORT, MX_CS1);
	MX_DATA_TRIS = 0x00;						//Configure data port as output
	MX_DATA_PORT = cmd;
	MX_LCD_Enable();
	MX_DATA_PORT = 0x00;
	set_bit(MX_CONTROL_PORT, MX_CS1);
}


void MX_GotoXY (char x, char y)
{
	char page, columnl, columnh;

	page = (y / 8) | 0xB0;
	columnh = (x >> 4) | 0x10;
	columnl = x & 0x0F;

	if(x > 127) x = 0;							//Ensure that coordinates are legal
	if(y > 63)  y = 0;

	mx_currentx = x;
	mx_currenty = y;
	mx_page = y / 8;

	MX_Write_Command(0x40);						//set display start line
	MX_Write_Command(page);						//set page address
	MX_Write_Command(columnh);					//set column address
	MX_Write_Command(columnl);
}



void MX_WriteData (char data)
{
	char displayData, yOffset, cmdPort;

	set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data
	clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to write data
	clear_bit(MX_CONTROL_PORT, MX_CS1);
	MX_DATA_TRIS = 0x00;							//Configure data port to Output
	yOffset = mx_currenty % 8;

	if(yOffset != 0) 								//First page?
	{
		cmdPort = MX_CONTROL_PORT;					//Save command port
		displayData = MX_ReadData();
		MX_CONTROL_PORT = cmdPort;					//Restore command port
		MX_DATA_TRIS = 0x00;						//Data port is output
		displayData = displayData | (data << yOffset);
		MX_DATA_PORT = displayData;					//Write data
		MX_LCD_Enable();							//Enable

		// second page
		MX_GotoXY(mx_currentx, (mx_currenty + 8));
		displayData = MX_ReadData();
		MX_CONTROL_PORT = cmdPort;					//Restore command port
		MX_DATA_TRIS = 0x00;						//Data port is output
		displayData = displayData | (data >> (8-yOffset));
		MX_DATA_PORT = displayData;					//Write data
		MX_LCD_Enable();							//Enable
		MX_GotoXY(mx_currentx + 1, (mx_currenty - 8));
	}
	else
	{
		MX_DATA_PORT = data;						//Write data
		MX_LCD_Enable();							//Enable
		mx_currentx = mx_currentx + 1;
	}
	MX_DATA_PORT = 0x00;
	set_bit(MX_CONTROL_PORT, MX_CS1);
}


char MX_ReadData (void)
{
	char data, i;

	MX_DATA_PORT = 0x00;
	MX_DATA_TRIS = 0xFF;							//Data port is input
	set_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to read data
	set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data
	clear_bit(MX_CONTROL_PORT, MX_CS1);
	nop();
	nop();
	data = MX_DATA_PORT;							//Read Data
	MX_DATA_TRIS = 0x00;							//Configure port as output
	set_bit(MX_CONTROL_PORT, MX_CS1);
	MX_GotoXY(mx_currentx, mx_currenty);
	return data;
}


// Dummy function to close the defines section off
void CUSTOM_Dummy_Function();
void CUSTOM_Dummy_Function()
{

/*Macro_GetDefines_End*/
}



void LCD_Init ()
{
/*Macro_LCD_Init_Start*/

	mx_currentx = 0;
	mx_currenty = 0;
	mx_page = 0;

	MX_DATA_TRIS = 0x00;								//Convert data port to output
	MX_DATA_PORT = 0x00;


	clear_bit(MX_CONTROL_TRIS, MX_ENABLE);				//Convert control pins to output
	clear_bit(MX_CONTROL_TRIS, MX_DAT_INST);
	clear_bit(MX_CONTROL_TRIS, MX_CS1);
	clear_bit(MX_CONTROL_TRIS, MX_CON_RES);
	clear_bit(MX_CONTROL_TRIS, MX_READ_WRITE);

	clear_bit(MX_CONTROL_PORT, MX_ENABLE);
	clear_bit(MX_CONTROL_PORT, MX_READ_WRITE);			//Write Command
	clear_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Instruction code
	set_bit(MX_CONTROL_PORT, MX_CS1);
	clear_bit(MX_CONTROL_PORT, MX_CON_RES);				//Make sure device is in reset mode

	delay_10us(1);										//Allow display power to stabilise
	set_bit(MX_CONTROL_PORT, MX_CON_RES);				//Switch on device
	delay_ms(1);										//Wait for device to reach initialised state

	//Commands

	MX_Write_Command(0xA2);		//11 LCD BIAS
	MX_Write_Command(0xA0);		//8 ADC Selection
	MX_Write_Command(0xC8);		//15 Common Output Mode
	MX_Write_Command(0x25);		//17 Regulator Resistor Ratio
	MX_Write_Command(0x81);		//18 Electronic Volume Control
	MX_Write_Command(0x20);		//18 Electronic Volume Register Set
	MX_Write_Command(0xF8);		//16 Booster Ratio 4x
	MX_Write_Command(0x00);
	MX_Write_Command(0x2F);		//Power Control


	LCD_Draw_Rect(0, 0, 127, 63, MX_WHITE);		//Initialise DDRAM

	MX_Write_Command(0xAC);		//Static indicator off
	MX_Write_Command(0xA6);		//Normal Display

	MX_GotoXY(0,0);

/*Macro_LCD_Init_End*/
}


void LCD_Clear ()
{
/*Macro_LCD_Clear_Start*/
	LCD_Draw_Rect(0, 0, 127, 63, MX_WHITE);
/*Macro_LCD_Clear_End*/
}


void LCD_PlotPixel (char x, char y, char colour)
{
/*Macro_LCD_PlotPixel_Start*/
	char data, mod_y;

	mod_y = y%8;
	MX_GotoXY(x, y);
	data = MX_ReadData();							//Read 8 pixels from display
	if (colour)
		data = data | (0x01 << mod_y);				//Set Pixel
	else
		data = data & (~(0x01 << mod_y));			//Clear Pixel
	MX_WriteData(data);
/*Macro_LCD_PlotPixel_End*/
}



void LCD_Draw_Line (char x, char y, char x2, char y2, char colour)
{
/*Macro_LCD_Draw_Line_Start*/
	int C1, M1;
	signed int D1 = 0;
	signed int Pixelx = x2 - x;    //number of X-pixels;
	signed int Pixely = y2 - y;    //Number of Y-pixels
	signed char Xinc = 1;
	signed char Yinc = 1;

	if (Pixelx < 0)        //If negative X direction
	{
		Xinc = -1;
		Pixelx = Pixelx * -1;
	}
	if (Pixely < 0)        //If negative Y direction
	{
		Yinc = -1;
		Pixely = Pixely * -1;
	}
	if (Pixely <= Pixelx)
	{
		C1 = 2 * Pixelx;
		M1 = 2 * Pixely;
		while (x != x2)
		{
			LCD_PlotPixel(x, y, colour);    //ForePlot line
			x = x + Xinc;
			D1 = D1 + M1;
			if (D1 > Pixelx)
			{
				y = y + Yinc;
				D1 = D1 - C1;
			}
		}
	}
	else
	{
		C1 = 2 * Pixely;
		M1 = 2 * Pixelx;
		while (y != y2)
		{
			LCD_PlotPixel(x, y, colour);    //ForePlot Line
			y = y + Yinc;
			D1 = D1 + M1;
			if (D1 > Pixely)
			{
				x = x + Xinc;
				D1 = D1 - C1;
			}
		}
		LCD_PlotPixel(x, y, colour);
	}
/*Macro_LCD_Draw_Line_End*/
}


void LCD_Draw_Rect (char x, char y, char width, char height, char colour)
{
/*Macro_LCD_Draw_Rect_Start*/
	char mask, pageOffset, h, i, data;

	if(colour)
		colour = 255;

	height = height + 1;

	pageOffset = y % 8;
	y = y - pageOffset;
	mask = 0xFF;

	if(height < (8 - pageOffset))
	{
		mask = mask >> (8-height);
		h = height;
	}
	else
		h = (8 - pageOffset);

	mask = mask << pageOffset;

	MX_GotoXY(x, y);

	for(i=0; i<=width; i++)
	{
		data = MX_ReadData();
		if(colour)
			data = data | mask;
		else
			data = data & (~mask);

		MX_WriteData(data);
	}

	while((h + 8) <= height)
	{
		h = h + 8;
		y = y + 8;
		MX_GotoXY(x, y);

		for(i=0; i<=width; i++)
			MX_WriteData(colour);
	}

	if(h < height)
	{
		mask = ~(0xFF << (height - h));
		MX_GotoXY(x, (y + 8));

		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();

			if(colour)
				data = data | mask;
			else
				data = data & (~mask);

			MX_WriteData(data);
		}
	}
/*Macro_LCD_Draw_Rect_End*/
}



void LCD_Print_String (char* String, char X, char Y, char Font, char Transparent, char Colour)
{
/*Macro_LCD_Print_String_Start*/
    char xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
    char Fontwidth = 1;                //First we assume small font
    char Fontheight = 1;
	char inv_colour = 1;

    char temp[6];
    temp[5] = 0x00;                        //Spacing Line

	if (Colour)
		inv_colour = 0;

    if (Font == 1)                     	//Double Height Sizes //Double Width
    {
        Fontwidth = 2;
    }
    if (Font == 2)                         //Double Height and Width Sizes
    {
        Fontwidth = 2;
        Fontheight = 2;
    }
    if (Font == 3)                         //Double Height Sizes
    {
        Fontheight = 2;
    }

    xcount = 0;
    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
    {
        if (String[i] == 0)
        	return;
        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

        for (count = 0; count < 5; count++)        //Use correct buffer location
        {
            if (pos_Str < 12)
            {
                temp[count]=ASCII1[(pos_Str*5)+count];
            }
            else if (pos_Str < 24)
            {
                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
            }
            else if (pos_Str < 36)
            {
                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
            }
            else if (pos_Str < 48)
            {
                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
            }
            else if (pos_Str < 60)
            {
                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
            }
            else if (pos_Str < 72)
            {
                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
            }
            else if (pos_Str < 84)
            {
                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
            }
            else if (pos_Str < 95)
            {
                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
            }
        }
        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
        {
            for (width=0;width<Fontwidth;width++)
            {
                ycount = 0;
                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
                {
                    for (height=0;height<Fontheight;height++)
                    {
                        if (test_bit(temp[xpix],ypix))
                        {
                            LCD_PlotPixel(X + xcount, Y + ycount, Colour);
                        }
                        else if (Transparent == 0)
                        {
                            LCD_PlotPixel(X+xcount, Y+ycount, inv_colour);
                        }
                        ycount++;
                    }
                }
                xcount++;
            }
        }
    }
/*Macro_LCD_Print_String_End*/
}


void LCD_Print_Number (short Number, char X, char Y, char Font, char Transparent, char Colour)
{
/*Macro_LCD_Print_Number_Start*/
	char string_length;

	if (Number < -10000	)
		string_length = 6;

	else if(Number > 10000 || Number < -1000)
		string_length = 5;

	else if(Number > 1000 || Number < -100)
		string_length = 4;

	else if(Number > 100 || Number < -10)
		string_length = 3;

	else if(Number > 10 || Number < -1)
		string_length = 2;

	else
		string_length = 1;

	char temp_str[6];

	FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
	LCD_Print_String(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
/*Macro_LCD_Print_Number_End*/
}



void LCD_Invert_Rect (char x, char y, char width, char height)
{
/*Macro_LCD_Invert_Rect_Start*/
	char mask, pageOffset, h, i, data, tmpData;
	height++;

	pageOffset = y % 8;
	y = y - pageOffset;
	mask = 0xFF;
	if(height < (8 - pageOffset))
	{
		mask = mask >> (8-height);
		h = height;
	}
	else
	{
		h = 8 - pageOffset;
	}
	mask = mask << pageOffset;

	MX_GotoXY(x, y);
	for(i=0; i<=width; i++)
	{
		data = MX_ReadData();
		tmpData = ~data;
		data = (tmpData & mask) | (data & ~mask);
		MX_WriteData(data);
	}

	while((h + 8) <= height)
	{
		h = h + 8;
		y = y + 8;
		MX_GotoXY(x, y);

		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			MX_WriteData(~data);
		}
	}

	if(h < height)
	{
		mask = ~(0xFF << (height-h));
		MX_GotoXY(x, y+8);

		for(i=0; i<=width; i++)
		{
			data = MX_ReadData();
			tmpData = ~data;
			data = (tmpData & mask) | (data & ~mask);
			MX_WriteData(data);
		}
	}
/*Macro_LCD_Invert_Rect_End*/
}

Thank you very much

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I have replaced in Custom.c

Code: Select all

rom char*
with

Code: Select all

const char
But I have a problem with port declaration

Code: Select all

t.c:6015: error: conflicting types for 'MX_Write_Command'
t.c:5996: error: previous declaration of 'MX_Write_Command' was here
t.c: In function 'MX_Write_Command':
t.c:6016: error: 'portd' undeclared (first use in this function)
t.c:6019: error: 'trisb' undeclared (first use in this function)
t.c:6020: error: 'portb' undeclared (first use in this function)
t.c: In function 'MX_WriteData':
t.c:6054: error: 'portd' undeclared (first use in this function)
t.c:6057: error: 'trisb' undeclared (first use in this function)
t.c:6067: error: 'portb' undeclared (first use in this function)
t.c: In function 'MX_ReadData':
t.c:6095: error: 'portb' undeclared (first use in this function)
t.c:6096: error: 'trisb' undeclared (first use in this function)
t.c:6097: error: 'portd' undeclared (first use in this function)
t.c: In function 'FCD_Custom0_LCD_Init':
t.c:6124: error: 'trisb' undeclared (first use in this function)
t.c:6125: error: 'portb' undeclared (first use in this function)
t.c:6128: error: 'trisd' undeclared (first use in this function)
t.c:6134: error: 'portd' undeclared (first use in this function)
Hard config:

SPI
SData: PA13 / PB5
SClk: PA14 / PB6
CS: PA31 / PD7
----
RST: PA27 / PD3
A0: PA28 / PD4
Last edited by Nico595 on Mon Oct 14, 2013 9:27 am, edited 1 time in total.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

The team is gone for the weekend without answer for me :cry: :cry: :cry:

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I try with SPI Component, Init sequence is OK but I can't display a line or letter.

SPI Component: fosc/64, idle_low, Data transmit on rising clock edge

Dispaly is ST7565R 128x64 in SPI mode only, like this:
Image

Hardware:
http://artronic.pl/o_produkcie.php?id=1144?

ST7565R codes:
http://asf.atmel.com/docs/2.11.1/xmegad ... group.html

ST7565R process:
http://www.google.fr/url?sa=t&rct=j&q=& ... 4254,d.d2k

Thank you for your help

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I found this code, may be help for write ST7565R component for ARM AT91SAM7S

http://code.google.com/p/lpc1343codebas ... ap/st7565/

Code: Select all

/**************************************************************************/
/*! 
    @file     ST7565.h
    @author   K. Townsend (microBuilder.eu)
    @date     22 March 2010
    @version  0.10


    @section LICENSE


    Software License Agreement (BSD License)


    Copyright (c) 2010, microBuilder SARL
    All rights reserved.


    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
    1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
    3. Neither the name of the copyright holders nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.


    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#ifndef __ST7565_H__
#define __ST7565_H__


#include "projectconfig.h"


#include "drivers/lcd/smallfonts.h"


// Pin Definitions
#define ST7565_A0_PORT                    (2)     // Register Select Pin (A0)
#define ST7565_A0_PIN                     (1)
#define ST7565_RST_PORT                   (2)     // Reset
#define ST7565_RST_PIN                    (2)
#define ST7565_CS_PORT                    (2)     // Select
#define ST7565_CS_PIN                     (3)
#define ST7565_BL_PORT                    (2)     // Backlight
#define ST7565_BL_PIN                     (4)
#define ST7565_SCLK_PORT                  (2)     // Serial Clock
#define ST7565_SCLK_PIN                   (5)
#define ST7565_SDAT_PORT                  (2)     // Serial Data
#define ST7565_SDAT_PIN                   (6)


// Commands
#define ST7565_CMD_DISPLAY_OFF            0xAE
#define ST7565_CMD_DISPLAY_ON             0xAF
#define ST7565_CMD_SET_DISP_START_LINE    0x40
#define ST7565_CMD_SET_PAGE               0xB0
#define ST7565_CMD_SET_COLUMN_UPPER       0x10
#define ST7565_CMD_SET_COLUMN_LOWER       0x00
#define ST7565_CMD_SET_ADC_NORMAL         0xA0
#define ST7565_CMD_SET_ADC_REVERSE        0xA1
#define ST7565_CMD_SET_DISP_NORMAL        0xA6
#define ST7565_CMD_SET_DISP_REVERSE       0xA7
#define ST7565_CMD_SET_ALLPTS_NORMAL      0xA4
#define ST7565_CMD_SET_ALLPTS_ON          0xA5
#define ST7565_CMD_SET_BIAS_9             0xA2 
#define ST7565_CMD_SET_BIAS_7             0xA3
#define ST7565_CMD_RMW                    0xE0
#define ST7565_CMD_RMW_CLEAR              0xEE
#define ST7565_CMD_INTERNAL_RESET         0xE2
#define ST7565_CMD_SET_COM_NORMAL         0xC0
#define ST7565_CMD_SET_COM_REVERSE        0xC8
#define ST7565_CMD_SET_POWER_CONTROL      0x28
#define ST7565_CMD_SET_RESISTOR_RATIO     0x20
#define ST7565_CMD_SET_VOLUME_FIRST       0x81
#define ST7565_CMD_SET_VOLUME_SECOND      0
#define ST7565_CMD_SET_STATIC_OFF         0xAC
#define ST7565_CMD_SET_STATIC_ON          0xAD
#define ST7565_CMD_SET_STATIC_REG         0x0
#define ST7565_CMD_SET_BOOSTER_FIRST      0xF8
#define ST7565_CMD_SET_BOOSTER_234        0
#define ST7565_CMD_SET_BOOSTER_5          1
#define ST7565_CMD_SET_BOOSTER_6          3
#define ST7565_CMD_NOP                    0xE3
#define ST7565_CMD_TEST                   0xF0


// Initialisation/Config Prototypes
void st7565Init( void );
void st7565Command( uint8_t c );
void st7565Data( uint8_t d );
void st7565SetBrightness( uint8_t val );


// Backlight Prototypes
void st7565BLEnable( void );
void st7565BLDisable( void );


// Drawing Prototypes
void st7565ClearScreen( void );
void st7565Refresh( void );
void st7565DrawPixel( uint8_t x, uint8_t y );
void st7565ClearPixel( uint8_t x, uint8_t y );
void st7565DrawString(uint16_t x, uint16_t y, char* text, struct FONT_DEF font);


#endif



Hide details 

Change log
r100 by r...@libnfc.org on Sep 22, 2010   Diff 
fixed capitals for linux compilingGo to: 	 

Sign in to write a code review

Older revisions
All revisions of this file 

File info


Size: 4812 bytes, 110 lines
View raw file

Code: Select all

/**************************************************************************/
/*! 
    @file     ST7565.c
    @author   K. Townsend (microBuilder.eu)


    @section DESCRIPTION


    Driver for 128x64 pixel display based on the ST7565 LCD controller.


    This driver is based on the ST7565 Library from Limor Fried
    (Adafruit Industries) at: http://github.com/adafruit/ST7565-LCD/    
    
    @section LICENSE


    Software License Agreement (BSD License)


    Copyright (c) 2010, microBuilder SARL
    All rights reserved.


    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
    1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
    3. Neither the name of the copyright holders nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.


    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#include <string.h>


#include "st7565.h"


#include "core/gpio/gpio.h"
#include "core/systick/systick.h"
#include "drivers/lcd/smallfonts.h"


void sendByte(uint8_t byte);


#define CMD(c)        do { gpioSetValue( ST7565_A0_PORT, ST7565_A0_PIN, 0 ); sendByte( c ); } while (0);
#define DATA(d)       do { gpioSetValue( ST7565_A0_PORT, ST7565_A0_PIN, 1 ); sendByte( d ); } while (0);
#define DELAY(mS)     do { systickDelay( mS / CFG_SYSTICK_DELAY_IN_MS ); } while(0);


uint8_t buffer[128*64/8];


/**************************************************************************/
/* Private Methods                                                        */
/**************************************************************************/


/**************************************************************************/
/*! 
    @brief Renders the buffer contents


    @param[in]  buffer
                Pointer to the buffer containing the raw pixel data
*/
/**************************************************************************/
void writeBuffer(uint8_t *buffer) 
{
  uint8_t c, p;
  int pagemap[] = { 3, 2, 1, 0, 7, 6, 5, 4 };


  for(p = 0; p < 8; p++) 
  {
    CMD(ST7565_CMD_SET_PAGE | pagemap[p]);
    CMD(ST7565_CMD_SET_COLUMN_LOWER | (0x0 & 0xf));
    CMD(ST7565_CMD_SET_COLUMN_UPPER | ((0x0 >> 4) & 0xf));
    CMD(ST7565_CMD_RMW);
    DATA(0xff);
    
    for(c = 0; c < 128; c++) 
    {
      DATA(buffer[(128*p)+c]);
    }
  }
}


/**************************************************************************/
/*! 
    @brief Simulates an SPI write using GPIO


    @param[in]  byte
                The byte to send
*/
/**************************************************************************/
void sendByte(uint8_t byte)
{
  int8_t i;


  // Note: This code can be optimised to avoid the branches by setting
  // GPIO registers directly, but we'll leave it as is for the moment
  // for simplicity sake


  // Make sure clock pin starts high
  gpioSetValue(ST7565_SCLK_PORT, ST7565_SCLK_PIN, 1);


  // Write from MSB to LSB
  for (i=7; i>=0; i--) 
  {
    // Set clock pin low
    gpioSetValue(ST7565_SCLK_PORT, ST7565_SCLK_PIN, 0);
    // Set data pin high or low depending on the value of the current bit
    gpioSetValue(ST7565_SDAT_PORT, ST7565_SDAT_PIN, byte & (1 << i) ? 1 : 0);
    // Set clock pin high
    gpioSetValue(ST7565_SCLK_PORT, ST7565_SCLK_PIN, 1);
  }
}


/**************************************************************************/
/*!
    @brief  Draws a single graphic character using the supplied font
*/
/**************************************************************************/
void drawChar(uint16_t x, uint16_t y, uint8_t c, struct FONT_DEF font)
{
  uint8_t col, column[font.u8Width];


  // Check if the requested character is available
  if ((c >= font.u8FirstChar) && (c <= font.u8LastChar))
  {
    // Retrieve appropriate columns from font data
    for (col = 0; col < font.u8Width; col++)
    {
      column[col] = font.au8FontTable[((c - 32) * font.u8Width) + col];    // Get first column of appropriate character
    }
  }
  else
  {    
    // Requested character is not available in this font ... send a space instead
    for (col = 0; col < font.u8Width; col++)
    {
      column[col] = 0xFF;    // Send solid space
    }
  }


  // Render each column
  uint16_t xoffset, yoffset;
  for (xoffset = 0; xoffset < font.u8Width; xoffset++)
  {
    for (yoffset = 0; yoffset < (font.u8Height + 1); yoffset++)
    {
      uint8_t bit = 0x00;
      bit = (column[xoffset] << (8 - (yoffset + 1)));     // Shift current row bit left
      bit = (bit >> 7);                     // Shift current row but right (results in 0x01 for black, and 0x00 for white)
      if (bit)
      {
        st7565DrawPixel(x + xoffset, y + yoffset);
      }
    }
  }
}


/**************************************************************************/
/* Public Methods                                                         */
/**************************************************************************/


/**************************************************************************/
/*! 
    @brief Initialises the ST7565 LCD display
*/
/**************************************************************************/
void st7565Init(void)
{
  // Note: This can be optimised to set all pins to output and high
  // in two commands by manipulating the registers directly (assuming
  // that the pins are located in the same GPIO bank).  The code is left
  // as is for clarity sake in case the pins are not all located in the
  // same bank.


  // Set clock pin to output and high
  gpioSetDir(ST7565_SCLK_PORT, ST7565_SCLK_PIN, 1);
  gpioSetValue(ST7565_SCLK_PORT, ST7565_SCLK_PIN, 1);


  // Set data pin to output and high
  gpioSetDir(ST7565_SDAT_PORT, ST7565_SDAT_PIN, 1);
  gpioSetValue(ST7565_SDAT_PORT, ST7565_SDAT_PIN, 1);


  // Configure backlight pin to output and set high (off)
  gpioSetDir(ST7565_BL_PORT, ST7565_BL_PIN, 1);
  gpioSetValue(ST7565_BL_PORT, ST7565_BL_PIN, 1);


  // Configure A0 pin to output and set high
  gpioSetDir(ST7565_A0_PORT, ST7565_A0_PIN, 1);
  gpioSetValue(ST7565_A0_PORT, ST7565_A0_PIN, 1);


  // Configure Reset pin and set high
  gpioSetDir(ST7565_RST_PORT, ST7565_RST_PIN, 1);
  gpioSetValue(ST7565_RST_PORT, ST7565_RST_PIN, 1);


  // Configure select pin and set high
  gpioSetDir(ST7565_CS_PORT, ST7565_CS_PIN, 1);
  gpioSetValue(ST7565_CS_PORT, ST7565_CS_PIN, 1);


  // Reset
  gpioSetValue(ST7565_CS_PORT, ST7565_CS_PIN, 0);     // Set CS low
  gpioSetValue(ST7565_RST_PORT, ST7565_RST_PIN, 0);   // Set reset low
  DELAY(500 / CFG_SYSTICK_DELAY_IN_MS);               // Wait 500mS
  gpioSetValue(ST7565_RST_PORT, ST7565_RST_PIN, 1);   // Set reset high


  // Configure Display
  CMD(ST7565_CMD_SET_BIAS_7);                         // LCD Bias Select
  CMD(ST7565_CMD_SET_ADC_NORMAL);                     // ADC Select
  CMD(ST7565_CMD_SET_COM_NORMAL);                     // SHL Select
  CMD(ST7565_CMD_SET_DISP_START_LINE);                // Initial Display Line
  CMD(ST7565_CMD_SET_POWER_CONTROL | 0x04);           // Turn on voltage converter (VC=1, VR=0, VF=0)
  DELAY(50 / CFG_SYSTICK_DELAY_IN_MS);                // Wait 50mS
  CMD(ST7565_CMD_SET_POWER_CONTROL | 0x06);           // Turn on voltage regulator (VC=1, VR=1, VF=0)
  DELAY(50 / CFG_SYSTICK_DELAY_IN_MS);                // Wait 50mS
  CMD(ST7565_CMD_SET_POWER_CONTROL | 0x07);           // Turn on voltage follower
  DELAY(10 / CFG_SYSTICK_DELAY_IN_MS);                // Wait 10mS
  CMD(ST7565_CMD_SET_RESISTOR_RATIO | 0x6);           // Set LCD operating voltage


  // Turn display on
  CMD(ST7565_CMD_DISPLAY_ON);
  CMD(ST7565_CMD_SET_ALLPTS_NORMAL);
  st7565SetBrightness(0x18);
}


/**************************************************************************/
/*! 
    @brief Enables or disables the backlight
*/
/**************************************************************************/
void st7565Backlight(bool state)
{
  gpioSetValue( ST7565_BL_PORT, ST7565_BL_PIN, state ? 0 : 1 );
}


/**************************************************************************/
/*! 
    @brief Sets the display brightness
*/
/**************************************************************************/
void st7565SetBrightness(uint8_t val)
{
  CMD(ST7565_CMD_SET_VOLUME_FIRST);
  CMD(ST7565_CMD_SET_VOLUME_SECOND | (val & 0x3f));
}


/**************************************************************************/
/*! 
    @brief Clears the screen
*/
/**************************************************************************/
void st7565ClearScreen(void) 
{
  memset(&buffer, 0x00, 128*64/8);
}


/**************************************************************************/
/*! 
    @brief Renders the contents of the pixel buffer on the LCD
*/
/**************************************************************************/
void st7565Refresh(void)
{
  writeBuffer(buffer);
}


/**************************************************************************/
/*! 
    @brief Draws a single pixel in image buffer


    @param[in]  x
                The x position (0..127)
    @param[in]  y
                The y position (0..63)
*/
/**************************************************************************/
void st7565DrawPixel(uint8_t x, uint8_t y) 
{
  if ((x >= 128) || (y >= 64))
    return;


  // x is which column
  buffer[x+ (y/8)*128] |= (1 << (7-(y%8)));
}


/**************************************************************************/
/*! 
    @brief Clears a single pixel in image buffer


    @param[in]  x
                The x position (0..127)
    @param[in]  y
                The y position (0..63)
*/
/**************************************************************************/
void st7565ClearPixel(uint8_t x, uint8_t y)
{
  if ((x >= 128) || (y >= 64))
    return;


  // x is which column
  buffer[x+ (y/8)*128] &= ~(1 << (7-(y%8)));
}


/**************************************************************************/
/*! 
    @brief Gets the value (1 or 0) of the specified pixel from the buffer


    @param[in]  x
                The x position (0..127)
    @param[in]  y
                The y position (0..63)


    @return     1 if the pixel is enabled, 0 if disabled
*/
/**************************************************************************/
uint8_t st7565GetPixel(uint8_t x, uint8_t y)
{
  if ((x >= 128) || (y >= 64)) return 0;
  return buffer[x+ (y/8)*128] & (1 << (7-(y%8)));
}


/**************************************************************************/
/*!
    @brief  Draws a string using the supplied font data.


    @param[in]  x
                Starting x co-ordinate
    @param[in]  y
                Starting y co-ordinate
    @param[in]  text
                The string to render
    @param[in]  font
                Pointer to the FONT_DEF to use when drawing the string


    @section Example


    @code 


    #include "drivers/lcd/bitmap/st7565/st7565.h"
    #include "drivers/lcd/smallfonts.h"
    
    // Configure the pins and initialise the LCD screen
    st7565Init();


    // Enable the backlight
    st7565BLEnable();


    // Render some text on the screen with different fonts
    st7565DrawString(1, 1, "3X6 SYSTEM", Font_System3x6);   // 3x6 is UPPER CASE only
    st7565DrawString(1, 10, "5x8 System", Font_System5x8);
    st7565DrawString(1, 20, "7x8 System", Font_System7x8);


    // Refresh the screen to see the results
    st7565Refresh();


    @endcode
*/
/**************************************************************************/
void st7565DrawString(uint16_t x, uint16_t y, char* text, struct FONT_DEF font)
{
  uint8_t l;
  for (l = 0; l < strlen(text); l++)
  {
    drawChar(x + (l * (font.u8Width + 1)), y, text[l], font);
  }
}


/**************************************************************************/
/*!
    @brief  Shifts the contents of the frame buffer up the specified
            number of pixels


    @param[in]  height
                The number of pixels to shift the frame buffer up, leaving
                a blank space at the bottom of the frame buffer x pixels
                high


    @section Example


    @code 


    #include "drivers/lcd/bitmap/st7565/st7565.h"
    #include "drivers/lcd/smallfonts.h"
    
    // Configure the pins and initialise the LCD screen
    st7565Init();


    // Enable the backlight
    st7565BLEnable();


    // Continually write some text, scrolling upward one line each time
    while (1)
    {
      // Shift the buffer up 8 pixels (adjust for font-height)
      st7565ShiftFrameBuffer(8);
      // Render some text on the screen with different fonts
      st7565DrawString(1, 56, "INSERT TEXT HERE", Font_System3x6);   // 3x6 is UPPER CASE only
      // Refresh the screen to see the results
      st7565Refresh();    
      // Wait a bit before writing the next line
      systickDelay(1000);
    }


    @endcode
*/
/**************************************************************************/
void st7565ShiftFrameBuffer( uint8_t height )
{
  if (height == 0) return;
  if (height >= 64)
  {
    // Clear the entire frame buffer
    st7565ClearScreen();
    return;
  }


  // This is horribly inefficient, but at least easy to understand
  // In a production environment, this should be significantly optimised


  uint8_t y, x;
  for (y = 0; y < 64; y++)
  {
    for (x = 0; x < 128; x++)
    {
      if (63 - y > height)
      {
        // Shift height from further ahead in the buffer
        st7565GetPixel(x, y + height) ? st7565DrawPixel(x, y) : st7565ClearPixel(x, y);
      }
      else
      {
        // Clear the entire line
        st7565ClearPixel(x, y);
      }
    }
  }
}





Hide details 

Change log
r143 by cont...@microbuilder.eu on Jan 26, 2011   Diff 
[No log message]Go to: 	 

Sign in to write a code review

Older revisions
 r142 by cont...@microbuilder.eu on Jan 20, 2011   Diff 
 r131 by cont...@microbuilder.eu on Dec 14, 2010   Diff 
 r106 by cont...@microbuilder.eu on Oct 13, 2010   Diff 
All revisions of this file 

File info
Size: 15138 bytes, 445 lines
View raw file

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ST7565R GLcd Component

Post by Benj »

Hi Nico,

This LCD is supported in v6. would this be an option for you?

Other wise we can use the original C code but we have to get the code for the port access changed so it will compile correctly. Do some writes to the I/O using an output icon and then have a look at the C code produced and see if this can easily plug into the existing definitions.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

Great :(

Thank you for your answer Benj.

Upgrade V5 with V6 is planned, your job is perfect, but I've not this money for the moment.

I try write code in C

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ST7565R GLcd Component

Post by Benj »

Sorry I've been leaving you hanging a bit, lots of internal meetings and such.

Let us know how your getting on and I will dive in and have a go if your struggling.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I write ST7565R code in Custom2.c with Custom.c

I have problem with print_string and print_number, like this:

http://www.matrixmultimedia.com/mmforum ... 65R#p22647
Image

Custom2.c ST7565R ARM

Code: Select all

//Custom2(0): //Defines:

/**** Macro Substitutions ****
a = User Define 1
b = User Define 2
c = User Define 3
d = User Define 4
e = User Define 5
f = User Define 6
g = User Define 7
h = User Define 8
i = User Define 9
j = User Define 10
******************************/

//common defines
#define MX_CUSTOM_1  
#define MX_CUSTOM_2  
#define MX_CUSTOM_3  
#define MX_CUSTOM_4  
#define MX_CUSTOM_5  
#define MX_CUSTOM_6  
#define MX_CUSTOM_7  
#define MX_CUSTOM_8  
#define MX_CUSTOM_9  
#define MX_CUSTOM_10 

#define LCD_COLUM_SET_H    0X10 
#define LCD_COLUM_SET_L    0X00 


//ASCII Pixel data
const char ASCII1[] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00,       // space // 32  - 43
					0x00 , 0x06 , 0x5F , 0x06 , 0x00,       // !
					0x07 , 0x03 , 0x00 , 0x07 , 0x03,       // ''
					0x24 , 0x7E , 0x24 , 0x7E , 0x24,       // #
					0x24 , 0x2B , 0x6A , 0x12 , 0x00,       // $
					0x63 , 0x13 , 0x08 , 0x64 , 0x63,       // %
					0x36 , 0x49 , 0x56 , 0x20 , 0x50,       // &
					0x00 , 0x07 , 0x03 , 0x00 , 0x00,       // '
					0x00 , 0x3E , 0x41 , 0x00 , 0x00,       // (
					0x00 , 0x41 , 0x3E , 0x00 , 0x00,       // )
					0x08 , 0x3E , 0x1C , 0x3E , 0x08,       // *
					0x08 , 0x08 , 0x3E , 0x08 , 0x08};      // +
const char ASCII2[] = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00,       // , // 44 - 55
					0x08 , 0x08 , 0x08 , 0x08 , 0x08,       // -
					0x00 , 0x60 , 0x60 , 0x00 , 0x00,       // .
					0x20 , 0x10 , 0x08 , 0x04 , 0x02,       // /
					0x3E , 0x51 , 0x49 , 0x45 , 0x3E,       // 0
					0x00 , 0x42 , 0x7F , 0x40 , 0x00,       // 1
					0x62 , 0x51 , 0x49 , 0x49 , 0x46,       // 2
					0x22 , 0x49 , 0x49 , 0x49 , 0x36,       // 3
					0x18 , 0x14 , 0x12 , 0x7F , 0x10,       // 4
					0x2F , 0x49 , 0x49 , 0x49 , 0x31,       // 5
					0x3C , 0x4A , 0x49 , 0x49 , 0x30,       // 6
					0x01 , 0x71 , 0x09 , 0x05 , 0x03};      // 7
const char ASCII3[] = {0x36 , 0x49 , 0x49 , 0x49 , 0x36,       // 8 // 56 - 67
					0x06 , 0x49 , 0x49 , 0x29 , 0x1E,       // 9
					0x00 , 0x6C , 0x6C , 0x00 , 0x00,       // :
					0x00 , 0xEC , 0x6C , 0x00 , 0x00,       // ;
					0x08 , 0x14 , 0x22 , 0x41 , 0x00,       // <
					0x24 , 0x24 , 0x24 , 0x24 , 0x24,       // =
					0x00 , 0x41 , 0x22 , 0x14 , 0x08,       // >
					0x02 , 0x01 , 0x59 , 0x09 , 0x06,       // ?
					0x3E , 0x41 , 0x5D , 0x55 , 0x1E,       // @
					0x7E , 0x09 , 0x09 , 0x09 , 0x7E,       // A
					0x7F , 0x49 , 0x49 , 0x49 , 0x36,       // B
					0x3E , 0x41 , 0x41 , 0x41 , 0x22};      // C
const char ASCII4[] = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E,       // D // 68 - 79
					0x7F , 0x49 , 0x49 , 0x49 , 0x41,       // E
					0x7F , 0x09 , 0x09 , 0x09 , 0x01,       // F
					0x3E , 0x41 , 0x49 , 0x49 , 0x7A,       // G
					0x7F , 0x08 , 0x08 , 0x08 , 0x7F,       // H
					0x00 , 0x41 , 0x7F , 0x41 , 0x00,       // I
					0x30 , 0x40 , 0x40 , 0x40 , 0x3F,       // J
					0x7F , 0x08 , 0x14 , 0x22 , 0x41,       // K
					0x7F , 0x40 , 0x40 , 0x40 , 0x40,       // L
					0x7F , 0x02 , 0x04 , 0x02 , 0x7F,       // M
					0x7F , 0x02 , 0x04 , 0x08 , 0x7F,       // N
					0x3E , 0x41 , 0x41 , 0x41 , 0x3E};      // O
const char ASCII5[] = {0x7F , 0x09 , 0x09 , 0x09 , 0x06,       // P // 80 - 91
					0x3E , 0x41 , 0x51 , 0x21 , 0x5E,       // Q
					0x7F , 0x09 , 0x09 , 0x19 , 0x66,       // R
					0x26 , 0x49 , 0x49 , 0x49 , 0x32,       // S
					0x01 , 0x01 , 0x7F , 0x01 , 0x01,       // T
					0x3F , 0x40 , 0x40 , 0x40 , 0x3F,       // U
					0x1F , 0x20 , 0x40 , 0x20 , 0x1F,       // V
					0x3F , 0x40 , 0x3C , 0x40 , 0x3F,       // W
					0x63 , 0x14 , 0x08 , 0x14 , 0x63,       // X
					0x07 , 0x08 , 0x70 , 0x08 , 0x07,       // Y
					0x71 , 0x49 , 0x45 , 0x43 , 0x00,       // Z
					0x00 , 0x7F , 0x41 , 0x41 , 0x00};      // [
const char ASCII6[] = {0x02 , 0x04 , 0x08 , 0x10 , 0x20,       // \ // 92 - 103
					0x00 , 0x41 , 0x41 , 0x7F , 0x00,       // ]
					0x04 , 0x02 , 0x01 , 0x02 , 0x04,       // ^
					0x80 , 0x80 , 0x80 , 0x80 , 0x80,       // _
					0x00 , 0x03 , 0x07 , 0x00 , 0x00,       // `
					0x20 , 0x54 , 0x54 , 0x54 , 0x78,       // a
					0x7F , 0x44 , 0x44 , 0x44 , 0x38,       // b
					0x38 , 0x44 , 0x44 , 0x44 , 0x28,       // c
					0x38 , 0x44 , 0x44 , 0x44 , 0x7F,       // d
					0x38 , 0x54 , 0x54 , 0x54 , 0x18,       // e
					0x08 , 0x7E , 0x09 , 0x09 , 0x00,       // f
					0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C};      // g
const char ASCII7[] = {0x7F , 0x04 , 0x04 , 0x78 , 0x00,       // h // 104 - 115
					0x00 , 0x00 , 0x7D , 0x00 , 0x00,       // i
					0x40 , 0x80 , 0x84 , 0x7D , 0x00,       // j
					0x7F , 0x10 , 0x28 , 0x44 , 0x00,       // k
					0x00 , 0x00 , 0x7F , 0x40 , 0x00,       // l
					0x7C , 0x04 , 0x18 , 0x04 , 0x78,       // m
					0x7C , 0x04 , 0x04 , 0x78 , 0x00,       // n
					0x38 , 0x44 , 0x44 , 0x44 , 0x38,       // o
					0xFC , 0x44 , 0x44 , 0x44 , 0x38,       // p
					0x38 , 0x44 , 0x44 , 0x44 , 0xFC,       // q
					0x44 , 0x78 , 0x44 , 0x04 , 0x08,       // r
					0x08 , 0x54 , 0x54 , 0x54 , 0x20};      // s
const char ASCII8[] = {0x04 , 0x3E , 0x44 , 0x24 , 0x00,       // t // 116 - 126
					0x3C , 0x40 , 0x20 , 0x7C , 0x00,       // u
					0x1C , 0x20 , 0x40 , 0x20 , 0x1C,       // v
					0x3C , 0x60 , 0x30 , 0x60 , 0x3C,       // w
					0x6C , 0x10 , 0x10 , 0x6C , 0x00,       // x
					0x9C , 0xA0 , 0x60 , 0x3C , 0x00,       // y
					0x64 , 0x54 , 0x54 , 0x4C , 0x00,       // z
					0x08 , 0x3E , 0x41 , 0x41 , 0x00,       // {
					0x00 , 0x00 , 0x7F , 0x00 , 0x00,       // |
					0x00 , 0x41 , 0x41 , 0x3E , 0x08,       // }
					0x02 , 0x01 , 0x02 , 0x01 , 0x00};      // ~


//Internal Prototypes
void Write_Command(char cmd, char chip);
void Write_Data(char data);
void GotoXY(char x, char y);



//Global Variables
char mx_page;
char mx_currentx;
char mx_currenty;



void MX_Write_Command(unsigned char cmd) 
 {
        //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
        //A0 PD4 = 0
        AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA28; // Set pin state to 'low'	
        //Appel de la Routine Composant: SPI_Send_Char(cmd)
		FCD_SPI_Legacy0_SPI_Send_Char(cmd); 
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31
 }


void MX_Write_Data(unsigned char dat) 
 {
		//CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
	    //A0 PD4 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA28; // Set Pin PA28	 
        //Appel de la Routine Composant: SPI_Send_Char(dat)
		FCD_SPI_Legacy0_SPI_Send_Char(dat);
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31
 }



void MX_GotoXY (char x, char y)
{
	char page, columnl, columnh;

	page = (y / 8) | 0xB0;
	columnh = (x >> 4) | 0x10;
	columnl = x & 0x0F;

	if(x > 127) x = 0;							//Ensure that coordinates are legal
	if(y > 63)  y = 0;

	mx_currentx = x;
	mx_currenty = y;
	mx_page = y / 8;

	MX_Write_Command(0x40);						//set display start line
	MX_Write_Command(page);						//set page address
	MX_Write_Command(columnh);					//set column address
	MX_Write_Command(columnl);
}



//Custom2(0): //Déclarations de fonction Macro

static void FCD_Custom20_READ_ME();
static void FCD_Custom20_clear_lcd();
static void FCD_Custom20_lcd_init();
static void FCD_Custom20_lcd_plotpixel(char x, char y, char colour);
static void FCD_Custom20_lcd_draw_line(char x, char x2, char y, char y2, char colour);
static void FCD_Custom20_lcd_draw_rect(char x, char y, char width, char height, char colour);
static void FCD_Custom20_lcd_print_string(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour);
static void FCD_Custom20_lcd_print_number(short Number, char X, char Y, char Font, char Transparent, char Colour);
static void FCD_Custom20_lcd_invert_rect(char x, char y, char width, char height);






//Custom2(0): //Implémentations Macro


static void FCD_Custom20_READ_ME()
{
	
		//To use this component, add new functions via
		//the "Customize Component Code" window

}

static void FCD_Custom20_clear_lcd()
{
	unsigned char i,j; 

	 for(i=0; i<9; i++)           //clear page 0~8 
	  { 
	   MX_Write_Command(0xB0+i);           //set page 
	   MX_Write_Command(LCD_COLUM_SET_L);  //set column 
	   MX_Write_Command(LCD_COLUM_SET_H);  //set column 
	   for(j=0; j<130; j++)       //clear all columns upto 130 
	   {      
	    MX_Write_Data(0x00);    
	   } 
	 } 
}

static void FCD_Custom20_lcd_init()
{
	    //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
	    //RST PD3 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA27; // Set pin state to 'low'
		//Pause: 500 ms
		delay_ms(500);
	    //RST PD3 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA27; // Set Pin PA27	 
	    //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low' 

	    MX_Write_Command(0x40);   // Display Line Start 
	    MX_Write_Command(0xA1);   // ADC Normal A0 / Reverse A1
	    MX_Write_Command(0xA3);   // Bias 1/7 
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0xC8);   // Scan Direction Normale C0 / Reverse C8
	    MX_Write_Command(0xA6);   // Display Normal A6 / Reverse A7
	    MX_Write_Command(0x2F);   // Booster Reg 
	    MX_Write_Command(0xF8);   // Internal Booster Set 
		//Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x00);   // Booster Value x4
	    MX_Write_Command(0x23);   // Contrast
	    MX_Write_Command(0x81);   // Volume Control Set 
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x27);   // Volume value
	    MX_Write_Command(0xAC);   // Static Indic Set
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x00);   // Value No
	    MX_Write_Command(0xAF);   // Display On 

}

static void FCD_Custom20_lcd_plotpixel(char x, char y, char colour)
{
	char data, mod_y;
	   MX_GotoXY(x, y);
	   mod_y = y%8;
	   if (colour)
	      data = data | (0x01 << mod_y);            //Set Pixel
	   else
	      data = data & (~(0x01 << mod_y));         //Clear Pixel
	   MX_Write_Data(data);
}

static void FCD_Custom20_lcd_draw_line(char x, char x2, char y, char y2, char colour)
{
	int C1, M1;
		signed int D1 = 0;
		signed int Pixelx = x2 - x;    //number of X-pixels;
		signed int Pixely = y2 - y;    //Number of Y-pixels
		signed char Xinc = 1;
		signed char Yinc = 1;

		if (Pixelx < 0)        //If negative X direction
		{
			Xinc = -1;
			Pixelx = Pixelx * -1;
		}
		if (Pixely < 0)        //If negative Y direction
		{
			Yinc = -1;
			Pixely = Pixely * -1;
		}
		if (Pixely <= Pixelx)
		{
			C1 = 2 * Pixelx;
			M1 = 2 * Pixely;
			while (x != x2)
			{
				FCD_Custom20_lcd_plotpixel(x, y, colour);    //ForePlot line
				x = x + Xinc;
				D1 = D1 + M1;
				if (D1 > Pixelx)
				{
					y = y + Yinc;
					D1 = D1 - C1;
				}
			}
		}
		else
		{
			C1 = 2 * Pixely;
			M1 = 2 * Pixelx;
			while (y != y2)
			{
				FCD_Custom20_lcd_plotpixel(x, y, colour);    //ForePlot Line
				y = y + Yinc;
				D1 = D1 + M1;
				if (D1 > Pixely)
				{
					x = x + Xinc;
					D1 = D1 - C1;
				}
			}
			FCD_Custom20_lcd_plotpixel(x, y, colour);
		}
}

static void FCD_Custom20_lcd_draw_rect(char x, char y, char width, char height, char colour)
{
		char mask, pageOffset, h, i, data;

		if(colour)
			colour = 255;

		height = height + 1;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;

		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
			h = (8 - pageOffset);

		mask = mask << pageOffset;

		MX_GotoXY(x, y);

		for(i=0; i<=width; i++)
		{
			if(colour)
				data = data | mask;
			else
				data = data & (~mask);

			MX_Write_Data(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
				MX_Write_Data(colour);
		}

		if(h < height)
		{
			mask = ~(0xFF << (height - h));
			MX_GotoXY(x, (y + 8));

			for(i=0; i<=width; i++)
			{
				if(colour)
					data = data | mask;
				else
					data = data & (~mask);

				MX_Write_Data(data);
			}
		}
}

static void FCD_Custom20_lcd_print_string(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour)
{
	    char xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
	    char Fontwidth = 1;                //First we assume small font
	    char Fontheight = 1;
		char inv_colour = 1;

	    char temp[6];
	    temp[5] = 0x00;                        //Spacing Line

		if (Colour)
			inv_colour = 0;

	    if (Font == 1)                     	//Double Height Sizes //Double Width
	    {
	        Fontwidth = 2;
	    }
	    if (Font == 2)                         //Double Height and Width Sizes
	    {
	        Fontwidth = 2;
	        Fontheight = 2;
	    }
	    if (Font == 3)                         //Double Height Sizes
	    {
	        Fontheight = 2;
	    }

	    xcount = 0;
	    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
	    {
	        if (String[i] == 0)
	        	return;
	        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

	        for (count = 0; count < 5; count++)        //Use correct buffer location
	        {
	            if (pos_Str < 12)
	            {
	                temp[count]=ASCII1[(pos_Str*5)+count];
	            }
	            else if (pos_Str < 24)
	            {
	                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
	            }
	            else if (pos_Str < 36)
	            {
	                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
	            }
	            else if (pos_Str < 48)
	            {
	                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
	            }
	            else if (pos_Str < 60)
	            {
	                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
	            }
	            else if (pos_Str < 72)
	            {
	                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
	            }
	            else if (pos_Str < 84)
	            {
	                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
	            }
	            else if (pos_Str < 95)
	            {
	                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
	            }
	        }
	        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
	        {
	            for (width=0;width<Fontwidth;width++)
	            {
	                ycount = 0;
	                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
	                {
	                    for (height=0;height<Fontheight;height++)
	                    {
	                        if (test_bit(temp[xpix],ypix))
	                        {
	                            FCD_Custom20_lcd_plotpixel(X + xcount, Y + ycount, Colour);
	                        }
	                        else if (Transparent == 0)
	                        {
	                            FCD_Custom20_lcd_plotpixel(X+xcount, Y+ycount, inv_colour);
	                        }
	                        ycount++;
	                    }
	                }
	                xcount++;
	            }
	        }
	    }
}

static void FCD_Custom20_lcd_print_number(short Number, char X, char Y, char Font, char Transparent, char Colour)
{
	char string_length;

		if (Number < -10000	)
			string_length = 6;

		else if(Number > 10000 || Number < -1000)
			string_length = 5;

		else if(Number > 1000 || Number < -100)
			string_length = 4;

		else if(Number > 100 || Number < -10)
			string_length = 3;

		else if(Number > 10 || Number < -1)
			string_length = 2;

		else
			string_length = 1;

		char temp_str[6];

		FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
		FCD_Custom20_lcd_print_string(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
}

static void FCD_Custom20_lcd_invert_rect(char x, char y, char width, char height)
{
	char mask, pageOffset, h, i, data, tmpData;
		height++;

		pageOffset = y % 8;
		y = y - pageOffset;
		mask = 0xFF;
		if(height < (8 - pageOffset))
		{
			mask = mask >> (8-height);
			h = height;
		}
		else
		{
			h = 8 - pageOffset;
		}
		mask = mask << pageOffset;

		MX_GotoXY(x, y);
		for(i=0; i<=width; i++)
		{
			tmpData = ~data;
			data = (tmpData & mask) | (data & ~mask);
			MX_Write_Data(data);
		}

		while((h + 8) <= height)
		{
			h = h + 8;
			y = y + 8;
			MX_GotoXY(x, y);

			for(i=0; i<=width; i++)
			{
				MX_Write_Data(~data);
			}
		}

		if(h < height)
		{
			mask = ~(0xFF << (height-h));
			MX_GotoXY(x, y+8);

			for(i=0; i<=width; i++)
			{
				tmpData = ~data;
				data = (tmpData & mask) | (data & ~mask);
				MX_Write_Data(data);
			}
		}
}
Thank

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

Ok, I have found even problem here:
http://www.matrixmultimedia.com/mmforum ... f=5&t=8262

After many research tests in GotoXY and lcd_Plotpixel, problem is value in "data"
For one write pixel there are 2 or 3 pixels on the column.

Original lcd_plotpixel Macro

Code: Select all

void lcd_plotpixel (char x, char y, char colour)
{
  char data, mod_y;
   MX_GotoXY(x, y);
   mod_y = y%8;
   if (colour)
      data = data | (0x01 << mod_y);            //Set Pixel
   else
      data = data & (~(0x01 << mod_y));         //Clear Pixel
   MX_Write_Data(data);
}
For test I have replaced data by 0x00

Code: Select all

void lcd_plotpixel (char x, char y, char colour)
{
  char data, mod_y;
   MX_GotoXY(x, y);
   mod_y = y%8;
   if (colour)
      data = 0x00 | (0x01 << mod_y);            //Set Pixel
   else
      data = 0x00 & (~(0x01 << mod_y));         //Clear Pixel
   MX_Write_Data(data);
}
Draw Line, Draw rect and plot pixel OK :)
But print string is no correct.

How data is write ?
I don't understand how print string write "data"

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ST7565R GLcd Component

Post by Benj »

Hello Nico,

Aha some progress, well done, the hardest part is now over.

Ok so the plot functions work but the print sting function doesn't. This sounds like a read modify write issue probably in the plot function.

Try drawing horizontal lines from say 1, 1 to 30, 1 and then another from 1, 3 to 15, 3. Is there any corruption?

Replicate with Vertical lines e.g. 1,1 to 1, 30 and 3,1 to 3,15 is there any corruption?

If you can show me the corruption generated from these then hopefully I can help to pinpoint the bug.

From closer inspection of your C file it looks like the ReadByte function is missing altogether. I'll see if I can dig you out an example.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

Hi Ben :D ,
Thank you.

2 Horizontals lines 1, 50 and 1, 30
2 Verticals lines 1, 50 and 1, 30
1 square h10, w10, x10, y10
1 Text: "TEST"

First picture: with data = data | (0x01 << mod_y);
Image

2nd picture: with data = 0x00 | (0x01 << mod_y);
Image

I think problem is in the value "data" D0 - D7

With this test

2 Horizontals lines 1, 50 and 1, 30 => postion OK, pixel OK
2 Verticals lines 1, 50 and 1, 30 => postion OK, pixel Pb
1 square h10, w10, x10, y10 => postion OK, w OK, h Pb
1 Text: "TEST" => position OK, pixel Pb
From closer inspection of your C file it looks like the ReadByte function is missing altogether. I'll see if I can dig you out an example.
With SPI mode I think I have not this function.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I have found ReadByte in your Custom.c in Write_Data function code.

Code: Select all

char MX_ReadData (void)
{
	char data, i;

	MX_DATA_PORT = 0x00;
	MX_DATA_TRIS = 0xFF;							//Data port is input
	set_bit(MX_CONTROL_PORT, MX_READ_WRITE);		//Configure to read data
	set_bit(MX_CONTROL_PORT, MX_DAT_INST);			//Configure to send data
	clear_bit(MX_CONTROL_PORT, MX_CS1);
	nop();
	nop();
	data = MX_DATA_PORT;							//Read Data
	MX_DATA_TRIS = 0x00;							//Configure port as output
	set_bit(MX_CONTROL_PORT, MX_CS1);
	MX_GotoXY(mx_currentx, mx_currenty);
	return data;
}
data is here :)

I have deleted this function in ST7565R SPI mode, communication is only MOSI / SCLK / CS / A0 / RST, no return by GLCD

EDIT: I understand, my MX_Write_Data is without char displayData, yOffset, cmdPort ...
With ST7565 in SPI mode yOffset is without ReadByte.

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

Yesss, it s Ok.

I mix your code with this:
http://mbed.org/users/igorsk/code/DOGLC ... fd318f/LCD

It s perfect. I write the code in Costum.c and I copy here :)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ST7565R GLcd Component

Post by Benj »

Aha good work,

Did you end up getting read functionality or have you found a way without having to do this?

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

Thank Ben :D

This code drive ST7565R without ReadByte.

It's a first draft, Draw_rect and Invert_rect are no write.
Clear_lcd, Draw_line, Print_string, Print_number OK

Code: Select all


//Custom2(0): //Defines:
/**** Macro Substitutions ****
a = User Define 1
b = User Define 2
c = User Define 3
d = User Define 4
e = User Define 5
f = User Define 6
g = User Define 7
h = User Define 8
i = User Define 9
j = User Define 10
******************************/

//common defines
#define MX_CUSTOM_1  
#define MX_CUSTOM_2  
#define MX_CUSTOM_3  
#define MX_CUSTOM_4  
#define MX_CUSTOM_5  
#define MX_CUSTOM_6  
#define MX_CUSTOM_7  
#define MX_CUSTOM_8  
#define MX_CUSTOM_9  
#define MX_CUSTOM_10 

#define LCD_COLUM_SET_H    0X10 
#define LCD_COLUM_SET_L    0X00 


//Static defines
#define MX_BLACK			0xFF
#define MX_WHITE			0x00

#define LCDWIDTH 128
#define LCDHEIGHT 64
#define LCDPAGES  (LCDHEIGHT+7)/8

// macro to make sure x falls into range from low to high (inclusive)
#define CLAMP(x, low, high) { if ( (x) < (low) ) x = (low); if ( (x) > (high) ) x = (high); } while (0);


//ASCII Pixel data
const char ASCII1[] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00,       // space // 32  - 43
					0x00 , 0x06 , 0x5F , 0x06 , 0x00,       // !
					0x07 , 0x03 , 0x00 , 0x07 , 0x03,       // ''
					0x24 , 0x7E , 0x24 , 0x7E , 0x24,       // #
					0x24 , 0x2B , 0x6A , 0x12 , 0x00,       // $
					0x63 , 0x13 , 0x08 , 0x64 , 0x63,       // %
					0x36 , 0x49 , 0x56 , 0x20 , 0x50,       // &
					0x00 , 0x07 , 0x03 , 0x00 , 0x00,       // '
					0x00 , 0x3E , 0x41 , 0x00 , 0x00,       // (
					0x00 , 0x41 , 0x3E , 0x00 , 0x00,       // )
					0x08 , 0x3E , 0x1C , 0x3E , 0x08,       // *
					0x08 , 0x08 , 0x3E , 0x08 , 0x08};      // +
const char ASCII2[] = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00,       // , // 44 - 55
					0x08 , 0x08 , 0x08 , 0x08 , 0x08,       // -
					0x00 , 0x60 , 0x60 , 0x00 , 0x00,       // .
					0x20 , 0x10 , 0x08 , 0x04 , 0x02,       // /
					0x3E , 0x51 , 0x49 , 0x45 , 0x3E,       // 0
					0x00 , 0x42 , 0x7F , 0x40 , 0x00,       // 1
					0x62 , 0x51 , 0x49 , 0x49 , 0x46,       // 2
					0x22 , 0x49 , 0x49 , 0x49 , 0x36,       // 3
					0x18 , 0x14 , 0x12 , 0x7F , 0x10,       // 4
					0x2F , 0x49 , 0x49 , 0x49 , 0x31,       // 5
					0x3C , 0x4A , 0x49 , 0x49 , 0x30,       // 6
					0x01 , 0x71 , 0x09 , 0x05 , 0x03};      // 7
const char ASCII3[] = {0x36 , 0x49 , 0x49 , 0x49 , 0x36,       // 8 // 56 - 67
					0x06 , 0x49 , 0x49 , 0x29 , 0x1E,       // 9
					0x00 , 0x6C , 0x6C , 0x00 , 0x00,       // :
					0x00 , 0xEC , 0x6C , 0x00 , 0x00,       // ;
					0x08 , 0x14 , 0x22 , 0x41 , 0x00,       // <
					0x24 , 0x24 , 0x24 , 0x24 , 0x24,       // =
					0x00 , 0x41 , 0x22 , 0x14 , 0x08,       // >
					0x02 , 0x01 , 0x59 , 0x09 , 0x06,       // ?
					0x3E , 0x41 , 0x5D , 0x55 , 0x1E,       // @
					0x7E , 0x09 , 0x09 , 0x09 , 0x7E,       // A
					0x7F , 0x49 , 0x49 , 0x49 , 0x36,       // B
					0x3E , 0x41 , 0x41 , 0x41 , 0x22};      // C
const char ASCII4[] = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E,       // D // 68 - 79
					0x7F , 0x49 , 0x49 , 0x49 , 0x41,       // E
					0x7F , 0x09 , 0x09 , 0x09 , 0x01,       // F
					0x3E , 0x41 , 0x49 , 0x49 , 0x7A,       // G
					0x7F , 0x08 , 0x08 , 0x08 , 0x7F,       // H
					0x00 , 0x41 , 0x7F , 0x41 , 0x00,       // I
					0x30 , 0x40 , 0x40 , 0x40 , 0x3F,       // J
					0x7F , 0x08 , 0x14 , 0x22 , 0x41,       // K
					0x7F , 0x40 , 0x40 , 0x40 , 0x40,       // L
					0x7F , 0x02 , 0x04 , 0x02 , 0x7F,       // M
					0x7F , 0x02 , 0x04 , 0x08 , 0x7F,       // N
					0x3E , 0x41 , 0x41 , 0x41 , 0x3E};      // O
const char ASCII5[] = {0x7F , 0x09 , 0x09 , 0x09 , 0x06,       // P // 80 - 91
					0x3E , 0x41 , 0x51 , 0x21 , 0x5E,       // Q
					0x7F , 0x09 , 0x09 , 0x19 , 0x66,       // R
					0x26 , 0x49 , 0x49 , 0x49 , 0x32,       // S
					0x01 , 0x01 , 0x7F , 0x01 , 0x01,       // T
					0x3F , 0x40 , 0x40 , 0x40 , 0x3F,       // U
					0x1F , 0x20 , 0x40 , 0x20 , 0x1F,       // V
					0x3F , 0x40 , 0x3C , 0x40 , 0x3F,       // W
					0x63 , 0x14 , 0x08 , 0x14 , 0x63,       // X
					0x07 , 0x08 , 0x70 , 0x08 , 0x07,       // Y
					0x71 , 0x49 , 0x45 , 0x43 , 0x00,       // Z
					0x00 , 0x7F , 0x41 , 0x41 , 0x00};      // [
const char ASCII6[] = {0x02 , 0x04 , 0x08 , 0x10 , 0x20,       // \ // 92 - 103
					0x00 , 0x41 , 0x41 , 0x7F , 0x00,       // ]
					0x04 , 0x02 , 0x01 , 0x02 , 0x04,       // ^
					0x80 , 0x80 , 0x80 , 0x80 , 0x80,       // _
					0x00 , 0x03 , 0x07 , 0x00 , 0x00,       // `
					0x20 , 0x54 , 0x54 , 0x54 , 0x78,       // a
					0x7F , 0x44 , 0x44 , 0x44 , 0x38,       // b
					0x38 , 0x44 , 0x44 , 0x44 , 0x28,       // c
					0x38 , 0x44 , 0x44 , 0x44 , 0x7F,       // d
					0x38 , 0x54 , 0x54 , 0x54 , 0x18,       // e
					0x08 , 0x7E , 0x09 , 0x09 , 0x00,       // f
					0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C};      // g
const char ASCII7[] = {0x7F , 0x04 , 0x04 , 0x78 , 0x00,       // h // 104 - 115
					0x00 , 0x00 , 0x7D , 0x00 , 0x00,       // i
					0x40 , 0x80 , 0x84 , 0x7D , 0x00,       // j
					0x7F , 0x10 , 0x28 , 0x44 , 0x00,       // k
					0x00 , 0x00 , 0x7F , 0x40 , 0x00,       // l
					0x7C , 0x04 , 0x18 , 0x04 , 0x78,       // m
					0x7C , 0x04 , 0x04 , 0x78 , 0x00,       // n
					0x38 , 0x44 , 0x44 , 0x44 , 0x38,       // o
					0xFC , 0x44 , 0x44 , 0x44 , 0x38,       // p
					0x38 , 0x44 , 0x44 , 0x44 , 0xFC,       // q
					0x44 , 0x78 , 0x44 , 0x04 , 0x08,       // r
					0x08 , 0x54 , 0x54 , 0x54 , 0x20};      // s
const char ASCII8[] = {0x04 , 0x3E , 0x44 , 0x24 , 0x00,       // t // 116 - 126
					0x3C , 0x40 , 0x20 , 0x7C , 0x00,       // u
					0x1C , 0x20 , 0x40 , 0x20 , 0x1C,       // v
					0x3C , 0x60 , 0x30 , 0x60 , 0x3C,       // w
					0x6C , 0x10 , 0x10 , 0x6C , 0x00,       // x
					0x9C , 0xA0 , 0x60 , 0x3C , 0x00,       // y
					0x64 , 0x54 , 0x54 , 0x4C , 0x00,       // z
					0x08 , 0x3E , 0x41 , 0x41 , 0x00,       // {
					0x00 , 0x00 , 0x7F , 0x00 , 0x00,       // |
					0x00 , 0x41 , 0x41 , 0x3E , 0x08,       // }
					0x02 , 0x01 , 0x02 , 0x01 , 0x00};      // ~


//Internal Prototypes
void Write_Command(char cmd, char chip);
void Write_Data(char data);

int _updating;
void _send_commands(const unsigned char* buf, size_t size);
void _send_data(const unsigned char* buf, size_t size);
void _set_xy(int x, int y);
unsigned char _framebuffer[LCDWIDTH*LCDPAGES];


void MX_Write_Command(unsigned char cmd) 
{
        //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
        //A0 PD4 = 0
        AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA28; // Set pin state to 'low'	
        //Appel de la Routine Composant: SPI_Send_Char(cmd)
		FCD_SPI_Legacy0_SPI_Send_Char(cmd); 
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31
}

void MX_Write_Data(unsigned char data) 
{
		//CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
	    //A0 PD4 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA28; // Set Pin PA28	
      	//Appel de la Routine Composant: SPI_Send_Char(data)
        FCD_SPI_Legacy0_SPI_Send_Char(data);
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31
}

void _set_xy(int x, int y)
{
    //printf("_set_xy(,)\n", x, y);
    CLAMP(x, 0, LCDWIDTH-1);
    CLAMP(y, 0, LCDPAGES-1);
    unsigned char cmd[3];
    cmd[0] = 0xB0 | (y&0xF); 
    cmd[1] = (x >> 4) | 0x10; 
    cmd[2] =  x & 0x0F;    
    _send_commands(cmd, 3);        
}

void pixel(int x, int y, int colour)
{
    CLAMP(x, 0, LCDWIDTH-1);
    CLAMP(y, 0, LCDHEIGHT-1);
    int page = y / 8;
    unsigned char mask = 1<<(y%8);
    unsigned char *byte = &_framebuffer[page*LCDWIDTH + x];
    if ( colour == 0 )
        *byte &= ~mask; // clear pixel
    else
        *byte |= mask; // set pixel
    if ( !_updating )
    {
        _set_xy(x, page);
        _send_data(byte, 1);
    }
}

void _send_commands(const unsigned char* buf, size_t size)
{
    // for commands, A0 is low
        //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
        //A0 PD4 = 0
        AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA28; // Set pin state to 'low'	
        while ( size-- > 0 )
        //Appel de la Routine Composant: SPI_Send_Char(cmd)
		FCD_SPI_Legacy0_SPI_Send_Char(*buf++); 
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31;
    
}

void _send_data(const unsigned char* buf, size_t size)
{
    // for data, A0 is high
        //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
	    //A0 PD4 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA28; // Set Pin PA28	
        while ( size-- > 0 )
        //Appel de la Routine Composant: SPI_Send_Char(data)
        FCD_SPI_Legacy0_SPI_Send_Char(*buf++);
        //A0 PD4 = 0
        AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA28; // Set pin state to 'low'
        //CS PD7 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA31; // Set Pin PA31();
    
}



//Custom2(0): //Déclarations de fonction Macro

static void FCD_Custom20_READ_ME();
static void FCD_Custom20_lcd_clear();
static void FCD_Custom20_lcd_init();
static void FCD_Custom20_lcd_draw_line(char x, char x2, char y, char y2, char colour);
static void FCD_Custom20_lcd_draw_rect(char x, char y, char width, char height, char colour);
static void FCD_Custom20_lcd_print_string(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour);
static void FCD_Custom20_lcd_print_number(short Number, char X, char Y, char Font, char Transparent, char Colour);
static void FCD_Custom20_lcd_invert_rect(char x, char y, char width, char height);


//Custom2(0): //Implémentations Macro

static void FCD_Custom20_READ_ME()
{
	
		//To use this component, add new functions via
		//the "Customize Component Code" window

}

static void FCD_Custom20_lcd_clear()
{
	unsigned char i,j; 

	 for(i=0; i<9; i++)           //clear page 0~8 
	  { 
	   MX_Write_Command(0xB0+i);           //set page 
	   MX_Write_Command(LCD_COLUM_SET_L);  //set column 
	   MX_Write_Command(LCD_COLUM_SET_H);  //set column 
	   for(j=0; j<132; j++)       //clear all columns upto 130
	   {      
	    MX_Write_Data(0x00);    
	   } 
	 } 
}

static void FCD_Custom20_lcd_init()
{
	    //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low'
	    //RST PD3 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA27; // Set pin state to 'low'
		//Pause: 500 ms
		delay_ms(500);
	    //RST PD3 = 1
		AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA27; // Set Pin PA27	 
	    //CS PD7 = 0
		AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA31; // Set pin state to 'low' 

	    MX_Write_Command(0x40);   // Display Line Start 
	    MX_Write_Command(0xA0);   // ADC Normal A0 / Reverse A1
	    MX_Write_Command(0xA3);   // Bias 1/7 
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0xC8);   // Scan Direction Normale C0 / Reverse C8
	    MX_Write_Command(0xA6);   // Display Normal A6 / Reverse A7
	    MX_Write_Command(0x2F);   // Booster Reg 
	    MX_Write_Command(0xF8);   // Internal Booster Set 
		//Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x00);   // Booster Value x4
	    MX_Write_Command(0x23);   // Contrast
	    MX_Write_Command(0x81);   // Volume Control Set 
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x27);   // Volume value
	    MX_Write_Command(0xAC);   // Static Indic Set
	    //Pause: 200 ms
		delay_ms(200);
	    MX_Write_Command(0x00);   // Value No
	    MX_Write_Command(0xAF);   // Display On 

}

static void FCD_Custom20_lcd_draw_line(char x, char x2, char y, char y2, char colour)
{
	int C1, M1;
		signed int D1 = 0;
		signed int Pixelx = x2 - x;    //number of X-pixels;
		signed int Pixely = y2 - y;    //Number of Y-pixels
		signed char Xinc = 1;
		signed char Yinc = 1;

		if (Pixelx < 0)        //If negative X direction
		{
			Xinc = -1;
			Pixelx = Pixelx * -1;
		}
		if (Pixely < 0)        //If negative Y direction
		{
			Yinc = -1;
			Pixely = Pixely * -1;
		}
		if (Pixely <= Pixelx)
		{
			C1 = 2 * Pixelx;
			M1 = 2 * Pixely;
	       	while (x != x2)
			{
	            pixel(x, y, colour);    //ForePlot line
				x = x + Xinc;
				D1 = D1 + M1;
				if (D1 > Pixelx)
				{
					y = y + Yinc;
					D1 = D1 - C1;
				}
			}
		}
		else
		{
			C1 = 2 * Pixely;
			M1 = 2 * Pixelx;
			while (y != y2)
			{
	            pixel(x, y, colour);    //ForePlot Line
				y = y + Yinc;
				D1 = D1 + M1;
				if (D1 > Pixely)
				{
					x = x + Xinc;
					D1 = D1 - C1;
				}
			}
			pixel(x, y, colour);
		}
}


static void FCD_Custom20_lcd_print_string(char* String, MX_UINT8 MSZ_String, char X, char Y, char Font, char Transparent, char Colour)
{
	    char xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
	    char Fontwidth = 1;                //First we assume small font
	    char Fontheight = 1;
		char inv_colour = 1;

	    char temp[6];
	    temp[5] = 0x00;                        //Spacing Line

		if (Colour)
			inv_colour = 0;

	    if (Font == 1)                     	//Double Height Sizes //Double Width
	    {
	        Fontwidth = 2;
	    }
	    if (Font == 2)                         //Double Height and Width Sizes
	    {
	        Fontwidth = 2;
	        Fontheight = 2;
	    }
	    if (Font == 3)                         //Double Height Sizes
	    {
	        Fontheight = 2;
	    }

	    xcount = 0;
	    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
	    {
	        if (String[i] == 0)
	        	return;
	        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

	        for (count = 0; count < 5; count++)        //Use correct buffer location
	        {
	            if (pos_Str < 12)
	            {
	                temp[count]=ASCII1[(pos_Str*5)+count];
	            }
	            else if (pos_Str < 24)
	            {
	                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
	            }
	            else if (pos_Str < 36)
	            {
	                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
	            }
	            else if (pos_Str < 48)
	            {
	                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
	            }
	            else if (pos_Str < 60)
	            {
	                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
	            }
	            else if (pos_Str < 72)
	            {
	                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
	            }
	            else if (pos_Str < 84)
	            {
	                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
	            }
	            else if (pos_Str < 95)
	            {
	                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
	            }
	        }
	        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
	        {
	            for (width=0;width<Fontwidth;width++)
	            {
	                ycount = 0;
	                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
	                {
	                    for (height=0;height<Fontheight;height++)
	                    {
	                        if (test_bit(temp[xpix],ypix))
	                        {
	                            pixel(X + xcount, Y + ycount, Colour);
	                        }
	                        else if (Transparent == 0)
	                        {
	                            pixel(X+xcount, Y+ycount, inv_colour);
	                        }
	                        ycount++;
	                    }
	                }
	                xcount++;
	            }
	        }
	    }
}

static void FCD_Custom20_lcd_print_number(short Number, char X, char Y, char Font, char Transparent, char Colour)
{
	char string_length;

		if (Number < -10000	)
			string_length = 6;

		else if(Number > 10000 || Number < -1000)
			string_length = 5;

		else if(Number > 1000 || Number < -100)
			string_length = 4;

		else if(Number > 100 || Number < -10)
			string_length = 3;

		else if(Number > 10 || Number < -1)
			string_length = 2;

		else
			string_length = 1;

		char temp_str[6];

		FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
		FCD_Custom20_lcd_print_string(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
}




User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

I have changed police ^^ and add a small offset (4px) into _set_xy

Code: Select all

void _set_xy(int x, int y)
{
    //printf("_set_xy(%d,%d)\n", x, y);
    CLAMP(x, 0, LCDWIDTH-1);
    CLAMP(y, 0, LCDPAGES-1);
    x = x + 4;
    unsigned char cmd[3];
    cmd[0] = 0xB0 | (y&0xF); 
    cmd[1] = (x >> 4) | 0x10; 
    cmd[2] =  x & 0x0F;    
    _send_commands(cmd, 3);        
}
1 pixel x5 y5 OK
Image

User avatar
Nico595
Posts: 84
Joined: Mon Jan 23, 2012 6:46 pm
Location: France
Has thanked: 12 times
Been thanked: 10 times
Contact:

Re: ST7565R GLcd Component

Post by Nico595 »

A small bug in Print_Number for 10 or 100 or 1000 or 10000 ... > is without = when number = 10 or 100 or 1000 or 10000 a 0 is lost.
Add = after >

lcd_print_number:

Code: Select all

static void FCD_Custom20_lcd_print_number(short Number, char X, char Y, char Font, char Transparent, char Colour)
{
	char string_length;

		if (Number < -10000	)
			string_length = 6;

		else if(Number >= 10000 || Number < -1000)
			string_length = 5;

		else if(Number >= 1000 || Number < -100)
			string_length = 4;

		else if(Number >= 100 || Number < -10)
			string_length = 3;

		else if(Number >= 10 || Number < -1)
			string_length = 2;

		else
			string_length = 1;

		char temp_str[6];

		FCI_TOSTRING(Number,temp_str,string_length);									//Convert number to String
		FCD_Custom20_lcd_print_string(temp_str, string_length, X, Y, Font, Transparent, Colour);		//Send string to Print function
}
:D

Post Reply