Modular programming of NOKIA5110 LCD screen controlled by single chip microcomputer

Label: SinglechipLCD screenFive thousand one hundred and tenNOKIAModularization
949 people read comment(0) Collection Report
Classification:

STC12C5A60S2 control Nokia LCD5110 I wrote here the program to share, hope predecessors advice.

(added: the following code only need to modify the lcd5110.h file containing the word "select" part and font header file wordCode.h, can achieve the effect of reuse)


Test procedure:

<reg52.h> #include
Lcd5110.h "#include"
WordCode.h "#include"


Main void ()
{
LCD5110Init ();

/ / Chinese characters
LCD5110AddressWriteWord (0,0, wordcode1[0], 16,3,0); / / each
LCD5110AddressWriteWord (2*8,0, wordcode1[0], 16,2,1); / / day
LCD5110AddressWriteWord (4*8,0, wordcode1[0], 16,2,2); / /.
LCD5110AddressWriteWord (6*8,0, wordcode1[0], 16,2,3); / / step
LCD5110AddressWriteWord (8*8,0, wordcode1[0], 16,2,4); / / A
															
LCD5110AddressWriteWord (0,2, wordcode1[0], 16,2,5); / / point
LCD5110AddressWriteWord (2*8,2, wordcode1[0], 16,2,6); / / point
LCD5110AddressWriteWord (4*8,2, wordcode1[0], 16,2,7); / / soon
LCD5110AddressWriteWord (6*8,2, wordcode1[0], 16,2,8); / / not
LCD5110AddressWriteWord (8*8,2, wordcode1[0], 16,2,9); / / again

LCD5110AddressWriteWord (0,4, wordcode1[0], 16,2,10); / / Jane
LCD5110AddressWriteWord (2*8,4, wordcode1[0], 16,2,11); / / single

/ / picture
//LCD5110AddressWritePicture (0,0, Pic, 42,12,0);

While (1);

}




/*################Lcd5110.hStart################* / 

__LCD5110_H__ #ifndef
__LCD5110_H__ #define

<reg52.h> #include
Common.h "#include"


Sbit LCD5110_RST_bit = P1^0; / * * / according to the hardware connection of choice
Sbit LCD5110_CE_bit = P1^1; / * * / according to the hardware connection of choice
Sbit LCD5110_DC_bit = P1^2; / * * / according to the hardware connection of choice
Sbit LCD5110_SDIN_bit= P1^3; / * * / according to the hardware connection of choice
Sbit LCD5110_SCLK_bit= P1^4; / * * / according to the hardware connection of choice

LCD5110_DC_DATA HIGH_LEVEL #define
LCD5110_DC_COMMAND LOW_LEVEL #define

LCD5110_X_AXIS_START_ADDRESS 0x80 #define
LCD5110_Y_AXIS_START_ADDRESS 0x40 #define


/***************** external interface function ******************/
/ / screen
Void LCD5110ClearAll extern (void);

/ / initialize
Void LCD5110Init extern (void);

Address / / writing
Void LCD5110AddressWriteWord extern (x UB8, y UB8, const *WCP UB8, uintLong UB8, uintNumber UB8, UW16, index);

Address / drawing
Void LCD5110AddressWritePicture extern (x UB8, y UB8, *PCP UB8, uintLong UB8, uintNumber UB8, UW16, index);
/**********************************************/


/*__LCD5110_H__*/ #endif


/*################Lcd5110.hEnd################* / 


*################ Lcd5110.cStart################*/ 

/***************************************************************************
Module: lcd5110.c

Purpose: of lcd5110 module. Implementation

Version: 0.01 12:00 2014/02/03 (OK)

Complier:Keil 8051 complier V9.01 C

MCU: STC12C5A60S2

Author: Yangrui

QQ: 279729201

Email: yangrui90s@163.com


Modification:
Desolate
11:53 2014/04/11
Reason:
1 finish

Desolate



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

<intrins.h> #include
Lcd5110.h "#include"

/ * external interface function declared in lcd5110.h.

/***************** internal function ******************/
Void LCD5110FreeBus static (void);
Void LCD5111WriteByte static (dataCode UB8, dataOrCommand bit);
/**********************************************/

/******************************************************
Function: LCD5110FreeBus
Input: N/A
Output: N/A
Return: N/A
Description: bus free (high)
Note: N/A
******************************************************/
Void LCD5110FreeBus static (void)
{
LCD5110_CE_bit = HIGH_LEVEL;
LCD5110_DC_bit = HIGH_LEVEL;
LCD5110_SCLK_bit = HIGH_LEVEL;
LCD5110_SDIN_bit = HIGH_LEVEL;
LCD5110_RST_bit = HIGH_LEVEL;
}

