基于ARM7驱动ym12864r显示的问题请各位帮忙看看我的程序有什么问题
[复制链接]
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
//=====================================================================================================
#define setRS IO0SET|=(1<<0) //RS P0.000000000000000000000000000000000000000000
#define clearRS IO0CLR|=(1<<0)
#define setRW IO0SET|=(1<<1) //RW P0.1
#define clearRW IO0CLR|=(1<<1)
#define setE IO0SET|=(1<<2) //E P0.2
#define clearE IO0CLR|=(1<<2)
#define PSB_H IO0SET|=(1<<3) //PSB P0.3
#define PSB_L IO0CLR|=(1<<3)
#define RESETH IO0SET|=(1<<4) //RESET P0.4
#define RESETL IO0CLR|=(1<<4)
#define DATAPIN 0XFF<<18
#define Fclk 60000000
#define uchar unsigned char
#define uint unsigned int
//=======================================================================================================
//液晶相关命令的控制定义
#define YBGW 0x30//将游标放在原始位置
#define KXSYGB 0x0f //开显示,有光标
#define KXSMGB 0x0c //开显示,有光标
#define CLEARP 0x01 //清屏
#define GBYY 0X06//光标右移一格,AC值加1,字符全部不动
//=======================================================================================================
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<50000; i++);
}
void delay_ns(unsigned long int t)
{
unsigned long int i;
unsigned long int j;
j=Fclk*t;
for(i = 0; i < j; i++);
}
void delay_nms(unsigned long int t)
{
unsigned long int i;
unsigned long int j;
j=Fclk/1000*t;
for(i = 0; i < j; i++);
}
void delay_nus(unsigned long int t)
{
unsigned long int i;
unsigned long int j;
j=Fclk/1000000*t;
for(i = 0; i < j; i++);
}
//======================================================================================================
void wait_busy(void)
{
clearRS;
setRW;//读取lcd中DB7的忙碌标志位
IO1SET=(DATAPIN&((0X80)<<18));//将DARA最高位设置为1
IO1DIR = 0X00000000;//设置为输入...默认状态为输入
setE;
delay_nus(5);
while(!(IO1PIN&0x80)) //判断是不是忙碌状态不是就延迟5ns
delay_nus(5);
clearE;
delay_nus(2);
IO1DIR = DATAPIN;//设置为输出
}
//=====================================================================================================
void Write(uchar ch)
{
PSB_H;//并行
clearRW;
setE;//并行使能信号
IO1SET =(DATAPIN&(ch<<18));//读数据此时DATAPIN口的数据位ch
delay_nus(10);
clearE;
delay_nus(2);
setRW;
}
//========================================================================================================
void WriteData(uchar data)
{
wait_busy();
setRS;
Write(data);
}
void WriteCommand(uchar command)
{
wait_busy();
clearRS;
Write(command);
}
//液晶初始化
//========================================================================================================
void lcd12864_init(void)
{
PSB_H;//并行
RESETL;//复位
DelayNS(0);
RESETH;
DelayNS(0);
//delay_nms(1);
WriteCommand(YBGW);//将游标放在原始位置
//delay_nms(1);
DelayNS(0);
//WriteCommand(KXSMGB); //开显示,没有光标
WriteCommand(KXSYGB);//开显示,有光标
//delay_nms(1);
DelayNS(0);
WriteCommand(CLEARP);//清屏
//delay_nms(1);
DelayNS(0);
WriteCommand(GBYY);//光标右移一格,AC值加1,字符全部不动
//delay_nus(100);
DelayNS(0);
}
//=======================================================================================================
void Set_display_Adress(uchar y,uchar x)
{
//设置显示坐标:y行,x列
uchar address;
switch(y)
{
case 0:
address=0x80+x;
break;
case 1:
address=0x90+x;
break;
case 2:
address=0x88+x;
break;
case 3:
address=0x98+x;
break;
}
WriteCommand(address);
}
//=======================================================================================================
void display_CN(uchar y,uchar x,uint CN)
{
uint8 CNH,CNL;
Set_display_Adress(y,x);//设置X,Y坐标
CNL=(char)CN&0xff;//写汉字
CNH=(int)CN>>8;
WriteData(CNH);
//delay_nus(5);
DelayNS(0);
WriteData(CNL);
}
//======================================================================================================
void display_Num(uchar yP,uchar xP,uint num)
{
char tmp0,tmp1,tmp2;
tmp0=num%10;
num/=10;
tmp1=num%10;
tmp2=num/10;
Set_display_Adress(yP,xP++);
WriteData(tmp2+0x30);
WriteData(tmp1+0x30);
Set_display_Adress(yP,xP);
WriteData(tmp0+0x30);
}
//====================================================================================================
//全屏显示图形子程序
void Display_Picture(uchar *tab )
{
unsigned i,j,k,l=0,x=0x80,y;
for(i=0;i<2;i++)
{
for(j=0,y=0x80; j<32;j++,y++,k=16)
{
WriteCommand(0x36); //8位扩充指令集,允许绘图
WriteCommand(y);//地址设置
WriteCommand(x);
WriteCommand(0x30);
while(k--)
WriteData(tab[l++]);
}
x=0x88;
}
}
//=======================================================================================================
int main (void)
{
PINSEL0=0X00000000;//选择GPIO口
PINSEL2=PINSEL2&(0X08);//P[25:16]
IO1DIR=DATAPIN;//设置控制口为输出
lcd12864_init();
display_Num(0,0,12);//写字数
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/