<meta name="keywords" content="必胜时时彩开户,keywords" /> AT89C51单片机驱动液晶显示汉字C语言 联系我们

AT89C51单片机驱动液晶显示汉字C语言


此法式模范模范的完全工程文件下载:http://mamjap.com/f/8952lkj_c.rar  上图是原理图及其仿真效果.

/*******************************************************************
 AT89C51单片机驱动液晶显示汉字C语言
****************************************************************/
#include<AT89x51.h>
#define uchar unsigned char
/*****************************************
电路毗连

P1------DB0~DB7
P2.0------RS
P2.1------RW
P2.2------E
*****************************************/
#define LCD_DB P1
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
sbit cs1=P2^6;
sbit cs2=P2^7;
 uchar code kk[] = {
      //"陕",
      0xFE,0x82,0x1A,0xE6,0x4C,0x74,0x44,0xFF,
      0x64,0x5C,0x46,0x44,0x0F,0x00,0x01,0x08,
      0x08,0x04,0x03,0x00,0x01,0x02,0x04,0x08};
 uchar code xi[]={//"西",
      0x02,0xFA,0x0A,0x8A,0x7E,0x0A,0x0A,0xFE,
      0x8A,0x8A,0xFB,0x02,0x00,0x0F,0x05,0x04,
      0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00};
 uchar code dian[]={//"电",
   0x00,0xFC,0x24,0x24,0x24,0xFF,0x24,0x24,
      0x24,0xFE,0x04,0x00,0x00,0x01,0x01,0x01,
      0x01,0x07,0x09,0x09,0x09,0x09,0x08,0x0E};
uchar code zi[]={//"子",
      0x00,0x20,0x21,0x21,0x21,0x21,0xF9,0x25,
      0x23,0x21,0x30,0x20,0x00,0x00,0x00,0x04,
      0x08,0x08,0x0F,0x00,0x00,0x00,0x00,0x00};
uchar code ke[]={//"科",
      0x8A,0x4A,0xFF,0x29,0x49,0x08,0x22,0xCC,
      0x80,0xFF,0x40,0x40,0x01,0x00,0x0F,0x00,
      0x00,0x01,0x01,0x00,0x00,0x0F,0x00,0x00};
uchar code ji[]={//"技",
      0x48,0x48,0xFF,0x28,0x28,0x64,0xA4,0x3F,
      0xA4,0x64,0x26,0x04,0x04,0x08,0x07,0x08,
      0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x08};
uchar code xue[]={ //"学",
      0x20,0x18,0x29,0x2E,0x28,0xA9,0xAE,0x68,
      0x2C,0x0B,0x98,0x08,0x01,0x01,0x01,0x01,
      0x05,0x09,0x0F,0x01,0x01,0x01,0x01,0x01};
uchar code yuan[]={//"院",
      0xFE,0x02,0x1A,0xE6,0x48,0x54,0xD4,0x55,
      0xD6,0x54,0x54,0x4C,0x0F,0x01,0x02,0x09,
      0x08,0x04,0x03,0x00,0x07,0x08,0x08,0x0E};
uchar code yu[]={//"余",
      0x20,0x50,0x48,0x54,0x52,0xF1,0x52,0xD4,
      0x48,0x50,0x60,0x20,0x08,0x04,0x02,0x05,
      0x08,0x0F,0x00,0x00,0x01,0x02,0x04,0x08};
uchar code lao[]={//"老",
      0x10,0x14,0x14,0x94,0x94,0x5F,0x34,0x9C,
      0x94,0x12,0x18,0x10,0x02,0x02,0x01,0x00,
      0x07,0x09,0x09,0x08,0x08,0x08,0x0E,0x00};
uchar code shi[]={//"师",
      0x00,0xFC,0x00,0xFF,0x00,0xFA,0x0A,0x0A,
      0xFE,0x0A,0x0B,0xFA,0x00,0x09,0x04,0x03,
      0x00,0x03,0x00,0x00,0x0F,0x00,0x02,0x03};
/******界说函数****************/
void  LCD_init(void);//声明初始化函数
void  LCD_write_command(uchar command);//写指令函数
void  LCD_write_data(uchar dat);//写数据函数
void  LCD_disp_char(uchar x,uchar y,uchar dat);//在某个屏幕职位上显示一
//个字符,X(0-16),y(1-2)
//void  LCD_check_busy(void);//检查忙函数。我没用到此函数,由于经由历程率极低。
void  delay(uint n);//延时函数
//********************************
//*******初始化函数***************
void  LCD_init(void)
{
LCD_write_command(0x38);//设置8位名堂,2行,5x7
LCD_write_command(0x0c);//所有显示,关光标,不闪灼
LCD_write_command(0x06);//设定输入要领,增量不移位--------------
LCD_write_command(0x01);//扫除屏幕显示----------------
delay(100);//现实证实,我的LCD1602上,用for 循环200 次便可以可靠完成清屏指令。
}
//********************************
//********写指令函数***********设置先向1602写入的数据为地址*
void   LCD_write_command(uchar dat)
{
LCD_DB=dat;
LCD_RS=0;//指令
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;//发生降低沿
delay(1);//现实证实,我的LCD1602 上,用for 循环1 次便可以完成浅易写指令。
}
//*******************************
//********再写数据函数*****向1602中写入数据********
void   LCD_write_data(uchar dat)
{
LCD_DB=dat;
LCD_RS=1;//数据
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;//发生降低沿
delay(1);
}
void   writeDataLcd(unsigned char dat)// 写入数据
  {
    LCD_RS=1; //RS置1    (运算后P5=xxx1 xxxx,即RS=1其他位状态稳固)
    LCD_RW=0; //RW清0   (运算后P5=xx0x xxxx, 即RW=0其他位状态稳固)
    LCD_E=0; //使能E清0   (运算后P5=xxxx 0xxx, 即E=0其他位状态稳固)
    P1  =  dat;  //送数据到P2OUT准备输入进入1602,等E降低沿来便可进入1602.
    LCD_E=1;  //使能E置1,P5OUT= xxxx xxxx+0000 1000=xxxx1xxx,E=1.
    delay(10);
    LCD_E=0; //使能E清0,这样E从1变0,发生一个降低,写入敕令到1602。
  }

