PIC16F74的12864点阵液晶驱动(不带字库)
此程序用于12864不带字库点阵液晶屏使用
*/
#include
#define DATA PORTB //RB端口为8位数据端口
#define Busy RB7 //RB7为忙标志位,数据的高位
#define RS RC1 //控制引脚说明
#define RW RC2
#define E RC3
#define CS1 RD2
#define CS2 RD3
//---------------数据定义----------------
//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}; //吉林日新
//---------------函数定义----------------
void picint(void);
void Leftwcom(unsigned char com); //左半屏写指令代码子程序
void Leftwdata(unsigned char ldata); //左半屏写显示数据子程序
void Rightwcom(unsigned char rcom); //右半屏写指令代码子程序
void Rightwdata(unsigned char rdata); //右半屏写显示数据子程序
void clear(void); //清屏函数
//***************************************
//初始化函数
//***************************************
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;
}
//***************************************
//延时函数
//***************************************
void delay(unsigned int asd)
{
unsigned int i;
for(i=0;i {}
}
//***************************************
//左半屏写指令代码子函数
//***************************************
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;
}
//***************************************
//左半屏写显示数据子函数
//***************************************
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;
}
//***************************************
//右半屏写数据代码
//***************************************
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;
}
//***************************************
//清屏函数
//***************************************
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);
}
}
}
//***************************************
//主函数
//***************************************
void main()
{
unsigned char i=0; //查表计数器
unsigned char z; //循环计数器
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]);
}
}
}
PIC16F7412864点阵液晶驱 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)