Single-Chip Microcomputer with font 12864 display Rectangular Wave

Source: Internet
Author: User
Tags response code

# Include <reg52.h>
# Include <intrins. h>
# Include <math. h>
// ------------ Define the interface -------------//
Sbit rs = P2 ^ 2;
Sbit RW = P2 ^ 3;
Sbit E = P2 ^ 4;
Sbit PSB = P2 ^ 5; // H = parallel port; L = "Serial Port ";
# Define LCD _bus P0
// P0 connect to LCM
# Define uchar unsigned char
# Define first_addr 0
// Define the character/start position of the Chinese Character Display
/* ------------------ Check the busy position -----------------------------*/
Void chk_busy ()
{
Rs = 0;
RW = 1;
E = 1;
LCD _bus = 0xff;
While (LCD _bus & 0x80) = 0x80 );
E = 0;
}
/* ---------------- Latency subroutine -----------------------------*/
Void delay (unsigned int T)
{
Unsigned int I, J;
For (I = 0; I <t; I ++)
For (j = 0; j <10; j ++ );
}

/* ---------------- Write the command to LCD ------------------------------*/
Void write_com (unsigned char encoding code)
{
Chk_busy ();
Rs = 0;
RW = 0;
E = 1;
LCD _bus = response code;
Delay (5 );
// ------------------ Add the appropriate latency when writing data
E = 0;
Delay (5 );
}

/* ------------------- Write data to LCD ----------------------------*/
Void write_data (unsigned char dispdata)
{
Chk_busy ();
Rs = 1;
RW = 0;
E = 1;
LCD _bus = dispdata;
Delay (5 );
// ------------------ Add the appropriate latency when writing data
E = 0;
Delay (5 );
}
/* ---------------- Initialize the LCD screen --------------------------*/
Void lcdreset ()
{
PSB = 1;
Delay (2000 );
Write_com (0x30 );
Delay (10 );
// Select the Basic Instruction Set
Write_com (0x30 );
// Select an 8-Bit Data Stream
Delay (5 );
Write_com (0x0c );
// Open display (no cursor or reversed)
Delay (10 );
Write_com (0x01 );
// Clear the display and set the address pointer to 00 h
Delay (500 );
Write_com (0x06 );
// Specify the moving direction of the cursor and the shift of the specified display when reading and writing data.
Delay (0 );
}
/* ------------------ Display string --------------------------*/
Void hzkdis (unsigned char Code * s)
{
While (* s> 0)
{
Write_data (* s );
S ++;
Delay (50 );
}
}
/* ------------------ Display on the first screen --------------------------*/
Void Ceshi ()
{
Write_com (0x01 );
// Clear the display and set the address pointer to 00 h
Delay (5 );

Write_com (0x80 );
// The first line (if the address is: 80 h, that is, the first position of the first line of the LCD)
Hzkdis ("Nanjing University of Posts and Telecommunications ");

Write_com (0x90 );
// The second line (if the address is: 90 H, that is, the first position of the second line of the LCD)
Hzkdis ("Communication and Information Engineering ");

Write_com (0x88 );
// Line 3 (if the address is 88 h, that is, the first position of the second line of the LCD)
Hzkdis ("Electronic Information Engineering ");

Write_com (0x98 );
// Line 4 (if the address is: 98 H, that is, the first position of the second line of the LCD)
Hzkdis ("Zheng Haibo test program ");
}
// ------------------ Clear the entire gdram space ----------------------------
Void clrgdram ()
{
Unsigned char X, Y;
For (y = 0; y <64; y ++)
For (x = 0; x <16; X ++)
{
Write_com (0x34 );
Write_com (Y + 0x80 );
// Line address
Write_com (x + 0x80 );
// Column address
Write_com (0x30 );
Write_data (0x00 );
Write_data (0x00 );
}
}
//------------------------------------------------------------
Void clrscreen ()
{
Write_com (0x01 );
Delay (10 );
}
Unsigned char readbyte (void)
{
Unsigned char byreturnvalue;
Chk_busy ();
LCD _bus = 0xff;
Rs = 1;
RW = 1;
E = 0;
E = 1;
Byreturnvalue = LCD _bus;
E = 0;

Return byreturnvalue;
}

/* Add a painting subroutine.
Function: draws a vertex at the coordinate (x, y ).
Parameter meaning
X: the abscissa of the 12864 screen, ranging from 0 to 128 (left to right)
Y: The ordinate of 12864, ranging from 0 to 64 (from top to bottom)
When color is set to 1, it indicates a black spot.
*/
Void drawpoint (unsigned char X, unsigned char y, unsigned char color)
{
Unsigned char row, tier, tier_bit;
Unsigned char readoldh, readoldl;
Write_com (0x34 );
Write_com (0x36 );
Tier = x> 4;
Tier_bit = x & 0x0f;
If (Y <32)
{
Row = y;
}
Else
{
Row = Y-32;
Tier + = 8;
}
Write_com (row + 0x80 );
Write_com (Tier + 0x80 );
Readbyte ();
Readoldh = readbyte ();
Readoldl = readbyte ();
Write_com (row + 0x80 );
Write_com (Tier + 0x80 );
If (tier_bit <8)
{
Switch (color)
{
Case 0:
Readoldh & = (~ (0x01 <(7-tier_bit )));
Break;
Case 1:
Readoldh | = (0x01 <(7-tier_bit ));
Break;
Case 2:
Readoldh ^ = (0x01 <(7-tier_bit ));
Break;
Default:
Break;
}
Write_data (readoldh );
Write_data (readoldl );
}
Else
{
Switch (color)
{
Case 0:
Readoldl & = (~ (0x01 <(15-tier_bit )));
Break;
Case 1:
Readoldl | = (0x01 <(15-tier_bit ));
Break;
Case 2:
Readoldl ^ = (0x01 <(15-tier_bit ));
Break;
Default:
Break;
}
Write_data (readoldh );
Write_data (readoldl );
}
Write_com (0x30 );
}
Void juxingbo (void) // display the Rectangular Wave
{
Uchar I, j, color = 1, flag = 0;
Uchar Zhan = 20; // time length of level '1'
Uchar high = 2; // High Position
Uchar low = 62; // low level position
For (I = 0; I <128; I ++)
{
If (I % Zhan = 0)
{
For (j = high; j <= low; j ++)
Drawpoint (I, j, color );
If (flag = 0)
Flag = 1;
Else
Flag = 0;
}
Else
{
If (flag = 0)
J = high;
Else
J = low;
Drawpoint (I, j, color );
}
}
}
Void main (void)
{
 
RW = 0;
Lcdreset ();
Ceshi ();
Clrgdram ();
Delay (2000 );
Clrscreen ();
Juxingbo ();
Delay (5000 );
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.