/***************************************************************************************************
工程名稱: 12864
功能描述: 實(shí)現(xiàn)12864液晶顯示,液晶第一行顯示" 北方藍(lán)芯科技 ",第二行顯示" www*hrbnbc*com "
硬件連接: 將12864液晶接口對(duì)應(yīng)插接到P2接口,注意1-20腳不要插反。
維護(hù)記錄: 2011-8-22
***************************************************************************************************/
#include "reg52.h" //包含頭文件
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^5; //命令/數(shù)據(jù)選擇
sbit RW=P2^4; //讀寫口
sbit E=P2^3; //鎖存控制
sbit RES = P2^0; //復(fù)位
sbit PSB = P2^2; //串并選擇
//**************************************************************************************************
//延時(shí)函數(shù)
//**************************************************************************************************
delay(uint time) //int型數(shù)據(jù)為16位,所以最大值為65535
{
uint i,j; //定義變量i,j,用于循環(huán)語句
for(i=0;i<time;i++) //for循環(huán),循環(huán)50*time次
for(j=0;j<100;j++); //for循環(huán),循環(huán)50次
}
//**************************************************************************************************
//查忙
//**************************************************************************************************
checkbusy()
{
RS=0; //命令/數(shù)據(jù)選擇,為0時(shí)選擇命令
RW=1; //讀/寫選擇,為1時(shí)選擇讀
E=1; //使能
while((P0&0x80)==0x80); //查忙標(biāo)志位,等待標(biāo)志位為0,即表示寫入完畢
E=0; //關(guān)閉讀寫
}
//**************************************************************************************************
//向LCD寫一命令
//**************************************************************************************************
wcode(uchar cmdcode)
{
checkbusy(); //查忙
RS=0; //命令/數(shù)據(jù)選擇,為0時(shí)選擇命令
RW=0; //讀/寫選擇,為0時(shí)選擇寫
E=1; //使能
P0=cmdcode; //送入命令
delay(10); //等待寫入
E=0; //關(guān)閉讀寫
}
//**************************************************************************************************
//向LCD寫一數(shù)據(jù)
//**************************************************************************************************
wdata(uchar dispdata)
{
checkbusy(); //查忙
RS=1; //命令/數(shù)據(jù)選擇,為1時(shí)選擇數(shù)據(jù)
RW=0; //讀/寫選擇,為0時(shí)選擇寫
E=1; //使能
P0=dispdata; //送入數(shù)據(jù)
delay(10); //等待寫入
E=0; //關(guān)閉讀寫
}
//**************************************************************************************************
//LCD 初始化
//**************************************************************************************************
InitLCD()
{
PSB=1; //設(shè)置為8BIT并口工作模式
RES=0; //復(fù)位
delay(10); //延時(shí)
RES=1; //關(guān)復(fù)位
wcode(0x30); //選擇基本指令集
wcode(0x0c); //開顯示(無游標(biāo)、不反白)
wcode(0x01); //清除顯示,并且設(shè)定地址指針為00H
wcode(0x06); //指定在資料的讀取及寫入時(shí),設(shè)定游標(biāo)的移動(dòng)方向及指定顯示的移位
}
//**************************************************************************************************
//任意位置顯示字符串
//**************************************************************************************************
void dis(uchar x,uchar y,uchar code *s)
{ //x為橫坐標(biāo),y位縱坐標(biāo),*s表示指針,為數(shù)據(jù)的首地址
switch(y) //選擇縱坐標(biāo)
{
case 0: wcode(0x80+x);break; //第1行
case 1: wcode(0x90+x);break; //第2行
case 2: wcode(0x88+x);break; //第3行
case 3: wcode(0x98+x);break; //第4行
default:break;
}
while(*s>0) //寫入數(shù)據(jù),直到數(shù)據(jù)為空
{
wdata(*s); //寫數(shù)據(jù)
delay(10); //等待寫入
s++; //下一字符
}
}
//**************************************************************************************************
//主函數(shù)
//**************************************************************************************************
main()
{
InitLCD(); //初始化液晶
while(1) //進(jìn)入死循環(huán),防止看門狗復(fù)位
{
dis(0,0," 合肥煒煌電子 "); //顯示第1行
dis(0,1," www*hfwhdz*com "); //顯示第2行
delay(5000); //保持顯示一段時(shí)間
wcode(0x01); //清屏
}
}
這個(gè)程序?yàn)槭裁床荒茉谟|屏液晶顯示屏上顯示,需要改什么參數(shù)嗎
|