//********************************
//*******显示一个字符函数*********
void LCD_disp_char(uchar x,uchar y,uchar dat)
{
 if(y>=64)
  {
  y=y-1;
  }
 LCD_write_command(0x40|y);
 delay(10);
 LCD_write_command(0xb8|x);
 LCD_write_data(dat);
}
//********************************
/*******检查忙函数*************
voidLCD_check_busy()       
 //现实证实,在我的LCD1602 上,检查忙指令通
过率极低,以致于不克不及正常应用LCD。是以我没有再用检查忙函数。而使
do//用了延时的措施,延时还是异常好用的。我试了一下,用//
{LCD_E=0;                     //for 循环作延时,浅易指令只需1次循便可完成。清屏指令
LCD_RS=0;                  //要用200次循环便能完成。
LCD_RW=1;
LCD_DB=0xff;
LCD_E=1;
while(LCD_DB^7==1);
******************************/
//********延时函数***************
void delay(uint n)
{ uint i;
uchar j;
for(i=n;i>0;i--)
for(j=0;j<2;j++); //在这个延时循环函数中我只做了2次循环,
} //现实证实我的LCD1602 上普
//通的指令只需1次循环便可以可靠完成。
//*******************************
//*********主函数*****************
void main(void)
{
while(1)
{
 uint i;
 LCD_init();
 while(1)
 {   
    for (i=0;i<12;i++)//陕字上半部
   { 
    cs1=1;
 cs2=0;
    LCD_disp_char(0,i+36+4,kk[i]);//加36是显示肇端职位左移,由于一个汉字的宽度为12
     delay(500);
  }
    for (i=12;i<24;i++)//陕字下半部
 { 
    cs1=1;
 cs2=0;
    LCD_disp_char(1,i+24+4,kk[i]);
     delay(500);
  }
  for (i=0;i<12;i++)//西上
 { 
    cs1=1;
 cs2=0; 
    LCD_disp_char(0,i+48+4,xi[i]);
     delay(500);
  }
      for (i=12;i<24;i++)//西下
 { 
    cs1=1;
 cs2=0;
    LCD_disp_char(1,i+36+4,xi[i]);
     delay(500);
  }
       for (i=0;i<12;i++)//电上
 {   
    cs1=0;
 cs2=1;   
    LCD_disp_char(0,i,dian[i]);
     delay(500);
  }
       for (i=12;i<24;i++)//电下
 { 
    cs1=0;
 cs2=1; 
    LCD_disp_char(1,i-12,dian[i]);
     delay(500);
  }
       for (i=0;i<12;i++)//子上
 {
    cs1=0;
 cs2=1; 
    LCD_disp_char(0,i+12,zi[i]);
     delay(500);
  }
  for (i=12;i<24;i++)//子下
 {
    cs1=0;
 cs2=1; 
    LCD_disp_char(1,i,zi[i]);
     delay(500);
  }
   /**************************************/ 
    for (i=0;i<12;i++)//ke上
 { 
     
    LCD_disp_char(0,i+24,ke[i]);
     delay(500);
  }
    for (i=12;i<24;i++)//ke下
 {
    LCD_disp_char(1,i+12,ke[i]);
     delay(500);
  }
  for (i=0;i<12;i++)//ji上
 { 
    cs1=1;
 cs2=0; 
    LCD_disp_char(3,i+48+4,ji[i]);
     delay(500);
  }
      for (i=12;i<24;i++)//ji下
 {
    LCD_disp_char(4,i+36+4,ji[i]);
     delay(500);
  }
       for (i=0;i<12;i++)//xue上
 { 
    cs1=0;
 cs2=1;   
    LCD_disp_char(3,i+24-24,xue[i]);
     delay(500);
  }
       for (i=12;i<24;i++)//xue下
 {
    LCD_disp_char(4,i+12-24,xue[i]);
     delay(500);
  }
for (i=0;i<12;i++)//yuan上
 {
    cs1=0;
 cs2=1; 
    LCD_disp_char(3,i+36-24,yuan[i]);
     delay(500);
  }
  for (i=12;i<24;i++)//下
 {
    LCD_disp_char(4,i+24-24,yuan[i]);
     delay(500);
  }
for (i=0;i<12;i++)//yu上
 {
    cs1=1;
 cs2=0; 
    LCD_disp_char(6,i+48+4,yu[i]);
     delay(500);
  }
  for (i=12;i<24;i++)//yu下
 {
    LCD_disp_char(7,i-12+48+4,yu[i]);
     delay(500);
  }
  for (i=0;i<12;i++)//老上
 {
    cs1=0;
 cs2=1; 
    LCD_disp_char(6,i,lao[i]);
     delay(500);
  }
  for (i=12;i<24;i++)//老下
 {
    LCD_disp_char(7,i-12,lao[i]);
     delay(500);
  }
  for (i=0;i<12;i++)//shi上
 {
    cs1=0;
 cs2=1; 
    LCD_disp_char(6,i+24-12,shi[i]);
     delay(500);
  }
  for (i=12;i<24;i++)//shi下
 {
    LCD_disp_char(7,i-12+24-12,shi[i]);
     delay(500);
  }
    LCD_write_command(0x01);
    delay(10000);
   }
}
}