讲51单片机lcd显示改写成下面2812的,请大家看看有什么问题,屏幕没有任何显示。时序是否有问题
#include "DSP281x_Device.h"
#include "System.h"
/****************端口宏定义*****************/
#define RS_OUT GpioDataRegs.GPBDAT.bit.GPIOB0
#define RS_DIR GpioMuxRegs.GPBDIR.bit.GPIOB0
#define RW_OUT GpioDataRegs.GPBDAT.bit.GPIOB1
#define RW_DIR GpioMuxRegs.GPBDIR.bit.GPIOB1
#define E_OUT GpioDataRegs.GPBDAT.bit.GPIOB2
#define E_DIR GpioMuxRegs.GPBDIR.bit.GPIOB2
#define PSB_OUT GpioDataRegs.GPBDAT.bit.GPIOB3
#define PSB_DIR GpioMuxRegs.GPBDIR.bit.GPIOB3
#define LcdData_OUT GpioDataRegs.GPADAT.all
#define LcdData_DIR GpioMuxRegs.GPADIR.all
/****************常量宏定义*****************/
#define uchar unsigned char
#define uint unsigned int
/****************函数声明*******************/
//延时子程序
void delay(long t)
{
unsigned int i,j;
for(i=0;i<10*t;i++)
for(j=0;j<10;j++);
}
//测试LCD忙
int Check_Busy()
{
int busy;
EALLOW;//选择寄存器操作,执行EALLOW
RS_DIR = 1;//输出
RW_DIR = 1;//输出
E_DIR = 1;//输出
LcdData_DIR &=0x00;//输入
EDIS;
RS_OUT = 0;
RW_OUT = 1;
E_OUT = 1;
delay(10);
busy = (int)(LcdData_OUT&0x80);
E_OUT = 0;
return busy;
}
//等待LCD到空闲
void wait()
{
while(Check_Busy());
}
//写数据
void Lcd_Writedata(unsigned char dispdata)
{
//wait();
EALLOW;//选择寄存器操作,执行EALLOW
RS_DIR = 1;//输出
RW_DIR = 1;//输出
E_DIR = 1;//输出
LcdData_DIR |= 0xff;
EDIS;
RS_OUT=1;
RW_OUT=0;
E_OUT=0;
delay(20);// _nop_();
LcdData_OUT=dispdata;
E_OUT=1;
delay(20);// _nop_();
E_OUT=0;
}
//写指令代码
void Lcd_WriteCmd(unsigned char cmdcode)
{
//wait();
EALLOW;//选择寄存器操作,执行EALLOW
RS_DIR = 1;//输出
RW_DIR = 1;//输出
E_DIR = 1;//输出
LcdData_DIR |= 0xff;
EDIS;
RS_OUT = 0;
RW_OUT = 0;
E_OUT = 0;
//delay(20);// _nop_();
LcdData_OUT=cmdcode;
delay(200);// _nop_();
E_OUT=1;
delay(200); //_nop_();
E_OUT=0;
}
//初始化LCD
void Lcd_Reset()
{
// delay(1000);
EALLOW;//选择寄存器操作,执行EALLOW
PSB_DIR=1;
EDIS;
PSB_OUT=1;
Lcd_WriteCmd(0x30); //选择基本指令集
delay(50);
Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)
delay(50);
Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H
delay(50);
Lcd_WriteCmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位
}
void WriteStr(unsigned char *s)
{
while(*s>0)
{ Lcd_Writedata(*s);
s++;
}
}
void hzDisp()
{
Lcd_WriteCmd(0x80);
WriteStr("黄河远上白云间,");
Lcd_WriteCmd(0x90);
WriteStr("一片孤城万仞山。");
Lcd_WriteCmd(0x88);
WriteStr("羌笛何须怨杨柳?");
Lcd_WriteCmd(0x98);
WriteStr("春风不度玉门关。");
}
/*绘图显示的步骤
1 关闭绘图显示功能
2 先将垂直的坐标(Y)写入绘图RAM地址
3 再将水平的位元组坐标(X)写入绘图RAM地址
4 将D15-D8写入RAM中
5 将D7-D0写入到RAM中
6 打开绘图显示功能*/
//整屏显示竖条 当ii=0时显示上面128?2,当ii=8时显示下面128?2
void LcdFill_Vertical()
{
unsigned char x,y,ii;
for(ii=0;ii<9;ii+=8)
for(y=0;y<0x20;y++)
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36);//扩充指令 绘图显示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+ii); //列地址
Lcd_Writedata(0x55); //写数据 D15-D8
Lcd_Writedata(0x55); //写数据 D7-D0
Lcd_WriteCmd(0x30);
}
}
//当ii=0时显示上面128?2,当ii=8时显示下面128?2
//整屏显示横条线
void LcdFill_Level()
{
unsigned char x,y,ii;
unsigned char k;
for(ii=0;ii<9;ii+=8)
for(y=0;y<0x20;y++)
{
if((y%2)==1)
k=0xff;
else
k=0;
for(x=0;x<8;x++)
{ Lcd_WriteCmd(0x36); //扩充指令 绘图显示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+ii); //列地址
Lcd_Writedata(k);
Lcd_Writedata(k);
Lcd_WriteCmd(0x30);
}
}
}
void main(void)
{
InitSysCtrl();
EALLOW;//选择寄存器操作,执行EALLOW
GpioMuxRegs.GPBMUX.all|=0x000f;
EDIS;
GpioDataRegs.GPBDAT.all|=0x0f;
//OEB = 0x0f;
Lcd_Reset(); //初始化LCD屏
while(1)
{
/* Lcd_Reset();
LcdFill_Vertical(); //显示竖条
delay(6000);delay(4000);delay(4000);
Lcd_Reset();
LcdFill_Level(); //显示横条
delay(6000);delay(4000);delay(4000);
*/
Lcd_Reset();
//hzDisp(); //显示汉字
// delay(6000); delay(4000);delay(4000);
}
} |