PIC16F74的12864點陣液晶驅(qū)動(不帶字庫)
此程序用于12864不帶字庫點陣液晶屏使用
*/
#include
#define DATA PORTB //RB端口為8位數(shù)據(jù)端口
#define Busy RB7 //RB7為忙標志位,數(shù)據(jù)的高位
#define RS RC1 //控制引腳說明
#define RW RC2
#define E RC3
#define CS1 RD2
#define CS2 RD3
//---------------數(shù)據(jù)定義----------------
//12867為縱向8點下高位
//每一頁的排列是縱向8位下高位,從左到右依次為64列
//下面是16*16的點陣字符代碼
unsigned char const table[]={0x90,0x8c,0x84,0x84,0x84,0x84,0xf5,0x86,
0x84,0x84,0x84,0x84,0x84,0xd4,0x8c,0x00,
0x00,0x00,0x80,0x84,0x46,0x49,0x28,0x10,
0x10,0x28,0x47,0xc0,0x00,0x00,0x00,0x00}; //漢字安的代碼
unsigned char const table1[]={0x08,0x08,0x88,0x88,0x88,0x88,0x88,0xff,
0x88,0x88,0x88,0xc8,0x88,0x0c,0x08,0x00,
0x00,0x00,0x00,0xfc,0x44,0x44,0x44,0x44,
0x44,0x44,0x44,0xff,0x04,0x00,0x00,0x00}; //吉字的點陣碼
unsigned char const table2[]={0x10,0x10,0x10,0xd0,0xff,0x90,0x10,0x00,
0x10,0xd0,0xff,0x90,0x10,0x18,0x10,0x00,
0x08,0x04,0x03,0x00,0xff,0x00,0x09,0x04,
0x03,0x00,0xff,0x00,0x03,0x06,0x02,0x00}; //林字的點陣碼
unsigned char const table3[]={0x00,0x00,0x00,0xfe,0x82,0x82,0x82,0x82,
0x82,0x82,0x82,0xff,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x7f,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x7f,0x00,0x00,0x00,0x00}; //日字的點陣碼
unsigned char const table4[]={0x40,0x44,0x54,0x65,0xc6,0x64,0xd6,0x44,
0x40,0xfc,0x00,0x00,0xc3,0x62,0x40,0x00,
0x20,0x11,0x49,0x81,0x7f,0x01,0x05,0x29,
0x18,0x07,0x00,0x00,0xff,0x00,0x00,0x00}; //新字的點陣碼
unsigned char const table5[]={0x08,0x08,0x88,0x88,0x88,0x88,0x88,0xff,0x88,0x88,0x88,0xc8,0x88,0x0c,0x08,0x00,
0x10,0x10,0x10,0xd0,0xff,0x90,0x10,0x00,0x10,0xd0,0xff,0x90,0x10,0x18,0x10,0x00,
0x00,0x00,0x00,0xfe,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xff,0x02,0x00,0x00,0x00,
0x40,0x44,0x54,0x65,0xc6,0x64,0xd6,0x44,0x40,0xfc,0x44,0x42,0xc3,0x62,0x40,0x00,
0x00,0x00,0x00,0xfc,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xff,0x04,0x00,0x00,0x00,
0x08,0x04,0x03,0x00,0xff,0x00,0x09,0x04,0x03,0x00,0xff,0x00,0x03,0x06,0x02,0x00,
0x00,0x00,0x00,0x7f,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7f,0x00,0x00,0x00,0x00,
0x20,0x11,0x49,0x81,0x7f,0x01,0x05,0x29,0x18,0x07,0x00,0x00,0xff,0x00,0x00,0x00}; //吉林日新
//---------------函數(shù)定義----------------
void picint(void);
void Leftwcom(unsigned char com); //左半屏寫指令代碼子程序
void Leftwdata(unsigned char ldata); //左半屏寫顯示數(shù)據(jù)子程序
void Rightwcom(unsigned char rcom); //右半屏寫指令代碼子程序
void Rightwdata(unsigned char rdata); //右半屏寫顯示數(shù)據(jù)子程序
void clear(void); //清屏函數(shù)
//***************************************
//初始化函數(shù)
//***************************************
void picint()
{
INTCON=0;
ADCON1=0x07; //AD口為通用IO口
TRISB=0; //RB端口為輸出端口
PSPMODE=0; //配置D口為通用IO口
TRISC1=0; //輸出引腳,控制引腳
TRISC2=0;
TRISC3=0;
TRISD3=0;
TRISD2=0;
}
//***************************************
//延時函數(shù)
//***************************************
void delay(unsigned int asd)
{
unsigned int i;
for(i=0;i {}
}
//***************************************
//左半屏寫指令代碼子函數(shù)
//***************************************
void Leftwcom(unsigned char com)
{
PORTB=0xff;
TRISB=0xff; //設置為輸入引腳
E=1;
CS1=1;
CS2=1;
RS=0;
RW=1;
while(1)
{
E=1;
if(RB7==0) break;
E=0;
}
RW=0;
TRISB=0;
PORTB=com;
E=1; //送命令
E=0;
}
//***************************************
//左半屏寫顯示數(shù)據(jù)子函數(shù)
//***************************************
void Leftwdata(unsigned char ldata)
{
PORTB=0xff;
TRISB=0xff; //設置為輸入
CS1=1;
CS2=1;
RS=0;
RW=1;
while(1)
{
E=1;
if(RB7==0) break;
E=0;
}
RS=1;
RW=0;
TRISB=0;
PORTB=ldata;
E=1;
E=0;
}
//***************************************
//右半屏寫指令代碼
//***************************************
void Rightwcom(unsigned char rcom)
{
PORTB=0xff;
TRISB=0xff; //設置為輸入引腳
E=1;
CS1=1;
CS2=1;
RS=0;
RW=1;
while(1)
{
E=1;
if(RB7==0) break;
E=0;
}
RW=0;
TRISB=0;
PORTB=rcom;
E=1; //送命令
E=0;
}
//***************************************
//右半屏寫數(shù)據(jù)代碼
//***************************************
void Rightwdata(unsigned char rdata)
{
PORTB=0xff;
TRISB=0xff; //設置為輸入
CS1=1;
CS2=1;
RS=0;
RW=1;
while(1)
{
E=1;
if(RB7==0) break;
E=0;
}
RS=1;
RW=0;
TRISB=0;
PORTB=rdata;
E=1;
E=0;
}
//***************************************
//清屏函數(shù)
//***************************************
void clear()
{
unsigned char i ,y;
for(i=0;i<3;i++)
{
Leftwcom(i|0xb8);
Rightwcom(i|0xb8);
for(y=0;y<64;y++)
{
Leftwdata(0x00);
Rightwdata(0x00);
}
}
}
//***************************************
//主函數(shù)
//***************************************
void main()
{
unsigned char i=0; //查表計數(shù)器
unsigned char z; //循環(huán)計數(shù)器
unsigned char y=0;
unsigned char e=0x40;
picint();
clear();
while(1)
{
Leftwcom(0xc0); //寫命令,設置顯示其實行為第一行
Leftwcom(0x3f); //開顯示設置
Leftwcom(0xb8); //設置第一頁
Leftwcom(0x40); //設置顯示為第一列
for(i=0;i<64;i++)
{
Leftwdata(table5[i]);
}
Leftwcom(0xb9); //設置第一頁
Leftwcom(0x40); //設置顯示為第一列
for(i=64;i<128;i++)
{
Leftwdata(table5[i]);
}
Rightwcom(0xc0); //寫命令,設置顯示其實行為第一行
Rightwcom(0x3f); //開顯示設置
Rightwcom(0xb8); //設置第一頁
Rightwcom(0x40); //設置顯示為第一列
for(i=0;i<64;i++)
{
Rightwdata(table5[i]);
}
Rightwcom(0xb9); //設置第一頁
Rightwcom(0x40); //設置顯示為第一列
for(i=64;i<128;i++)
{
Rightwdata(table5[i]);
}
}
}
評論