新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STC89C52單片機12864液晶顯示

STC89C52單片機12864液晶顯示

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

實現(xiàn)功能:在實驗板上所佩帶的LCD12864上顯示想顯示的漢字,達到學習操作
12864的目的
實驗板型號:KBL-XYD-C52
實驗名稱: lcd12864漢字顯示實驗
編寫人: 謝應東
編寫日期: 2012-5-3
///////////////////////////////////////////////////////////////////////
#include

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

#define uchar unsigned char
#define uint unsigned int

#define Lcd_IO P0
#define Commd 0
#define Data 1

sbit LCDRS=P3^4; //12864是數(shù)據(jù)選擇端還是指令選擇端
sbit LCDRW=P3^5; //12864的讀寫操作端
sbit LCDEN=P3^6; //12864的使能端
sbit LCDPSB=P3^7; //選擇12864是并行輸入還是串行輸入

sbit wei=P2^7; //定義數(shù)碼管的位選
sbit duan=P2^6; //定義數(shù)碼管的段選

//一幅公雞圖形數(shù)據(jù)
uchar code Lcd_num[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x00,0x70,0xC0,0x02,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x00,0x70,0xC0,0x0F,0x03,0x00,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x00,0x70,0xC0,0xFF,0x83,0x00,0xC0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xE8,0x03,0xFE,0xC0,0x1C,0x03,0x03,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xCC,0x00,0x70,0xC0,0x1C,0x33,0x04,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xC7,0x00,0x76,0xDC,0x1C,0x33,0x08,0x00,0x01,0x00,0x00,0x00,0xE0,0x30,0x00,
0x03,0x87,0x87,0x7F,0xFC,0x1C,0x33,0x18,0x06,0x0C,0xE0,0x00,0x00,0xC0,0x30,0x00,
0x07,0x03,0xF7,0xFF,0xFC,0xFF,0xB3,0x10,0x06,0x1D,0xC0,0x00,0x00,0xC0,0x30,0x00,
0x0C,0x01,0xE7,0xFE,0xDC,0xFF,0xB3,0x20,0x0E,0x3A,0xF0,0x00,0x00,0xC0,0x70,0x00,
0x1F,0xFF,0xE7,0x0E,0xDC,0x1C,0x33,0x20,0x0E,0x31,0xD0,0x00,0x01,0xC0,0x70,0x00,
0x2F,0xFF,0xA3,0x04,0xDC,0x3C,0x33,0x20,0x0E,0x70,0x60,0x00,0x01,0xC0,0x70,0x00,
0x00,0x70,0x03,0xFC,0xDC,0x3E,0x33,0x40,0x0C,0xE0,0x00,0x00,0x01,0xC0,0x60,0x00,
0x00,0x70,0x00,0x18,0xDC,0x3F,0x33,0x40,0x0C,0xC1,0x9F,0xC3,0xD9,0xBC,0x6E,0x1C,
0x00,0x70,0x00,0x70,0xDC,0x3F,0x33,0x40,0x1D,0x81,0x9F,0xE7,0xF9,0xFC,0x6E,0x18,
0x1F,0xFF,0xE0,0xF2,0xDC,0x7F,0x33,0x40,0x1F,0x81,0x98,0xE7,0x39,0x8E,0xE6,0x38,
0x1F,0xFF,0xE0,0x76,0xDC,0x7D,0x33,0x40,0x1F,0x03,0x98,0xEE,0x33,0x8E,0xE6,0x30,
0x08,0x70,0x00,0x7C,0xDC,0x5C,0x33,0x20,0x1F,0x83,0xB8,0xCE,0x33,0x8C,0xE6,0x30,
0x0C,0x71,0x87,0xF8,0xDC,0xDC,0x33,0x20,0x1B,0x83,0x38,0xCE,0x33,0x0C,0xC6,0x60,
0x06,0x71,0x07,0xF1,0xDC,0x9C,0x33,0x20,0x19,0x83,0x38,0xCC,0x33,0x0C,0xC6,0x60,
0x07,0x73,0x07,0x71,0xDD,0x9C,0x03,0x10,0x39,0xC3,0x31,0xCC,0x73,0x1C,0xC6,0xC0,
0x03,0x72,0x00,0x71,0x9C,0x1C,0x03,0x18,0x39,0xC3,0x31,0xCC,0x77,0x1D,0xC6,0xC0,
0x03,0x76,0x00,0x71,0x9C,0x1C,0x03,0x08,0x39,0xC7,0x31,0xDC,0x67,0x1D,0xC7,0x80,
0x02,0x74,0x00,0x73,0x1C,0x1C,0x03,0x04,0x38,0xE7,0x71,0x9C,0xE7,0x39,0x83,0x80,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x06,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xC0,0x00,0x0C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xC0,0x00,0x0C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x80,0x00,0x18,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x00,0x30,0x00,0x05,0x04,0x84,0x00,0x00,0x00,0x01,0x04,0x00,0x14,0x00,
0x00,0x11,0x10,0x08,0x00,0x04,0x82,0x48,0x1F,0xF0,0x00,0x00,0x84,0x00,0x12,0x00,
0x00,0x1F,0xF0,0x04,0x00,0x04,0x0F,0xFE,0x00,0x10,0x00,0x00,0x04,0x00,0x10,0x00,
0x00,0x00,0x40,0x04,0x03,0xFF,0x88,0x02,0x08,0x10,0x00,0x03,0xE7,0x8F,0xFE,0x00,
0x00,0x12,0x40,0x0A,0x00,0x04,0x03,0xF8,0x04,0x10,0x00,0x00,0x04,0x00,0x10,0x00,
0x00,0x3F,0x78,0x0A,0x00,0x04,0x00,0x10,0x02,0x10,0x00,0x02,0x44,0x00,0x10,0x00,
0x00,0x12,0x88,0x0A,0x01,0xF4,0x00,0x20,0x00,0x50,0xFF,0xE1,0x5F,0x87,0xD0,0x00,
0x00,0x12,0x20,0x11,0x00,0x44,0x0F,0xFE,0x01,0x90,0x00,0x01,0x50,0x81,0x10,0x00,
0x00,0x1E,0x20,0x11,0x00,0x42,0x00,0x40,0x06,0x10,0x00,0x00,0x90,0x81,0x08,0x00,
0x00,0x12,0x50,0x20,0x80,0x42,0x80,0x40,0x38,0x10,0x00,0x00,0xD0,0x81,0x0A,0x00,
0x00,0x12,0x50,0x40,0x40,0x79,0x80,0x40,0x00,0x10,0x00,0x03,0x1F,0x81,0xE6,0x00,
0x00,0x1E,0x88,0x80,0x23,0x80,0x81,0xC0,0x00,0xE0,0x00,0x00,0x10,0x8E,0x02,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x11,0xF0,0x04,0x00,0x40,0x00,0x80,0x13,0xE0,0x51,0x00,0x20,0x00,0x00,
0x00,0x00,0x1C,0x90,0x04,0x00,0x20,0x1F,0xFC,0x12,0x20,0x51,0x07,0xFF,0x00,0x00,
0x00,0x00,0x24,0x91,0x3F,0x87,0xFF,0x11,0x04,0x13,0xE0,0x91,0x01,0x04,0x00,0x00,
0x00,0x00,0x49,0x30,0x84,0x80,0x80,0x0F,0xF8,0x7E,0x20,0xBF,0x80,0x88,0x00,0x00,
0x00,0x00,0x3E,0x00,0x04,0x80,0x80,0x02,0x20,0x13,0xE1,0x91,0x03,0xFE,0x00,0x00,
0x00,0x00,0x2A,0xA0,0x04,0x80,0xFE,0x01,0xC0,0x10,0x00,0x91,0x02,0x52,0x00,0x00,
0x00,0x00,0x3E,0xF0,0x7F,0xC0,0x82,0x1E,0x38,0x1B,0xF0,0x91,0x02,0x8A,0x00,0x00,
0x00,0x00,0x2B,0x20,0x04,0x00,0x82,0x00,0x80,0x70,0x80,0xFF,0xC3,0x76,0x00,0x00,
0x00,0x00,0x3E,0x20,0x8A,0x01,0x02,0x1F,0xFC,0x12,0xE0,0x80,0x02,0x52,0x00,0x00,
0x00,0x00,0x2A,0xF1,0x0A,0x01,0x02,0x02,0xA0,0x12,0x80,0x91,0x02,0x72,0x00,0x00,
0x00,0x00,0x2A,0x20,0x11,0x02,0x02,0x04,0x90,0x12,0x80,0xA0,0x82,0x02,0x00,0x00,
0x00,0x00,0x46,0x20,0x60,0xC4,0x1C,0x18,0x8C,0x35,0xF0,0xC0,0x42,0x06,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
///////////////////////////////////////////////////////////////////////
函數(shù)名稱:DelayUs
函數(shù)功能:讓單片機延時10us,即當iNumber=10時,延時為100us
參數(shù)介紹:iNumber:定義要延時10us的次數(shù)
返回值:
注意事項:無
///////////////////////////////////////////////////////////////////////
void DelayUs(uint iNumber)
{
for(;iNumber>0;iNumber--);
}
///////////////////////////////////////////////////////////////////////
函數(shù)名稱:毫秒延時函數(shù)
函數(shù)功能:實現(xiàn)毫秒級的延時
參數(shù)介紹:Delay_MS: 定義需要延時的毫秒的數(shù)值
iNumber: 記錄Delay_MS的數(shù)值,以for語句實現(xiàn)所要求的延時
iValue: 要延時毫秒所要進行的循環(huán)數(shù)值,本數(shù)值為實際測得
返回值:
注意事項:本實驗是在所用晶振為12M的前提下實現(xiàn)的毫秒延時,本函數(shù)是通過循環(huán)的形
式完成,所以如果改變了晶振的頻率,請做相應的改變
///////////////////////////////////////////////////////////////////////
void DelayMs(uint Delay_MS)
{
uint iNumber,iValue;
for(iNumber=0;iNumber{
iValue=107;
while(iValue--);
}
}
///////////////////////////////////////////////////////////////////////
函數(shù)名稱:WriteLCD_CommdData
函數(shù)功能:向12864寫入一條命令或一個字節(jié)的數(shù)據(jù)
參數(shù)介紹:cCommd:選擇是寫入命令了還是數(shù)據(jù),當cCommd=1時,為命令,cCommd=0相反
返回值: cData:要寫入的命令或數(shù)據(jù)
注意事項:無
///////////////////////////////////////////////////////////////////////
void WriteLCD_CommdData(uchar cCommd,uchar cData)
{
if(cCommd)
LCDRS=1; //數(shù)據(jù)
else LCDRS=0; //命令
Lcd_IO=cData;
LCDRW=0;
LCDEN=1;
DelayUs(30);
LCDEN=0;
}
///////////////////////////////////////////////////////////////////////
函數(shù)名稱:Init_LCD()
函數(shù)功能:初始化12864液晶
參數(shù)介紹:無
返回值:
注意事項:初始化的具體過程請看12864的數(shù)據(jù)手冊
///////////////////////////////////////////////////////////////////////
void Init_LCD() //液晶初始化
{
DelayUs(10); //外部復位
LCDPSB=1; //選擇12864為并行模式
WriteLCD_CommdData(Commd,0x30); //基本指令格式
DelayUs(30);
WriteLCD_CommdData(Commd,0x01); //液晶清屏
DelayMs(30);
WriteLCD_CommdData(Commd,0x06); //設置顯示格式,光標位置
WriteLCD_CommdData(Commd,0x0c);
}
//液晶自定義顯示
void Lcd_define(uchar *str)
{
uint m,n;
WriteLCD_CommdData(Commd,0x34); //設置位擴展指令格式
for(m=0;m<32;m++)
{
for(n=0;n<8;n++)
{
WriteLCD_CommdData(Commd,0x80+m); //寫縱坐標,00H--1FH
WriteLCD_CommdData(Commd,0x80+n); //寫橫坐標,00H--07H
WriteLCD_CommdData(Data,str[m*16+n*2]);
WriteLCD_CommdData(Data,str[m*16+n*2+1]);//連續(xù)寫兩個數(shù)據(jù)
}
}

for(m=32;m<64;m++)
{
for(n=0;n<8;n++)
{
WriteLCD_CommdData(Commd,0x80+m-32); //寫縱坐標,00H--1FH
WriteLCD_CommdData(Commd,0x88+n); //寫橫坐標,08H--0FH
WriteLCD_CommdData(Data,str[m*16+n*2]);
WriteLCD_CommdData(Data,str[m*16+n*2+1]); //連續(xù)寫兩個數(shù)據(jù)
}
}
WriteLCD_CommdData(Commd,0x30); //基本指令格式
WriteLCD_CommdData(Commd,0x01); //清屏
DelayMs(30);
WriteLCD_CommdData(Commd,0x34); //擴展指令格式
WriteLCD_CommdData(Commd,0x36); //顯示自定義圖形
}
//主函數(shù)
void main()
{
wei=1;
P0=0XFF;
wei=0;
duan=1;
P0=0x00;
duan=0;

Init_LCD();
Lcd_define(Lcd_num);
while(1);
}



評論


技術專區(qū)

關閉