lcd16824驱动程序

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include <lm3sxxx.h>
#define fuc_PERIPH SYSCTL_PERIPH_GPIOE
#define fuc_PORT GPIO_PORTE_BASE
#define rs_PIN GPIO_PIN_0
#define rw_PIN GPIO_PIN_1
#define en_PIN GPIO_PIN_2
#define lcd_PERIPH SYSCTL_PERIPH_GPIOD
#define lcd_PORT GPIO_PORTD_BASE
#define lcd_PINS 0xff
#define SysCtlPeriEnable SysCtlPeripheralEnable
#define SysCtlPeriDisable SysCtlPeripheralDisable
#define GPIOPinTypeIn GPIOPinTypeGPIOInput
#define GPIOPinTypeOut GPIOPinTypeGPIOOutput
#define GPIOPinTypeOD GPIOPinTypeGPIOOutputOD
#define FIRST_ADDR 0 //定义字符/汉字显示起始位置
unsigned char CGRAM[]={
0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e, 0x1f,
0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f, 0xc0,
};
unsigned char BMP1[];
unsigned char BMP2[];
unsigned char BMP3[];
unsigned char BMP4[];
unsigned char BMP5[];
unsigned char BMP6[];
unsigned char BMP7[];
unsigned char BMP8[];
unsigned char Num[]={'0','1','2','3','4','5','6','7','8','9','.'};
void delay (int m)
{
i nt n;
f or(n=0;n<=m;n++);
}
void check(void) //判断是否忙碌
{
delay(500);
}
void write_com(unsigned char com) //写显示命令
{
GPIOPinWrite(lcd_PORT , lcd_PINS, com); //P0=com;
GPIOPinWrite(fuc_PORT , rs_PIN, 0X00); // rs=0;
GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0
GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); // lcden=0;
check();
GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;
GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;
}
void write_data(unsigned char date) //写显示数据
{
GPIOPinWrite(lcd_PORT , lcd_PINS, date); //P0=com;
GPIOPinWrite(fuc_PORT , rs_PIN, 0Xff); // rs=0;
GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0
GPIOPinWrite(fuc_PORT , en_PIN, 0xff); // lcden=0;
check();
GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;
GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;
}
void LCD_INIT(void) //初始化LCD
{
S ysCtlPeriEnable(lcd_PERIPH); // 使能LcD所在的GPIO 端口
GPIOPinTypeOut(lcd_PORT,lcd_PINS);
S ysCtlPeriEnable(fuc_PERIPH); // 使能LcD功能端口所在的GPIO 端口 GPIOPinTypeOut(fuc_PORT,rs_PIN|en_PIN|rw_PIN );
G PIOPinWrite(fuc_PORT , en_PIN, 0Xff); //lcden=1;
w rite_com(0x01); //清除屏幕显示,将DDRAM的地址计数器清零
d elay(5);
write_com(0x30); //清除屏幕显示,将DDRAM的地址计数器清零
d elay(5);
w rite_com(0x30); //8BIT控制界面,基本指令集
d elay(5);
w rite_com(0X0C);
d elay(5);
w rite_com(0x01); // /清除屏幕显示,将DDRAM的地址计数器清零
d elay(5);
w rite_com(0x06); //DDRAM的地址计数器(AC)加1
d elay(5);
}
//********************************************************************
// 名称 : DisStr16()
// 功能 : 12864显示16*16字符串函数
// 输入 : hang显示的行数,lie显示的列数,*p显示的内容
// 输出 : 无
//*********************************************************************** void zhifuchuan16(unsigned char hang,unsigned char lie,char *p)
{
unsigned char a=0,i=0;
if(lie>8) lie=1;
switch(hang)
{
case 1: a=0x80;break;
c ase 2: a=0x90;break;
c ase 3: a=0x88;break;
c ase 4: a=0x98;break;
}
a=a+lie-1;
delay(5);
write_com(a);
delay(5);
while(1)
{
if((i/2+lie)>8) break;
if(*p=='\0') break;
write_data(*p);
p++;
i++;
}
GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff);
//IO1PIN=IO1PIN&0xff00ffff|0x00010000;
}
//********************************************************************
//* 名称 : DisStr8()
//* 功能 : 12864显示8*16字符串函数
//* 输入 : hang显示的行数,lie显示的列数,*p显示的内容
//* 输出 : 无
//***********************************************************************/
void zhifuchuan8(unsigned char hang,unsigned char lie,char *p)
{
unsigned char a,i=0;
if(lie<1) lie=1;
if(lie>16) lie=16;
lie=lie-1;
if(hang==1) a=0x80;
if(hang==2) a=0x90;
if(hang==3) a=0x88;
if(hang==4) a=0x98;
a=a+lie/2;
write_com(a);
if(lie%2==1) write_data(0x20);
while(1)
{
if((i+lie)>15) break;
if(*p=='\0') break;
write_data(*p);
p++;
i++;
}
//IO1PIN=IO1PIN&0xff00ffff|0x00010000;
}
/********************************************************************
* 名称 : DisChar()
* 功能 : 显示单个数字字符函数
* 输入 : hang显示的行数,lie显示的列数,sign显示的内容
* 输出 : 无
***********************************************************************/
void DisChar(unsigned char hang,unsigned char lie,unsigned int sign)
{
unsigned char a;
if(lie<1) lie=1;
if(lie>16) lie=16;
lie=lie-1;
if(hang==1) a=0x80;
if(hang==2) a=0x90;
if(hang==3) a=0x88;
if(hang==4) a=0x98;
a=a+lie/2;
write_com(a);
if(lie%2==1) write_data(0x20);
write_data(sign+0x30);
//IO1PIN=IO1PIN&0xff00ffff|0x00010000;
}
/* 名称 : DisNum()
* 功能 : 显示单个数字字符函数
* 输入 : hang显示的行数,lie显示的列数,sign显示的内容
* 输出 : 无
***********************************************************************/
void DisNum(unsigned char hang,unsigned char lie,unsigned int num1,unsigned int num2)
{
unsigned char a;
if(lie<1) lie=1;
if(lie>16) lie=16;
lie=lie-1;
if(hang==1) a=0x80;
if(hang==2) a=0x90;
if(hang==3) a=0x88;
if(hang==4) a=0x98;
a=a+lie/2;
write_com(a);
if(lie%2==1) write_data(0x20);
write_data(num1+0x30);
write_data(num2+0x30);
//IO1PIN=IO1PIN&0xff00ffff|0x00010000;
}
/********************************************************************
* 名称 : DisImg(uint xs,uint ys,uint xe,uint ye,uchar *img)
* 功能 : 显示图片 xs为图片显示的起始横坐标,xs=1-16
xe为图片显示的结束横坐标,xe=2-17
宽单位为8个像素点,图片大小必须为的宽必须为8的倍数,
且小于128,如宽为16时,xe-xs=2 即宽度为2*8=16个像素点
ys为图片显示的起始纵坐标,ys=1-64
ye为图片显示的结束纵坐标,ye=2-65
高单位为1个像素,图片高小于64,
如高为19,ye-ys=19 即高度为 19个像素点
* 输入 : 无
* 输出 : 无
***********************************************************************/
void DisImg(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye,unsigned char *img)
{
unsigned int j=0;
unsigned char x,y,xxs,xxe,i=0,k=0;
xs-=1;ys-=1;xe-=1;ye-=1;
xxs=xs/2;xxe=xe/2;
for(y=ys;y<=ye;y++)
{
for(x=xxs;x<xxe;x++)
{
if(y>=32) i=8,k=32;
write_com(0x36); //8位数据总线,扩展指令集,绘图显示开 write_com(y+0x80-k); //行地址
write_com(x+0x80+i); //列地址
write_com(0x30);
if(xs%2==1) write_data(0x00);
write_data(img[j++]);
write_data(img[j++]);
}
}
}
/********************************************************************
* 名称 : CLR()
* 功能 : 清屏
* 输入 : 无
* 输出 : 无
***********************************************************************/ void CLR()
{
write_com(0x01);
delay(1);
}
/********************************************************************
/********************************************************************
* 名称 : CLRGDRAM()
* 功能 : 清整个GDRAM空间
* 输入 : 无
* 输出 : 无
***********************************************************************/
void CLRGDRAM()
{
unsigned char x,y,i;
CLR();
zhifuchuan16(1,1," ");
for(i=0;i<9;i+=8) //0时上半屏,8时下半屏
for(y=0;y<32;y++) //列地址(0~32) (0~32)
for(x=0;x<8;x++) //行地址(0~7) (8~15)
{
write_com(0x36); //8位数据总线,扩展指令集,绘图显示开 write_com(y+0x80); //行地址
write_com(x+0x80+i); //列地址
write_com(0x30);
write_data(0x00);
write_data(0x00);
}
CLR();
}
//***********************************闪烁
******************************************************//
// void shanshuo ()
//{
// write_com(0x02);
// write_com(0x0e);
void LCD_set_xy( unsigned char hang, unsigned char lie )
{
unsigned char a=0,i=0;
if(lie>8) lie=1;
switch(hang)
{
case 1: a=0x80;break;
c ase 2: a=0x90;break;
c ase 3: a=0x88;break;
c ase 4: a=0x98;break;
}
a=a+lie-1;
delay(5);
write_com(a);
}
void LCD_falsh(unsigned char hang,unsigned char lie,unsigned char falsh) {
L CD_set_xy( hang, lie );
i f(falsh)
w rite_com(0x0e);
}
//************************************************************************* ***
//*火影图片*/
//*-- 宽度x高度=128x64 --*/
unsigned char BMP2[]=
{
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,
0XFC,0X00,0X00,0X03,0XFF,0XFF,0XF1,0X33,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE, 0X3F,
0XFC,0X00,0X00,0X40,0X3E,0XFC,0X00,0X10,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE, 0X7F,
0XFC,0X00,0X00,0X40,0X38,0X00,0X00,0X01,0XC3,0XFF,0XFF,0XFF,0XF8,0X00,0XFF, 0X7F,
0XFC,0X00,0X00,0XC0,0X50,0X27,0XFE,0X00,0X07,0XFF,0XFF,0XC0,0X00,0X00,0X7F, 0X3F,
0XFC,0X00,0X00,0XC0,0X11,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F,
0XFC,0X00,0X00,0X00,0X00,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0XFF,0XF0,0X00,0X02, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0XF9,0X7F,0XE0,0X03,0X00,0X00,0X00,0X00,0X00,0X0C, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X7D,0XFF,0X80,0X01,0X80,0X00,0X00,0X00,0X0F,0XE8, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X7F,0XFF,0X00,0X00,0XA8,0X00,0X00,0X02,0X03,0XE1, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X3E,0X30,0X00,0X03,0X4F,0X81,0XFF,0XFC,0X01,0XE1, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X03,0X0F,0X00,0XFF,0XC4,0X45,0XE1, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X1F,0X00,0X00,0X03,0X1F,0X40,0X47,0XEC,0X0F,0XE9, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X30,0X00,0X00,0X03,0X0F,0X40,0X6F,0XFE,0X0F,0XF9, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X20,0X00,0X00,0X03,0X0F,0XC3,0XFF,0XFF,0X0F,0XF3, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X3F,0XE0,0XFF,0XFF,0XDF,0XE3, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFB,0XFF,0XFF,0XFF,0XE6, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X8F,0XFF,0XFF,0XFF,0XFF,0XCC, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC7,0XFF,0XFF,0XFF,0XFF,0XCC, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X77,0XFF,0XFF,0XFF,0XFF,0XDC, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X37,0XFF,0XFF,0XFF,0XFF,0X18, 0X3F,
0XFC,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X33,0XFF,0XFF,0XFF,0XFF,0XB8, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X13,0XFF,0XFF,0XFF,0XFF,0XFE, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XFF,0XFF, 0X3F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1D,0XFF,0XFF,0XFF,0XFF,0X3F, 0XBF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFD,0X3F,0XFF,0X7F,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X3C,0XFF,0XFC,0X3F,0XFF,0X7F, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFC,0XFF,0XFE,0X7F,0XFE,0X7F, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XF8,0X7F,0XFF,0XFF,0XFC,0X4F, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XF8,0X3F,0XFF,0XFF,0XF8,0X4F, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X1F,0XFF,0XFF,0XF9,0X07, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF0,0X0F,0XFF,0XFF,0XE7,0X07, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X07,0XFF,0XFF,0XC3,0X07, 0XFF,
0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X63,0XFF,0XFF,0X81,0X0F, 0XFF,
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0XFF,0XFF,0XFF,0XFF,0XFF,
};。

相关文档
最新文档