lcd1602 Liquid Crystal

Source: Internet
Author: User
Tags 0xc0 clear screen
Include<reg52.h>//Contains header file, general situation does not need to change, header file contains the definition of special function register
#include <intrins.h>


Sbit RS = p2^6; Defining ports
Sbit RW = p2^5;
Sbit EN = p2^7;
Sbit SPK = p3^0;


unsigned char time[] = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};
unsigned char *clock = "23:59:54";
unsigned char hour,minute,second = 58,num;
unsigned char keyscan1 (void);
unsigned char updatetimerflag;


#define RS_CLR Rs=0
#define Rs_set Rs=1


#define RW_CLR rw=0
#define Rw_set Rw=1


#define EN_CLR en=0
#define En_set En=1


#define Dataport P0
#define Keyport P1


void Init_timer0 ();
void Gong_zi ();
void Clock_1 ();
void Clock_2 ();


void Delayus (unsigned char t)
{
while (--T);
}


void delayms (unsigned char t)
{
while (t--)
{
Delayus (245);
Delayus (245);
}
}


Function of a busy sentence
Bit lcd_check_busy ()
{
dataport = 0xFF;
RS_CLR;
Rw_set;
EN_CLR;
_nop_ ();
En_set;
return (BIT) (dataport & 0x80);


}


Write Command function
void lcd_write_com (unsigned char Com)
{
while (Lcd_check_busy ()); Busy is waiting for
Delayms (5);
RS_CLR;
RW_CLR;
En_set;
dataport = com;
_nop_ ();
EN_CLR;


}


Write Data functions
void Lcd_write_data (unsigned char Data)
{
while (Lcd_check_busy ()); Busy is waiting for
Delayms (5);
Rs_set;
RW_CLR;
En_set;
Dataport= Data;
_nop_ ();
EN_CLR;
}


Clear Screen function
void Lcd_clear ()
{
Lcd_write_com (0x01);
Delayms (5);
}


Write String function
void lcd_write_string (unsigned char x,unsigned char y,unsigned char *s)
{
if (y = = 0)
{
Lcd_write_com (0x80 +x);
}
Else
{
Lcd_write_com (0XC0+X);
}
while (*s)
{
Lcd_write_data (*s);
s++;
}

}


Write character function
void Lcd_write_char (unsigned char x,unsigned char y,unsigned char Data)
{
if (y = = 0)
{
Lcd_write_com (0x80 +x);
}
Else
{
Lcd_write_com (0XC0+X);
}
Lcd_write_data (Data);
}


initialization function


void Lcd_init ()
{
Lcd_write_com (0x38);
Delayms (5);
Lcd_write_com (0x38);
Delayms (5);
Lcd_write_com (0x38);
Delayms (5);
Lcd_write_com (0x38);
Lcd_write_com (0x08);
Lcd_write_com (0x01);
Lcd_write_com (0x06);
Delayms (5);
Lcd_write_com (0x0c);
}


/*void t0_time () Interrupt 1
{
TH0 = 0xd8;
TL0 = 0XF0;
min_sec++;
if (min_sec = 100)
{
min_sec = 0;
sec++;
if (sec = 60)
{
SEC = 0;
}
}

} */


Main function
void Main ()
{
unsigned char i;
unsigned char *p;
Lcd_init ();
Lcd_clear ();
/* Tmod = 0X01;
TH0 = 0xd8;
TL0 = 0XF0;
EA = 1; Open Total Interrupt
ET0 = 1; Open Timer 0
TR0 = 1; Start Timer 0 * *
/* while (1)
{
i = 1;
p = "Hello world!";
Lcd_clear ();
Lcd_write_string (2,0, "Yzh");
Delayms (250);
while (*P)
{
Lcd_write_char (I,1,*P);
i++;
p++;
Delayms (250);
}
Delayms (250);
}
Gong_zi ();
Clock_1 ();
Lcd_write_com (0x87);
Lcd_write_data (0x00);
} */
Clock_2 ();


}
/*void Gong_zi ()
{
Lcd_write_com (0x40);
Lcd_write_data (0x1f);
Lcd_write_com (0x41);
Lcd_write_data (0x1f);
Lcd_write_com (0x42);
Lcd_write_data (0x04);
Lcd_write_com (0x43);
Lcd_write_data (0x04);
Lcd_write_com (0x44);
Lcd_write_data (0x04);
Lcd_write_com (0x45);
Lcd_write_data (0x04);
Lcd_write_com (0x46);
Lcd_write_data (0x1f);
Lcd_write_com (0x47);
Lcd_write_data (0x1f);
}*/

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.