12864 Driver Based on 51 Single-Chip Microcomputer

Source: Internet
Author: User

/************** Dis_12864.h ***************/

# Include <reg52.h>


# Ifndef _ dis_12864_h __
# DEFINE _ dis_12864_h __

# Define uchar unsigned char
# Define uint unsigned int

/* 12864 port definition */
# Define LCD _data P0 // data port
Sbit LCD _rs = p1 ^ 0; // register selection Input
Sbit LCD _rw = p1 ^ 1; // LCD read/write control
Sbit LCD _en = P2 ^ 5; // LCD enabling control

Sbit LCD _psb = p1 ^ 2; // string/parallel control


/* Function declaration */
Void delay (int ms );
Void LCD _init ();
Void BEEP ();
Void dataconv ();
Void LCD _pos (uchar X, uchar y); // determine the display position
Void zifu_dis (uchar X, uchar y, uchar * Dis );

# Endif




/************** Dis_12864.c ***************/

# Include <dis_12864.h>

/*************************************** ****************************/
// Latency Function
/*************************************** ****************************/
Void delay (ms int)
{
While (MS --)
{
Uchar I;
For (I = 0; I <250; I ++)
{
;;;;
}
}
}
/*************************************** ****************************/
/* Check the LCD busy status */
/* When LCD _busy is 1, it is busy. Wait. When LCD-busy is 0, it is idle and can write commands and data. */
/*************************************** ****************************/
Bit LCD _busy ()
{
Bit result;
LCD _rs = 0;
LCD _rw = 1;
LCD _en = 1;
Delay (1 );
Result = (BIT) (LCD _data & 0x80 );
LCD _en = 0;
Return (result );
}
/*************************************** ****************************/
/* Write command data to LCD */
/* Rs = L, RW = L, E = high pulse, D0-D7 = instruction code. */
/*************************************** ****************************/
Void LCD _wcmd (uchar cmd)
{
While (LCD _busy ());
LCD _rs = 0;
LCD _rw = 0;
LCD _en = 0;
Delay (1 );
LCD _data = cmd;
Delay (1 );
LCD _en = 1;
Delay (1 );
LCD _en = 0;
}
/*************************************** ****************************/
/* Write the display 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;
LCD _data = dat;
Delay (1 );
LCD _en = 1;
Delay (1 );
LCD _en = 0;
}
/*************************************** ****************************/
/* LCD initialization settings */
/*************************************** ****************************/
Void LCD _init ()
{


LCD _psb = 1; // parallel port Mode

LCD _wcmd (0x34); // extended command operation
Delay (5 );
LCD _wcmd (0x30); // basic command operation
Delay (5 );
LCD _wcmd (0x0c); // display on, close the cursor
Delay (5 );
LCD _wcmd (0x01); // clear the LCD display content
Delay (5 );
}


/*************************************** ******************/
/* Set the display position X: number of rows Y: Number of columns */
/*************************************** ******************/
Void LCD _pos (uchar X, uchar y)
{
Uchar Pos;
If (x = 0)
{X = 0x80 ;}
Else if (x = 1)
{X = 0x90 ;}
Else if (x = 2)
{X = 0x88 ;}
Else if (x = 3)
{X = 0x98 ;}
Pos = x + y;
LCD _wcmd (POS); // display address
}

/*************************************** ******************/
/* Display characters (strings) at the specified position )*/
/*************************************** ******************/
Void zifu_dis (uchar X, uchar y, uchar * Dis)
{
Uchar I;
LCD _pos (x, y );
I = 0;
While (DIS [I]! = '\ 0 ')
{// Display characters
LCD _wdat (DIS [I]);
I ++;
}
}



/************* Main. c ***** test ***********/

# Include <reg52.h>
# Include <intrins. h>
# Include <dis_12864.h>

Uchar code dis1 [] = {"gz_go blog "};
Uchar code dis2 [] = {"www.csdn.net "};
Uchar code dis3 [] = {"keep learning! "};
Uchar code dis4 [] = {"keep thinking! "};

Void main (void)
{
Delay (10); // latency
LCD _init (); // initialize the LCD
Zifu_dis (, "csdncsdn"); // the essence of the string returned is its starting address in the memory.
Zifu_dis (1, 0, dis2 );
Zifu_dis (2, 0, dis3 );
Zifu_dis (3, 0, dis4 );
While (1 );
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.