Home > Back-end >  I first use the problems in the LCD12864 procedure
I first use the problems in the LCD12864 procedure

Time:12-05

I first learn to use LCD12864
Beginners are copied the sentence by sentence, ace to skip! Program in more than a pile of useless things, to understand, to for a long time, find the pos=X + Y, also can not get the answer, in this paper, the answer came: the program without Y, (when I learn to use Y, to share with you)
Experience:
I use intertek TX - 1 c development board, download the CD 12864 - a - 3 c source program (E: new concept 51 singlechip c language tutorial \ \ 3. The CD data sample code and module data \ 2. Extension module \ LCD \ 12864 3.12864 with character test procedure), and found some mistakes and not language sentence, definition, for the convenience of the beginners to learn, as I do now post, for reference only, please the teacher to correct the wrong place,
(1) line 35 to 39, definition and declaration is not used, respectively is:
Uchar IRDIS [2].
Uchar IRCOM [4].
Void delay0 (uchar x);
Void beep ();
Void dataconv ();
40 other void lcd_pos (uchar uchar X, Y);
Now changed to void lcd_pos (uchar X); Y parameter definition is not used, the graphics GDRAM operation should be used when Y,
(2) 74 lines result=(bit) (P0 & amp; 0 x80); Really means: "the result is 1 for busy,
0 is empty, and returns the data
(3) 148 lines lcd_pos (0, 0);//set the display position to the first line of the first character,
Instead of lcd_pos (0); Only to x, with less than Y, I for pos=x + Y headache for a long time,
(4) 182 ~ 195 lines, the time delay function in a program is not called,
(5) 214 lines of pos=X + Y; To: pos=X;
0 error warning, download, display pictures as follows:


C language source program:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* this program I was tested, modified the unused part and the wrong place, such as pos=X + Y, this way, should be used in the graphics operations,
This procedure 0 error warning
LCD models: TS12864A - 3 (with Chinese character) or compatible model controller ST7920
MCU: STC89S52, crystal frequency: 11.0592 MHz */
/* [the statement] this program is used only for study and reference, reference please indicate copyright and author information! */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include
#include //null operation and cyclic shift instructions

# define uchar unsigned char
# define uint unsigned int

/* 12864 port definitions */
# define LCD_data P0/mouth/data
Sbit LCD_RS=P3 ^ 5;//register select input
Sbit LCD_RW=P3 ^ 6;//LCD read/write control
Sbit LCD_EN=P3 ^ 4;//LCD that can control the
Sbit LCD_PSB=P3 ^ 7;//string and the method of controlling the
Sbit wela=P2 ^ 6;
Sbit dula=P2 ^ 7;

Uchar code dis1 []={" intertek electronic "};
Uchar code dis2 []={" www.txmcu.com "};
Uchar code dis3 []={" TX - 1 - c development board to take you "};
Uchar code dis4 []={" to the world of MCU "};

# define delayNOP (); {_nop_ (); _nop_ (); _nop_ (); _nop_ (); };
/* uchar IRDIS [2];//not used
Uchar IRCOM [4].
Void delay0 (uchar x);//* 0.14 x MS not used
Void beep ();
Void dataconv ();
Void lcd_pos (uchar X, uchar Y);//determine the display position */
Void lcd_pos (uchar X);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */delay function
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay (int ms)
{
While (ms -)
{
Uchar I;
for(i=0; i<250; I++)
{
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* check LCD busy state */
/* lcd_busy to 1, busy, waiting, 0 for LCD - busy, idle, can be written instructions and data, */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Bit lcd_busy ()
{
Bit result;
LCD_RS=0;
LCD_RW=1;
LCD_EN=1;
DelayNOP ();
Result=(bit) (P0 & amp; 0 x80);//the result is 1 for busy, 0 is empty, returns the data
LCD_EN=0;
Return (result);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
/* written instruction data to the LCD
/* RS=L, RW=L, E=high pulse, D0 - D7=order code, */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void lcd_wcmd (uchar CMD)
{
While (lcd_busy ());//1, a waiting, 0 when executing the following program
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
_nop_ ();
_nop_ ();
P0=CMD;
DelayNOP ();
LCD_EN=1;
DelayNOP ();
LCD_EN=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
/* to write data to the LCD
/* RS=H, RW=L, E=high pulse, D0 - D7=data, */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void lcd_wdat (uchar dat)
{
While (lcd_busy ());
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
DelayNOP ();
LCD_EN=1;
DelayNOP ();
LCD_EN=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
/* LCD initialization setting */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void lcd_init ()
{

LCD_PSB=1;//parallel way

Lcd_wcmd (0 x34);//expanded instruction
delay(5);
Lcd_wcmd (0 x30);//basic instruction operation
delay(5);
Lcd_wcmd (0 x0c);//display on and off the cursor
delay(5);
Lcd_wcmd (0 x01);//remove the LCD display content
delay(5);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* the main program */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The main ()
{
Uchar I;
delay(10);//delay
wela=0;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related