/******************************************************
Function: LCD5111WriteByte
Input: byte-data, or data flag command
Output: N/A
Return: N/A
Description: byte-data to LCD5110 Write
Note: dataOrCommand for 1: data (will be written to RAM)
0: command
******************************************************/
Void LCD5111WriteByte static (dataCode UB8, dataOrCommand bit)
{
UB8 i;
	
LCD5110_CE_bit = HIGH_LEVEL;
LCD5110_DC_bit = dataOrCommand;
LCD5110_SCLK_bit = HIGH_LEVEL;

LCD5110_CE_bit = LOW_LEVEL;
For (i=0; i<8; i++)
{
LCD5110_SCLK_bit = LOW_LEVEL;
LCD5110_SDIN_bit = dataCode & (>>i 0x80);
LCD5110_SCLK_bit = HIGH_LEVEL;
}
LCD5110_CE_bit = HIGH_LEVEL;

LCD5110FreeBus ();
}

/******************************************************
Function: LCD5110ClearAll
Input: N/A
Output: N/A
Return: N/A
Description screen:
Note: N/A
******************************************************/
LCD5110ClearAll void (void)
{
I UW16;
LCD5111WriteByte (0x40, LCD5110_DC_COMMAND); //Y coordinates back to 0
LCD5111WriteByte (0x80, LCD5110_DC_COMMAND); //X coordinates back to 0
	
For (i=0; i<504; i++)
{
LCD5111WriteByte (0x00, LCD5110_DC_DATA);
}
}

/******************************************************
Function: LCD5110Init
Input: N/A
Output: N/A
Return: N/A
Description: initialization LCD5110
Note: N/A
******************************************************/
LCD5110Init void (void)
{
Reset / / A
LCD5110_RST_bit = HIGH_LEVEL;
_nop_ ();
_nop_ ();
LCD5110_RST_bit = LOW_LEVEL;
_nop_ ();
_nop_ ();
LCD5110_RST_bit = HIGH_LEVEL;
	
LCD5111WriteByte (0x21, LCD5110_DC_COMMAND); / / H=1 mode
LCD5111WriteByte (0xc8, LCD5110_DC_COMMAND); / / set the Vlcd voltage
	
LCD5111WriteByte (0x20, LCD5110_DC_COMMAND); / / H=0 mode
LCD5111WriteByte (0x0c, LCD5110_DC_COMMAND); / / ordinary display mode D=1 E=0
//LCD5111WriteByte (0x0D, LCD5110_DC_COMMAND); / / D=1 E=1 embossed into reverse
//LCD5111WriteByte (0x08, LCD5110_DC_COMMAND); / / white nothing D=0 E=0
//LCD5111WriteByte (0x09, LCD5110_DC_COMMAND); / / black D=0 E=1
LCD5110ClearAll ();
}

