#include
#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 { 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(); } //***********************************闪烁