聯(lián)系人:劉小姐,李小姐,王小姐
Tel:010-62000662,62051209
Fax:010-82036512
Mobile:13701081790
Email:bjqingda@126.com
Web:www.tsingtek.com
QQ:453189731
微信:13701081790
地址:北京市海淀區(qū)花園東路32號花園公寓A402室1602字符液晶6800時序8位并口樣例程序
1602字符液晶6800時序8位并口樣例程序由清達光電技術(shù)部提供,清達光電專業(yè)設(shè)計生產(chǎn)液晶模塊,OLED模塊,TFT模塊等,產(chǎn)品齊全,供貨快捷。
#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS = P3^3;
sbit RW = P3^1;
sbit E = P3^0;
unsigned char X,Y;
/*-----------建立自定義演示用字符庫-----------*/
code unsigned int CGTAB[9][8]={
/*
橫向取模 ,先上后下
*/
0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, /* "↓"代碼=0 */
0x0f,0x09,0x0f,0x09,0x0f,0x09,0x11,0x00, /* "月"代碼=1 */
0x1f,0x11,0x11,0x1f,0x11,0x11,0x1f,0x00, /* "日"代碼=2 */
0x11,0x0a,0x04,0x1f,0x04,0x1f,0x04,0x00, /* "¥"代碼=3 */
0x0e,0x00,0x1f,0x0a,0x0a,0x0a,0x13,0x00, /* "元"代碼=4 */
0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, /* "℃"代碼=5 */
0x04,0x0a,0x15,0x04,0x04,0x04,0x04,0x00, /* "↑"代碼=6 */
0x17,0x15,0x15,0x15,0x15,0x15,0x17,0x00, /* "10"代碼=7 */
0x04,0x04,0x04,0x04,0x15,0x0a,0x04,0x00, /* "↓"代碼=8 */
};
/*-----------自定義字符顯示用字庫-----------*/
void delay(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
;
}
void busy(void)
{ P1=0xff;
RS=0;
RW=1;
E=1;
while((P1&0x80)==0x80);
E=0;
}
void writecom(unsigned char com)
{ RS=0;
RW=0;
P1=com;
E=1;
_nop_();
E=0;
}
void lcdwc(unsigned char com)
{
busy();
writecom(com);
}
void lcdwd(unsigned char dat)
{
busy();
RS=1;
RW=0;
P1=dat;
E=1;
_nop_();
E=0;
}
/*****************************************************
定義地址ddram顯示范圍
****************************************************/
void lcdpos(void)
{
X&=0x0f; ///16列
Y&=0x03; ///2行
if(Y==0x00)
lcdwc(X|0x80);//**行ddram
else if(Y==0x01)
lcdwc((X+0x40)|0x80); //**行ddram
}
/*****************************************************
初始化函數(shù)
****************************************************/
void lcdreset()
{ delay(150); writecom(0x38);
delay(50); writecom(0x38);
delay(50); writecom(0x38);
lcdwc(0x38); //8位數(shù)據(jù) 顯示2行 5*7字符
lcdwc(0x08); //關(guān)顯示 光標關(guān) 閃爍關(guān)
lcdwc(0x01); //
lcdwc(0x06); //光標右移 畫面不動
lcdwc(0x0c); //開顯示 光標關(guān) 閃爍關(guān)
}
/***************************************
全部寫入
***************************************/
void lcdfill(unsigned char n)
{
for(Y=0;Y<2;Y++)
for(X=0;X<16;X++)
{ lcdpos(); ///定義起始地址
lcdwd(n); }
}
/***************************************
全部寫入隔點
***************************************/
void lcdgraphic(unsigned char m)
{
for(Y=0;Y<2;Y++)
for(X=0;X<16;X++)
{ lcdpos();
lcdwd(m);
lcdwd(~m); }
}
/*****************************************
字符串寫入
*******************************************/
void lcdwda(unsigned char x,unsigned char y,unsigned char *s)
{
Y=y;
for(X=x;X<16;X++)
{
lcdpos();
lcdwd(*s);
s++;
delay(400);
}
}
/**************************/
/* 建立自定義函數(shù) */
/**************************/
CGRAM()
{
uchar dat;
unsigned char i,j;
lcdwc(0x40); /* 設(shè)置CGRAM地址 */
/* 調(diào)寫指令函數(shù) */
for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
dat=CGTAB[i][j]; /* 取字模 */
lcdwd(dat); /* 調(diào)寫數(shù)據(jù)函數(shù) */
}
}
}
/*****************************************
主函數(shù)
*******************************************/
main()
{
unsigned char i,j;
E=0;
lcdreset();
while(1)
{
// lcdreset();
lcdfill(0xff);
delay(2000);
lcdfill(0x55);
delay(2000);
lcdfill(0xaa);
delay(2000);
lcdgraphic(0xff);
delay(2000);
lcdgraphic(0x00);
delay(2000);
lcdgraphic(0x55);
delay(2000);
lcdgraphic(0xaa);
delay(2000);
for(i=0x30;i<=0x3a;i++)
{ lcdfill(i);
delay(3500);//顯示0-9數(shù)字
}
lcdfill(' ');
delay(2000);
lcdwda(0,0,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
lcdwda(0,1,"ZYXWVUTSRQPONMLKJIHGFEDCBA");
delay(2000);
lcdfill(' ');
/*------------CGRAM顯示段--------------*/
CGRAM(); /* 調(diào)自定義字符庫函數(shù) */
lcdwc(0x80); /* 設(shè)置DDRAM地址**行顯示 */
// lcdwc(0xc0); /* 設(shè)置DDRAM地址**行顯示 */
/* 調(diào)寫指令函數(shù) */
for(i=0;i<9;i++)
{
/* 取字符代碼 */
lcdwd(i); /* 調(diào)寫數(shù)據(jù)函數(shù) */
}
delay(4000); lcdfill(' ');
}
}