十年單片機開發(fā)方案公司深圳英銳恩分享PIC單片機實例七:SED1565型液晶串行驅動。
程序(PICC8.05)
/***********************************************
* 標題:SED1565圖形LCD模塊驅動 *
* 作者:Flashbird *
* 日期:2008.03.16 *
* 版本:ZHX1.0 *
* 說明:所用單片機為PIC16F877A *
***********************************************/
#include
#define NOP() asm("nop")
#define SI RB0
#define SCL RB1
#define A0 RB2
#define CS1 RB3
#define uch unsigned char
/**********************************************
* 函數(shù):SerialInputByte(uch dat) *
* 描述:從SI口串行輸入8位數(shù)據(jù) *
**********************************************/
void SerialInputByte(uch dat)
{
uch i;
for(i=0;i<8;i++)
{
if(dat&0x80)SI=1;
else SI=0;
SCL=0; //上升沿有效
NOP();
SCL=1;
dat=dat<<1;
}
}
/**********************************************
* 函數(shù):WriteData(uch dat) *
* 描述:從SI口串行輸入要顯示的數(shù)據(jù) *
**********************************************/
void WriteData(uch dat)
{
CS1=0;
A0=1; //寫數(shù)據(jù)
SerialInputByte(dat);
CS1=1;
}
/**********************************************
* 函數(shù):WriteCommand(uch cmd) *
* 描述:從SI口串行輸入命令 *
**********************************************/
void WriteCommand(uch cmd)
{
CS1=0;
A0=0; //寫命令
SerialInputByte(cmd);
CS1=1;
}
/**********************************************
* 函數(shù):ClearScreen() *
* 描述:清屏 *
**********************************************/
void ClearScreen()
{
uch i,j;
for(i=0;i<8;i++)
{
WriteCommand(0xb0+i);
WriteCommand(0x10);
WriteCommand(0x0);
for(j=0;j<132;j++)
{
WriteData(0x00);
}
}
}
/**********************************************
* 函數(shù):SetLine(uch line) *
* 描述:設定頁地址----X:0--7 *
**********************************************/
void SetLine(uch line)
{
line=line&0x07; //0<=line<=7
line=line|0xb0;
WriteCommand(line);
}
/**********************************************
* 函數(shù):SetColumn(uch column) *
* 描述:設定列地址----Y:0--127 *
**********************************************/
void SetColumn(uch column)
{
uch column_h,column_l;
column=column&0x7f; //0<=column<=127
column_h=column&0x0f0; //列地址高四位
column_h=column>>4;
column_l=column&0x0f; //列地址低四位
column_h=column_h|0x10;
column_l=column_l|0x00;
WriteCommand(column_h);
WriteCommand(column_l);
}
/**********************************************
* 函數(shù):SetOnOff(uch state) *
* 描述:開關顯示 1:開顯示 0:關顯示 *
**********************************************/
void SetOnOff(uch state)
{
state=state|0xae;
WriteCommand(state);
}
/*****************************************************
* 函數(shù):Show16X16(uch line,uch comlon,const uch *pt) *
* 描述:顯示一個16X16的漢字 *
* line:顯示的頁(0--7) *
* column:顯示的列(0--127) *
* *pt:顯示字的首地址 *
*****************************************************/
void Show16X16(uch line,uch column,const uch *pt)
{
uch i,column_temp;
WriteCommand(0xa1); //反向顯示(即從左到右顯示)
column_temp=column;
SetColumn(column); //設置起始列
SetLine(line); //設置行
for(i=0;i<16;i++)
{
WriteData(*pt); //寫數(shù)據(jù)
*pt++;//
column++;
}
SetLine(line+1); //設置漢字下半部分顯示頁
column=column_temp;
SetColumn(column);
for(i=0;i<16;i++)
{
WriteData(*pt);
*pt++;
column++;
}
}
//以下為測試程序
/**********************************************
* 函數(shù):Init() *
* 描述:端口初始化 *
**********************************************/
void init()
{
TRISB=0;
PORTB=0;
}
//字庫
const uch huan[]=
{0x14,0x24,0x44,0x84,0x64,0x1C,0x20,0x18,0x0F,0xE8,0x08,0x08,0x28,0x18,0x08,0x00,
0x20,0x10,0x4C,0x43,0x43,0x2C,0x20,0x10,0x0C,0x03,0x06,0x18,0x30,0x60,0x20,0x00};/*"歡",0*/
const uch ying[]=
{0x40,0x41,0xCE,0x04,0x00,0xFC,0x04,0x02,0x02,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x40,0x20,0x1F,0x20,0x40,0x47,0x42,0x41,0x40,0x5F,0x40,0x42,0x44,0x43,0x40,0x00};/*"迎",1*/
const uch fang[]=
{0x40,0x41,0x4E,0xC4,0x00,0x08,0x08,0x08,0x09,0xFE,0x4A,0x48,0x48,0xC8,0x08,0x00,
0x00,0x00,0x00,0x3F,0x10,0x48,0x20,0x18,0x07,0x00,0x20,0x60,0x20,0x1F,0x00,0x00};/*"訪",2*/
const uch wen[]=
{0x00,0x00,0xF8,0x01,0x06,0xE0,0x22,0x22,0x22,0x22,0xE2,0x02,0x02,0xFE,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x03,0x02,0x02,0x02,0x02,0x03,0x40,0x80,0x7F,0x00,0x00};/*"問",3*/
//滾動顯示“歡迎訪問”
void test()
{
int i;
uch set=0;
uch column=32;
while(1)
{
Show16X16(3,column,huan);
Show16X16(3,column+16,ying);
Show16X16(3,column+32,fang);
Show16X16(3,column+48,wen);
for(i=0;i<4000;i++);
if(set==0)column--;
if(set==1)
{
column++;
SetColumn(column-1);
SetLine(3);
WriteData(0); //擦除前面顯示的數(shù)據(jù)
SetColumn(column-1);
SetLine(4);
WriteData(0); //擦除前面顯示的數(shù)據(jù)
}
if(column==0)set=1; //如果到最左,就往右移
if((column+48)==111)set=0; //如果到最右,就往左移
}
}
void main()
{
(文源網(wǎng)絡,侵刪)