新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > AT89C51單片機驅(qū)動液晶顯示漢字C語言

AT89C51單片機驅(qū)動液晶顯示漢字C語言

作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏

此程序的完整工程文件下載:http://www.51hei.com/f/8952lkj_c.rar 上圖是原理圖及其仿真效果.

/*******************************************************************
示漢字C語言
****************************************************************/
#include
#define uchar unsigned char
/*****************************************
電路連接

本文引用地址:http://butianyuan.cn/article/201611/323946.htm
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};
/******定義函數(shù)****************/
void LCD_init(void);//聲明初始化函數(shù)
void LCD_write_command(uchar command);//寫指令函數(shù)
void LCD_write_data(uchar dat);//寫數(shù)據(jù)函數(shù)
void LCD_disp_char(uchar x,uchar y,uchar dat);//在某個屏幕位置上顯示一
//個字符,X(0-16),y(1-2)
//void LCD_check_busy(void);//檢查忙函數(shù)。我沒用到此函數(shù),因為通過率極低。
void delay(uint n);//延時函數(shù)
//********************************
//*******初始化函數(shù)***************
void LCD_init(void)
{
LCD_write_command(0x38);//設置8位格式,2行,5x7
LCD_write_command(0x0c);//整體顯示,關(guān)光標,不閃爍
LCD_write_command(0x06);//設定輸入方式,增量不移位--------------
LCD_write_command(0x01);//清除屏幕顯示----------------
delay(100);//實踐證明,我的LCD1602上,用for 循環(huán)200 次就能可靠完成清屏指令。
}
//********************************
//********寫指令函數(shù)***********設置先向1602寫入的數(shù)據(jù)為地址*
void LCD_write_command(uchar dat)
{
LCD_DB=dat;
LCD_RS=0;//指令
LCD_RW=0;//寫入
LCD_E=1;//允許
LCD_E=0;//產(chǎn)生下降沿
delay(1);//實踐證明,我的LCD1602 上,用for 循環(huán)1 次就能完成普通寫指令。
}
//*******************************
//********再寫數(shù)據(jù)函數(shù)*****向1602中寫入數(shù)據(jù)********
void LCD_write_data(uchar dat)
{
LCD_DB=dat;
LCD_RS=1;//數(shù)據(jù)
LCD_RW=0;//寫入
LCD_E=1;//允許
LCD_E=0;//產(chǎn)生下降沿
delay(1);
}
上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