将51单片机lcd显示改写成下面28035的,请大家看看有什么问题,屏幕没有任何显示。
#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(uint16 order); //向12864中写入命令
void write_data12864(uint16 shuju); //向12864中写入数据
uint16 Busy_12864(void); //12864忙信号检测
void write_address(uint16 y,uint16 x); //数据显示位置
void static1(void);
uint16 const a[]={"你好!"};
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)
{
DELAY_US(2000); //26us
PSB=1;
write_order12864(0x30); //8位数据,基本指令操作
DELAY_US(8);
write_order12864(0x30); //8位数据,基本指令操作
DELAY_US(2);
write_order12864(0x0c); //数据整体显示,游标不显示
DELAY_US(8);
write_order12864(0x06); //游标移动方向
DELAY_US(8);
write_order12864(0x01); //清屏
DELAY_US(80);
}
void write_order12864(uint16 order) //写命令
{
while(Busy_12864()==1);
RS=0;
RW=0;
E=0;
DELAY_US(2);
E=1;
DELAY_US(8);
GpioDataRegs.GPADAT.all=(order&0x00ff)|GpioDataRegs.GPADAT.all;
DELAY_US(2);
E=0;
DELAY_US(2);
}
void write_data12864(uint16 shuju) //写数据
{
while(Busy_12864()==1);
RS=1;
RW=0;
E=0;
DELAY_US(2);
E=1;
DELAY_US(8);
GpioDataRegs.GPADAT.all=(shuju&0x00ff)|GpioDataRegs.GPADAT.all;
DELAY_US(2);
E=0;
DELAY_US(2);
}
uint16 Busy_12864(void) //忙信号检测
{
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO7=0;
EDIS;
uint16 jiance=0;
RS=0;
RW=1;
E=1;
DELAY_US(2);
jiance+=BF;
DELAY_US(2);
E=0;
DELAY_US(2);
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO7=1;
EDIS;
return jiance;
}
void write_address(uint16 y,uint16 x) //数据显示位置
{
switch(y)
{
case 1: write_order12864(0x0080|x);
break;
case 2: write_order12864(0x0090|x);
break;
case 3: write_order12864(0x0088|x);
break;
case 4: write_order12864(0x0098|x);
break;
}
}
void static1(void)
{
write_order12864(0x01); //清屏
DELAY_US(8);
uint16 i=0;
write_address(2,1);
DELAY_US(8);
while(a!='\0')
{
write_data12864(a);
i++;
DELAY_US(20);
}
}
楼主在51应用时也是这样写的(或相当)?
GpioDataRegs.GPADAT.all=(shuju&0x00ff)|GpioDataRegs.GPADAT.all;
这句话的作用是什么?
楼主,这样是不行滴。昨天刚出现这种情况。不能直接拿GpioDataRegs.GPADAT.all参加运算,你应该先给个变量x将GpioDataRegs.GPADAT.all赋值给x,再运算x,最后把x赋值给GpioDataRegs.GPADAT.all。
急求啊,这东西怎么改都不行啊,延时是我根据手册一个一个写的,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--);
}