新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AT89C51單片機(jī)驅(qū)動(dòng)128x64液晶顯示C語言

AT89C51單片機(jī)驅(qū)動(dòng)128x64液晶顯示C語言

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
/*******************************************************************

AT89C51單片機(jī)驅(qū)動(dòng)128x64液晶顯示C語言
****************************************************************/
#include
#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;
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[]={ //"學(xué)",
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[]={//"余",
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0xE0,0x70,0x3F,0x1F,0x32,0x60,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x60,0x20,0x10,0x98,0x8C,0x87,0xCB,
0xCD,0x4C,0xFC,0xFC,0x46,0x66,0x66,0x61,
0x63,0x67,0x4E,0x0C,0x0C,0x0C,0x08,0x08,
0x00,0x00,0x00,0x00,0x30,0x3C,0x1E,0x00,
0x20,0x60,0xFE,0xFF,0x00,0x00,0x02,0x06,
0x0E,0x1C,0x18,0x00,0x00,0x00,0x00,0x00};
/******定義函數(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);//在某個(gè)屏幕位置上顯示一
//個(gè)字符,X(0-16),y(1-2)
//void LCD_check_busy(void);//檢查忙函數(shù)。我沒用到此函數(shù),因?yàn)橥ㄟ^率極低。
void delay(uint n);//延時(shí)函數(shù)
//********************************
//*******初始化函數(shù)***************
void LCD_init(void)
{
LCD_write_command(0x38);//設(shè)置8位格式,2行,5x7
LCD_write_command(0x0c);//整體顯示,關(guān)光標(biāo),不閃爍
LCD_write_command(0x06);//設(shè)定輸入方式,增量不移位--------------
LCD_write_command(0x01);//清除屏幕顯示----------------
delay(100);//實(shí)踐證明,我的LCD1602上,用for 循環(huán)200 次就能可靠完成清屏指令。
}
//********************************
//********寫指令函數(shù)***********設(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);//實(shí)踐證明,我的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);
}
void writeDataLcd(unsigned char dat)// 寫入數(shù)據(jù)
{
LCD_RS=1; //RS置1 (運(yùn)算后P5=xxx1 xxxx,即RS=1其他位狀態(tài)不變)
LCD_RW=0; //RW清0 (運(yùn)算后P5=xx0x xxxx, 即RW=0其他位狀態(tài)不變)
LCD_E=0; //使能E清0 (運(yùn)算后P5=xxxx 0xxx, 即E=0其他位狀態(tài)不變)
P1 = dat; //送數(shù)據(jù)到P2OUT準(zhǔn)備輸出進(jìn)入1602,等E下降沿來即可進(jìn)入1602.
LCD_E=1; //使能E置1,P5OUT= xxxx xxxx+0000 1000=xxxx1xxx,E=1.
delay(10);
LCD_E=0; //使能E清0,這樣E從1變0,產(chǎn)生一個(gè)下降,寫入命令到1602。
}

本文引用地址:http://m.butianyuan.cn/article/201611/323965.htm

//********************************
//*******顯示一個(gè)字符函數(shù)*********
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);
}
//********************************
/*******檢查忙函數(shù)*************
voidLCD_check_busy()
//實(shí)踐證明,在我的LCD1602 上,檢查忙指令通
過率極低,以至于不能正常使用LCD。因此我沒有再用檢查忙函數(shù)。而使
do//用了延時(shí)的方法,延時(shí)還是非常好用的。我試了一下,用//
{LCD_E=0; //for 循環(huán)作延時(shí),普通指令只要1次循就可完成。清屏指令
LCD_RS=0; //要用200次循環(huán)便能完成。
LCD_RW=1;
LCD_DB=0xff;
LCD_E=1;
while(LCD_DB^7==1);

******************************/
//********延時(shí)函數(shù)***************
void delay(uint n)
{ uint i;
uchar j;
for(i=n;i>0;i--)
for(j=0;j<2;j++); //在這個(gè)延時(shí)循環(huán)函數(shù)中我只做了2次循環(huán),
} //實(shí)踐證明我的LCD1602 上普
//通的指令只需1次循環(huán)就能可靠完成。
//*******************************
//*********主函數(shù)*****************
void main(void)
{
while(1)
{
uint i=0;
LCD_init();
while(1)
{

for (i=0;i<12;i++)//shan
{
LCD_disp_char(0,i,kk[i]);
delay(1);
}
for (i=12;i<24;i++)
{
LCD_disp_char(1,i-12,kk[i]);
delay(1);
}
for (i=0;i<12;i++)//xi
{
LCD_disp_char(0,i+12,xi[i]);
delay(1);
}
for (i=12;i<24;i++)
{
LCD_disp_char(1,i,xi[i]);
delay(1);
}
for (i=0;i<12;i++)//dian
{
LCD_disp_char(0,i+24,dian[i]);
delay(1);
}
for (i=12;i<24;i++)
{
LCD_disp_char(1,i+12,dian[i]);
delay(1);
}
for (i=0;i<12;i++)//zi
{
LCD_disp_char(0,i+36,zi[i]);
delay(1);
}
for (i=12;i<24;i++)
{
LCD_disp_char(1,i+24,zi[i]);
delay(1);
}


上一頁 1 2 下一頁

關(guān)鍵詞: AT89C51單片機(jī)液晶顯

評(píng)論


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

關(guān)閉