急求啊,这东西怎么改都不行啊,延时是我根据手册一个一个写的,delay函数延时使用示波器测的。。。
#include "DSP28x_Project.h"
#define uint16 unsigned char
#define uint32 unsigned int
#define RS GpioDataRegs.GPADAT.bit.GPIO8
#define RW GpioDataRegs.GPADAT.bit.GPIO9
#define E GpioDataRegs.GPADAT.bit.GPIO10
#define PSB GpioDataRegs.GPADAT.bit.GPIO11
#define BF GpioDataRegs.GPADAT.bit.GPIO7
void init_gpio(void);
void init_12864(void); //12864初始化
void write_order12864(uint32 order); //向12864中写入命令
void write_data12864(uint32 shuju); //向12864中写入数据
void Busy_12864(void); //12864忙信号检测
void write_address(uint32 y,uint32 x); //数据显示位置
void static1(void);
void delayus(uint32 t);
uint16 const a[]={"HELLO"};
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IFR=0x0000;
IER=0x0000;
InitPieVectTable();
init_gpio();
init_12864();
while(1)
{
static1();
}
}
void init_gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all=0x00000000;
GpioCtrlRegs.GPAMUX2.all=0x00000000;
GpioCtrlRegs.GPAPUD.all=0xffffffff;
GpioCtrlRegs.GPADIR.all=0x0000ffff;
EDIS;
GpioDataRegs.GPADAT.all=0x00000000;
}
void init_12864(void)
{
delayus(2000); //26us
PSB=1;
write_order12864(0x30); //8位数据,基本指令操作
delayus(8);
write_order12864(0x30); //8位数据,基本指令操作
delayus(8);
write_order12864(0x0c); //数据整体显示,游标不显示
delayus(8);
write_order12864(0x06); //游标移动方向
delayus(8);
write_order12864(0x01); //清屏
delayus(200);
}
void write_order12864(uint32 order) //写命令
{
Busy_12864();
uint32 temp=0;
//delayus(200);
RS=0;
RW=0;
E=0;
delayus(2);
E=1;
delayus(2);
temp=GpioDataRegs.GPADAT.all;
temp=temp & 0xff00;
temp=temp|(order & 0x00ff);
GpioDataRegs.GPADAT.all=temp;
delayus(4);
E=0;
delayus(50);
}
void write_data12864(uint32 shuju) //写数据
{
Busy_12864();
uint32 temp=0;
//delayus(200);
RS=1;
RW=0;
E=0;
delayus(2);
E=1;
delayus(2);
temp=GpioDataRegs.GPADAT.all;
temp=temp & 0xff00;
temp=temp|(shuju & 0x00ff);
GpioDataRegs.GPADAT.all=temp;
delayus(4);
E=0;
delayus(50);
}
void Busy_12864(void) //忙信号检测
{
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO7=0;
EDIS;
uint32 jiance=1;
RS=0;
RW=1;
delayus(1);
E=1;
delayus(2);
while(jiance==1)
{
jiance=BF;
delayus(8);
}
E=0;
delayus(50);
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO7=1;
EDIS;
}
void write_address(uint32 y,uint32 x) //数据显示位置
{
switch(y)
{
case 1: write_order12864(0x00000080|x);
break;
case 2: write_order12864(0x00000090|x);
break;
case 3: write_order12864(0x00000088|x);
break;
case 4: write_order12864(0x00000098|x);
break;
}
}
void static1(void)
{
write_order12864(0x01); //清屏
delayus(200);
uint32 i=0;
write_address(2,1);
delayus(8);
while(a[i]!='\0')
{
write_data12864(a[i]);
i++;
delayus(100);
}
}
void delayus(uint32 t) //25us
{
uint32 i=150*t;
for(;i>0;i--);
}