用TI的piccolo系列DSP驱动LCM1602显示,可总是没任何反应,什么字符都没有显示,以下是代码,有没有兄弟能指教一下的,非常感谢
#include "includes.h"
#define DELAY_MS(x) (DELAY_US((unsigned long)(x)*1000L))
#define D7 GpioDataRegs.GPADAT.bit.GPIO18
#define READ 1
#define WRITE 0
/*
#define D0_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO8=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO8=1;}
#define D1_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO25=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO25=1;}
#define D2_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO27=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO27=1;}
#define D3_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO31=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO31=1;}
#define D4_SET(x) if(x) {GpioDataRegs.GPBSET.bit.GPIO44=1;} else {GpioDataRegs.GPBCLEAR.bit.GPIO44=1;}
#define D5_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO16=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO16=1;}
#define D6_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO17=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO17=1;}
#define D7_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO18=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO18=1;}
*/
#define D0_SET(x) GpioDataRegs.GPADAT.bit.GPIO8=(x);
#define D1_SET(x) GpioDataRegs.GPADAT.bit.GPIO25=(x);
#define D2_SET(x) GpioDataRegs.GPADAT.bit.GPIO27=(x);
#define D3_SET(x) GpioDataRegs.GPADAT.bit.GPIO31=(x);
#define D4_SET(x) GpioDataRegs.GPBDAT.bit.GPIO44=(x);
#define D5_SET(x) GpioDataRegs.GPADAT.bit.GPIO16=(x);
#define D6_SET(x) GpioDataRegs.GPADAT.bit.GPIO17=(x);
#define D7_SET(x) GpioDataRegs.GPADAT.bit.GPIO18=(x);
#define E_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO3=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO3=1;}
#define RW_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO6=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO6=1;}
#define COMMAND 0
#define DATA 1
#define RS_SET(x) if(x) {GpioDataRegs.GPASET.bit.GPIO7=1;} else {GpioDataRegs.GPACLEAR.bit.GPIO7=1;}
void Gpio_R_W(Uint16 operation)
{
EALLOW;
if(operation)
{
//read
GpioCtrlRegs.GPADIR.bit.GPIO8 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO27 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO31 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO44 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO16 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO17 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO18 = 0;
}
if(!operation)
{
//write
GpioCtrlRegs.GPADIR.bit.GPIO8 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO25 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO27 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;
GpioCtrlRegs.GPBDIR.bit.GPIO44 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO16 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO17 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO18 = 1;
}
EDIS;
}
void Dat2DB8(Uint8 data)
{
Gpio_R_W(WRITE);
D0_SET(data&0x0001);
D1_SET((data>>1)&0x0001);
D2_SET((data>>2)&0x0001);
D3_SET((data>>3)&0x0001);
D4_SET((data>>4)&0x0001);
D5_SET((data>>5)&0x0001);
D6_SET((data>>6)&0x0001);
D7_SET((data>>7)&0x0001);
}
// mod==1 : write data
// mod==0 : write command
void LCD1602Write( Uint8 data, Uint8 mod )
{
Dat2DB8(data);
RS_SET(mod);
RW_SET(WRITE);
DELAY_US(5L);
E_SET(1);
DELAY_US(10L);
E_SET(0);
}
void LCD1602ReadBusy()
{
Dat2DB8(0xff);
RS_SET(COMMAND);
RW_SET(READ);
E_SET(1);
Gpio_R_W(READ);
while(D7);
E_SET(0);
}
void LCDMoveTo(int16 y, int16 x)
{
}
void LCD1602Init()
{
E_SET(0);
RS_SET(DATA);
RW_SET(READ);
Dat2DB8(0x00ff);
DELAY_MS(15);
LCD1602Write(0x0038,COMMAND);
DELAY_MS(5);
LCD1602Write(0x0038,COMMAND);
DELAY_MS(5);
LCD1602Write(0x0038,COMMAND); // 设置12*2显示,5*8点阵,8位数据接口
LCD1602ReadBusy();
LCD1602Write(0x0038,COMMAND);
LCD1602ReadBusy();
LCD1602Write(0x0008,COMMAND); // 关显示,不显示光标位置,光标不闪烁
LCD1602ReadBusy();
LCD1602Write(0x0001,COMMAND); // 清除显示
LCD1602ReadBusy();
LCD1602Write(0x0006,COMMAND); // 写一个字符指针自动加1
LCD1602ReadBusy();
LCD1602Write(0x000c,COMMAND); // 开显示不显示光标
}
// y : row, x : column, c : character to display
void LCD1602DisplayChar( Uint8 y, Uint8 x, char c )
{
if( y ) // second line
{
x += 0x40;
}
x += 0x80;
LCD1602ReadBusy();
LCD1602Write( x, COMMAND); // cursor move to
LCD1602ReadBusy();
LCD1602Write( c, DATA); // write data
}
// y : row, x : column, c : string to display
void LCD1602DisplayStr( Uint8 y, Uint8 x, char str[] )
{
char *c = str;
while( *c )
{
LCD1602DisplayChar( y, x, *c );
c++;
}
}
void LCD1602BlinkCursor(Uint8 y, Uint8 x, Uint8 blink)
{
if( y ) // second line
{
x += 0x40;
}
x += 0x80;
LCD1602Write( x, COMMAND); // cursor move to
if ( blink )
{
LCD1602Write( 0x0F, COMMAND);
}
else
{
LCD1602Write( 0x0C, COMMAND);
}
}
初始化后调用LCD1602DisplayStr()全无任何反应...
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>