void S12864_SysCtl_Init(void)
{
SysCtlPeripheralEnable(S12864_PERIPH);
GPIODirModeSet(S12864_PORT,S12864_SCLK_PIN|S12864_CS_PIN|S12864_SID_PIN,GPIO_DIR_MODE_OUT);
GPIOPinTypeGPIOOutput(S12864_PORT,S12864_SCLK_PIN|S12864_CS_PIN|S12864_SID_PIN);
}
void S12864_WriteByte(unsigned char ucCOM,unsigned char ucData)
{
unsigned char t1,i;
GPIOPinWrite(S12864_PORT,S12864_CS_PIN,0x00);
SysCtlDelay(50*(TheSysClock/3000));
GPIOPinWrite(S12864_PORT,S12864_CS_PIN,0xFF);
for (i=0;i<=7;i++)
{
t1=ucCOM&0x80;
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0x00);
if (t1)GPIOPinWrite(S12864_PORT,S12864_SID_PIN,S12864_SID_PIN);
else GPIOPinWrite(S12864_PORT,S12864_SID_PIN,~S12864_SID_PIN);
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0xFF);
SysCtlDelay(50*(TheSysClock/3000));
ucCOM=ucCOM<<1;
}
t1=ucData&0xF0;
for(i=0;i<=7;i++)
{
t1=t1&0x80;
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0x00);
if (t1)GPIOPinWrite(S12864_PORT,S12864_SID_PIN,S12864_SID_PIN);
else GPIOPinWrite(S12864_PORT,S12864_SID_PIN,~S12864_SID_PIN);
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0xFF);
SysCtlDelay(50*(TheSysClock/3000));
t1=t1<<1;
}
t1=ucData<<4;
for(i=0;i<=7;i++)
{
t1=t1&0x80;
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0x00);
if (t1)GPIOPinWrite(S12864_PORT,S12864_SID_PIN,S12864_SID_PIN);
else GPIOPinWrite(S12864_PORT,S12864_SID_PIN,~S12864_SID_PIN);
GPIOPinWrite(S12864_PORT,S12864_SCLK_PIN,0xFF);
SysCtlDelay(50*(TheSysClock/3000));
t1=t1<<1;
}
GPIOPinWrite(S12864_PORT,S12864_CS_PIN,0x00);
SysCtlDelay(50*(TheSysClock/3000));
}
void S12864_Init(void)
{
S12864_WriteByte(Write_ORDER,BASIC_SET);
SysCtlDelay(50*(TheSysClock/3000));
S12864_WriteByte(Write_ORDER,LCD_CLEAR);
SysCtlDelay(50*(TheSysClock/3000));
S12864_WriteByte(Write_ORDER,0X06);
SysCtlDelay(50*(TheSysClock/3000));
S12864_WriteByte(Write_ORDER,DISPLAY_ON);
}
void S12864_SetPos(unsigned char ucX,unsigned char ucY)
{
unsigned char pos;
if (ucX==1)
{
ucX=0x80;
}
else if (ucX==2)
{
ucX=0x90;
}
else if (ucX==3)
{
ucX=0x88;
}
else if (ucX==4)
{
ucX=0x98;
}
pos=ucX+ucY;
S12864_WriteByte(Write_ORDER,pos);
}
void S12864_WriteChar(unsigned char ucCHAR,unsigned char ucX,unsigned char ucY)
{
S12864_SetPos(ucX,ucY);
S12864_WriteByte(Write_DATA,ucCHAR);
}
#include "systemInit.h"
#include "S12864.H"
// 主函数(程序入口)
int main(void)
{
//jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 时钟初始化:晶振,6MHz
S12864_SysCtl_Init();
S12864_Init();
S12864_WriteChar('c',1,1);
//S12864_WriteCount(98.987,0,1);
for (;;)
{
}
}
为什么一直没有显示?
用的应该是别人的程序,先看看板子是否正常工作起来了,板子上晶振是 6 Mhz 的吗?
检查一下输出的波形时序和屏的时序,驱动屏其实挺简单的,只要驱动正确,一般没什么问题的。
移植程序的时候要注意时钟呢,时钟往往决定着延时,在12864的驱动程序中延时是很重要的。另外还要注意端口配置呢!调试程序的时候单步运行下试试呢,看看程序会不会卡住呢!另外要注意你的硬件连接呢,特别需要注意的是液晶屏供电电压是否满足要求(3.3V or 5V),还有对比度调节呢(因为我就走过这歪路呢)! 纯属个人经验
人有的时候真是奇怪,选择了会后悔,放弃了会遗憾,完美只能是一种理想,不是一种存在。
检查波形和时序;定时,时钟,以及看看你的接口是不是对,逐步检查你的程序,看看运行的时候有没有异常