/******************************************************
Function: LCD5110AddressWriteWord
Input:
X: value x_axis
Y: value y_axis
*WCP:Word Code Point to store the starting address array two-dimensional array of font data, such as table[0]
UintLong: two dimensional array, the length of one dimensional array
UintNumber: two-dimensional array, constitute a complete figure of the number of one-dimensional array
Index: the font in the two-dimensional array of the index 0~n
			
Output: N/A
Return: N/A
Description: N/A
Note: using PCtoLCD2002 extraction matrix, word width and high word must be an even number.
[Chinese]: in the software set the lattice value is equal to the width of the word, that is, "dot matrix = word width"
In the software, the lattice value is set to equal to the width of the word value divided by 2, that is, "dot matrix = word width /2"
Font data are stored in the "WordsCode.h" in the header file
******************************************************/
LCD5110AddressWriteWord void (x UB8, y UB8, *WCP UB8, uintLong UB8, uintNumber UB8, UW16, index)
{
Start UL32;
I J, UB8;
	
Start=uintLong * uintNumber * index; / * * / determine the starting position of the matrix data extraction
WCP=WCP+start; / * pointer to array positioning to achieve the starting position of the data.
	
For (i=0; i<uintNumber; i++)
{
LCD5111WriteByte (LCD5110_X_AXIS_START_ADDRESS|x, LCD5110_DC_COMMAND); * / /*X coordinates
LCD5111WriteByte (LCD5110_Y_AXIS_START_ADDRESS| (y+i), LCD5110_DC_COMMAND); /*Y +iLine coordinates is to ensure that the data can be automatically Chinese characters spell down one line.
		
For (j=0; j<uintLong; / / j++) will be a one-dimensional array of data output sequence
{
LCD5111WriteByte (*WCP++, LCD5110_DC_DATA);
}
}
}

/******************************************************
Function: LCD5110AddressWritePicture
Input:
X: value x_axis
Y: value y_axis
*PCP:Picture Code Point to store the starting address of two-dimensional array data matrix, such as table[0]
UintLong: two dimensional array, the length of one dimensional array
UintNumber: two-dimensional array, constitute a complete figure of the one-dimensional array of numbers
Index: the figure in the two-dimensional array of index 0~n
			
Output: N/A
Return: N/A
Description: N/A
Note: using PCtoLCD2002 extraction matrix.
[image]: to do advanced processing, the maximum width of 84, height 48.
Software set the value of the bitmap is equal to the width of the picture divided by 2, that is, "dot matrix = picture width /2"
Font data are stored in the "WordsCode.h" in the header file
******************************************************/
LCD5110AddressWritePicture void (x UB8, y UB8, *PCP UB8, uintLong UB8, uintNumber UB8, UW16, index)
{
Start UL32;
I J, UB8;
Count=0 UB8;
	
Start=uintLong * uintNumber * index; / * * / determine the starting position of the matrix data extraction
PCP=PCP+start; / * pointer to array positioning to achieve the starting position of the data.

LCD5111WriteByte (LCD5110_X_AXIS_START_ADDRESS|x, LCD5110_DC_COMMAND); * / /*X coordinates
LCD5111WriteByte (LCD5110_Y_AXIS_START_ADDRESS|y, LCD5110_DC_COMMAND); * / /*Y coordinates
	
For (j=0; j<uintLong; j++) the data are sequentially output / * * / in the one-dimensional array
{
LCD5111WriteByte (* (PCP++), LCD5110_DC_DATA);
} / / output first one-dimensional array of data
	
Count++;
	
For (i=1; i<uintNumber; i++)
{
If (Count==2)
{
LCD5111WriteByte (LCD5110_Y_AXIS_START_ADDRESS|++y, LCD5110_DC_COMMAND); //Y coordinate +1 is in order to be able to automatically down the line
LCD5111WriteByte (LCD5110_X_AXIS_START_ADDRESS|x, LCD5110_DC_COMMAND); //X coordinates
Count=0;
}
Else
{
LCD5111WriteByte (LCD5110_Y_AXIS_START_ADDRESS|y, LCD5110_DC_COMMAND); //Y coordinates
LCD5111WriteByte (LCD5110_X_AXIS_START_ADDRESS| (x+uintLong), LCD5110_DC_COMMAND); //X coordinate
}
For (j=0; j<uintLong; / / j++) will be a one-dimensional array of data output sequence
{
LCD5111WriteByte (* (PCP++), LCD5110_DC_DATA);
}
Count++;
}
}


*################ Lcd5110.cEnd################*/ 


/*################ Start################*/ wordCode.h 

_WORDCODE_H_ #ifndef
_WORDCODE_H_ #define


<reg52.h> #include
Common.h "#include"




Code wordcode1[][16]= UB8
{
/ / each (0)
/ / day (1)
/ / in (2)
/ / step (3)
/ / a (4)
/ / point (5)
/ / point (6)
Is / / (7)
/ / no (8)
Then / / (9)
/ / Jane (10)
/ / single (11)


{0x20,0x10,0x0C, 0xF3,0x12,0x12,0x52,0x92,0x12,0x12,0x12,0xF2,0x02,0x02,0x00,0x00},
{0x01,0x01,0x1F, 0x11,0x11,0x11,0x15,0x19,0x51,0x91,0x51,0x3F, 0x11,0x11,0x01,0x00}, 0*/ / * "every",

{0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xFE, 0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00},
{0x80,0x80,0x40,0x20,0x10,0x0C, 0x03,0x00,0x03,0x0C, 0x10,0x20,0x40,0x80,0x80,0x00}, 1*/ / * "days",

{0x40,0x40,0x42,0xCC, 0x00,0x80,0x88,0x88,0xFF, 0x88,0x88,0xFF, 0x88,0x88,0x80,0x00},
{0x00,0x40,0x20,0x1F, 0x20,0x40,0x50,0x4C, 0x43,0x40,0x40,0x5F, 0x40,0x40,0x40,0x00}, 2*/ / * "into"

{0x40,0x40,0x40,0x7C, 0x40,0x40,0x40,0xFF, 0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00},
{0x80,0x90,0x88,0x46,0x40,0x40,0x20,0x2F, 0x10,0x10,0x08,0x04,0x02,0x00,0x00,0x00}, 3*/ / * "step"

{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} / *, "one", 4*/

{0x00,0x00,0xC0,0x40,0x40,0x40,0x7F, 0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x00,0x00},
{0x80,0x40,0x37,0x04,0x04,0x14,0x64,0x04,0x14,0x64,0x04,0x07,0x10,0xE0,0x00,0x00} / * "point", 5*/

{0x00,0x00,0xC0,0x40,0x40,0x40,0x7F, 0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x00,0x00},
{0x80,0x40,0x37,0x04,0x04,0x14,0x64,0x04,0x14,0x64,0x04,0x07,0x10,0xE0,0x00,0x00} / * "point", 6*/

{0x04,0xE4,0x25,0x26,0x24,0xE4,0x04,0x20,0x20,0xFF, 0x20,0xE2,0x2C, 0x20,0x20,0x00},
{0x10,0x4B, 0x82,0x7E, 0x02,0x0B, 0x90,0x60,0x1C, 0x03,0x00,0x3F, 0x40,0x40,0x70,0x00}, 7*/ / * ""

{0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E, 0x42,0x82,0x02,0x02,0x02,0x00,0x00},
{0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF, 0x00,0x00,0x00,0x01,0x02,0x0C, 0x00,0x00}, 8*/ / * "no".

{0x02,0x02,0xF2,0x92,0x92,0x92,0x92,0xFE, 0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0x00},
{0x04,0x04,0xFF, 0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x44,0x84,0x7F, 0x04,0x04,0x00}, 9*/ / * "again."

{0x08,0x04,0xC3,0x12,0x26,0x8A, 0xA2,0xAA, 0xA4,0xA3,0x22,0x26,0xEA, 0x02,0x02,0x00},
{0x00,0x00,0xFF, 0x00,0x00,0x3F, 0x24,0x24,0x24,0x3F, 0x00,0x80,0xFF, 0x00,0x00,0x00}, 10*/ / * "Jane",

{0x00,0x00,0xF8,0x49,0x4A, 0x4C, 0x48,0xF8,0x48,0x4C, 0x4A, 0x49,0xF8,0x00,0x00,0x00},
{0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF, 0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00}, 11*/ / * "single"


};
Code wordcode2[][8]= UB8
{


{0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18},
{0x00,0x20,0x20,0x3F, 0x20,0x20,0x00,0x00}, F, 0*/ / *


{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x19,0x24,0x22,0x22,0x22,0x3F, 0x20}, a, 1*/ / *



};
Code Pic[12][42]= UB8
{

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0x78,0x78,0x38,0x38,0x38,0x3C, 0x3C, 0x1C, 0xDC, 0xCC, 0xDA, 0x52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07,0x07,0x0F, 0x07,0x0F, 0x1F, 0x1F, 0x1F, 0x3D, 0x3D, 0x3D, 0x38,0x3C, 0x3C, 0x38,0x7F, 0x7F, 0x70,0x7F, 0x7F, 0x70,0x7F, 0x7F, 0x70},
{0x77,0x7F, 0x7F, 0x7B, 0x7F, 0x7F, 0x7F, 0x7B, 0x7F, 0x7F, 0x3F, 0x3C, 0x3F, 0x1F, 0x1C, 0x1C, 0x1D, 0x0F, 0x0F, 0x0E, 0x0F, 0x0F, 0x07,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, C:\Users\lenovo\Desktop\5110\Pic\C_129_conew1.bmp, 0*/ / *


};
#endif


/*################ End################*/ wordCode.h 


Supplement: common.h

__COMMON_H__ #ifndef
__COMMON_H__ #define

Unsigned char UB8 typedef;
Unsigned short int UW16 typedef;
Unsigned long UL32 typedef;

Char SB8 typedef;
Short int SW16 typedef;
Long SL32 typedef;
	
HIGH_LEVEL #define 1
LOW_LEVEL #define 0


/*__COMMON_H__*/ #endif


top
Zero
step on
Zero

Reference knowledge base

Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit:42884 times
    • Integral:Eight hundred and four
    • Grade:
    • Rank:Thousands of miles away
    • Original:35
    • Reproduced:0
    • Translation:0
    • Comments:25
    Latest comments