Home > Blockchain >  Liquid crystal display program
Liquid crystal display program

Time:09-17

# include
# include
# include
# define Uchar unsigned char
/* note: 8031 crystal vibration frequency of 12 MHZ */
/* * * * * * * * * * * LCD interface pin definition * * * * * * * * * * * * * * */
Sbit Elcm=P2 ^ 7;
Sbit CSALCM=P2 ^ 2;
Sbit CSBLCM=P2 ^ 3;
Sbit Dilcm=P2 ^ 0;
Sbit Rwlcm=P2 ^ 1;
SFR Datalcm=0 x80;/* * mouth/
/* * * * * * * * * * * commonly used commands and parameters definition * * * * * * * * * * * * * * */
# define DISPON 0 x3f/* on */
# define DISPOFF 0 x3e/* show off */
# define DISPFIRST 0 xc0/* display the starting line defines */
# define your SETX 0 x40/* X position setting instruction (pp) */
# define SETY 0 xb8/* Y location setting instruction (column) */
# define Lcdbusy 0 x80/* LCM busy judging a */

/* * * * * * * * * * * * * * according to partition the boundary location * * * * * * * * * * * * * * * * */
# define MODL 0 x00/* left area */
# define MODM 0 x40/* left area and the central division */
# define MODR 0 x80/* the central area and right boundary */
# define LCMLIMIT 0 xc0/* shows the right boundary */

/* * * * * * * * * * * * * * * * global variable definition * * * * * * * * * * * * * * * * * * */
Uchar col, row, cbyte;/* column, the x line (pp) y, output data */
Bit, y;/* line drawing direction sign: 1 level */

/* * * * * * * * * * * * * * * * * function list * * * * * * * * * * * * * * * * * * * * * */
Void Lcminit (void); LCD module initialization/* */
Void Delay (Uchar);/* time delay, the entry for Ms */
Void lcdbusyL (void);/* busy, waiting for the (l) */
Void lcdbusyM (void);/* busy, waiting for the (central) */
Void lcdbusyR (void);/* busy, waiting for the (right) */
Void Putedot (Uchar); Half-width characters/* o */
Void Putcdot (Uchar);/* all Angle (Chinese characters) o */
Void Wrdata (Uchar);/* data output to LCM */
Void Lcmcls (void);/* LCM full-screen zero (0) filled */
Void wtcom (void);/* public busy wait */
Void Locatexy (void); The cursor *//*
Void WrcmdL (Uchar);/* left area command output */
Void WrcmdM (Uchar); The central command output/* */
Void WrcmdR (Uchar); Right area command output/* */
Void Putstr (Uchar * puts, Uchar I); String output in both English and Chinese/* */
Void Rollscreen (Uchar x); Screen scroll up/* */
Void Rddata (void);/* read data from the LCD tablet */
Void Linehv (Uchar length); Draw a line/* horizontal (vertical) direction */
The void point (void); Dot/* */
Void Linexy (Uchar endx, Uchar endy);

/* * * * * * * * * * * * * * * * * * an array list * * * * * * * * * * * * * * * * * * * * */
Uchar code Ezk [];/* routine ASCII character lattice clock */
Uchar code Hzk []; Use Chinese characters dot matrix clock */*/
Uchar code STR1 [];/* */custom string
Uchar code STR2 [];
Uchar code STR3 [];
Uchar code STR4 [];

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the main program * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main (void)
{
Uchar x;
Col=0;
The row=0;
Delay (40); About 40 ms/* delay, waiting for the peripherals ready */
Lcminit ();/* LCD module initialization, including full screen screen clearing */
Putstr (STR1, 12);/* the first line output character, 12 bytes */
Col=0;
The row=2;
Putstr (STR2, 14);/* the second line output character, 14 bytes */
Col=0;
The row=4;
Putstr (STR3, 11);/* the third line output character, 11 bytes */
Col=0;
The row=6;
Putstr (STR4, 12);/* the fourth line output character, 12 bytes */
X=0;
Col=0;
The row=0;
Y=1;/* direction signs, as the horizontal direction */
Linehv (192);/* draw a horizontal line (0, 0) - (191, 0) */
Col=0;
The row=15;
Y=1;
Linehv (192);/* draw a horizontal line (0 (9) - (191) */
Col=0;
The row=32;
Y=1;
Linehv (192); Aiaa/* draw a horizontal line (0) - (191, 32) */
Col=0;
The row=1;
X, y=0;/* direction signs, as the vertical direction */
Linehv (31). Draw a vertical bar/* (0, 1) - (0, 31) */
Col=191;
The row=1;
X, y=0;
Linehv (31). Draw a vertical bar/* (191, 1) - (191, 31) */
Col=0;/* set slash starting point coordinate */
The row=63;
Linexy (44, 31);/* draw a slash tobacco (0) - (44, 31) */
Col=44;
The row=31;
Linexy on conversion (190); Slash (44, 31) -/* continues to paint (191 tobacco) */
While (1) {
Rollscreen (x);/* to locate new display the starting line */
X++;
Delay (100);/* delay, control the rolling speed */
};
}

/* * * * * * * * * * * * * * * * * * * * * * * line drawing, arbitrary direction of diagonal lines, does not support the vertical or horizontal line * * * * * * * * * * * * * * * * * * * * * * */
Void Linexy (Uchar endx, Uchar endy)
{
The register Uchar t;
Int xerr=0, yerr=0, delta_x and delta_y, short;
Uchar incx incy;
Delta_x=endx - col; Calculating the distance of two direction *//*
Delta_y=endy - row;
If (delta_x & gt; 0 incx)=1;/* to calculate incremental direction, increment of 0 said neither vertical nor horizontal line */
Else if (delta_x==0) incx=0;
The else incx=1;
If (delta_y & gt; 0) incy=1;
Else if (delta_y==0) incy=0;
The else incy=1;
Delta_x=cabs (delta_x);/* determine which is the larger distance */
Delta_y=cabs (delta_y);
If (delta_x & gt; Delta_y) short=delta_x;
The else short=delta_y;
Began to draw lines/* */
For (t=0; T & lt;=short + 1; T++) {
Point ();
Xerr +=delta_x;
Yerr +=delta_y;
If (xerr & gt; Short) {
Xerr -=short;
Col +=incx;
}
If (yerr & gt; Short) {
Yerr -=short;
The row +=incy;
}
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * line drawing, only provide X or Y direction, do not support the diagonal lines * * * * * * * * * * * * * * * * * * * * * * * * */
Void Linehv (Uchar length)
{
Uchar xs and ys.
If (x, y) {ys=col;
For (xs=0; XsCol=ys + xs;
Point (); }
}
The else {xs=row;
For (ys=0; Ys{
The row=xs + ys;
Point (); }
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * draw point * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The void point (void)
{
Uchar x1, y1, x, y;
X1=col;
Y1=row;
The row=y1 & gt;> 3;/* Y direction page address */
Rddata ();
Y=y1 & amp; 0 x07;/* byte position calculation */
X=0 x01;
X=x<& lt; y;/* to painted point */
Wrdata (cbyte | x);/* * on screen/
Col=x1;/* */restore the xy coordinates
The row=y1;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * screen scroll position * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Rollscreen (Uchar x)
{
Cbyte=DISPFIRST | x;/* define x display the starting behavior? */
WrcmdL (cbyte);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related