#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
#include "xbasic_types.h"
#include "xstatus.h"
#include "xgpio.h"
#define CHANNEL 1
#define SET_RS
XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1)
#define CLEAR_RS
XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1)
#define SET_RW XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x2)
#define CLEAR_RW
XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2)
#define SET_EN XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8)
#define CLEAR_EN XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8)
#define SET_PORT_IN
XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0xffffffff)
#define SET_PORT_OUT
XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x00000000)
unsigned char
dis[]={"123456"};
XGpio Lcd_Data,Lcd_Ctr;
/*延时time us*/
void delay_us(Xuint16 time)
{
Xuint16 i,j;
for(i=0;i<time;i++)
for(j=0;j<26;j++);
}
void delay_ms(Xuint16 time)
{
Xuint16 i,j;
for(i=0;i<time;i++)
for(j=0;j<3785;j++);
}
/*对液晶12864进行操作的一系列子函数 没什么可说的 按照时序图写就是了
/*******************************************************************/
/*
*/
/*检查LCD忙状态
*/
/*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */
/*******************************************************************/
/*
*/
/*写指令数据到LCD
*/
/*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */
/*******************************************************************/
Xint8 lcd_busy()
{
Xuint8 result;
SET_PORT_IN;
CLEAR_EN;
CLEAR_RS;
SET_RW;
delay_us(2);
SET_EN;
delay_us(2);
result=XGpio_DiscreteRead
(&Lcd_Data,CHANNEL);
xil_printf("the value of result is
%x\r\n",result);
CLEAR_EN;
result=result&0x80;
SET_PORT_OUT;
return result;
}
/*******************************************************************/
void lcd_wcmd(Xuint8 cmd)
{
while(lcd_busy());
// delay(50);
CLEAR_EN;
CLEAR_RS;// XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x1);
//asm("nop");
CLEAR_RW;//
XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2);
// asm("nop");
//XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
delay_us(2);
SET_EN;
//XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
XGpio_DiscreteWrite(&Lcd_Data,CHANNEL,cmd);
delay_us(2);
CLEAR_EN;//XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8);
//delay(2);
//XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
xil_printf("cmd done: %x \r\n",cmd);
}
/*******************************************************************/
/*
*/
/*写显示数据到LCD
*/
/*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */
/*
*/
/*******************************************************************/
void lcd_wdat(Xuint8 dat)
{
while(lcd_busy());
// delay(50);
CLEAR_EN;
SET_RS;
CLEAR_RW;
delay_us(2);
SET_EN;
//
XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x1);
//asm("nop");
//XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x2);
// asm("nop");
//XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
// delay(2);
//XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
XGpio_DiscreteWrite(&Lcd_Data,CHANNEL,dat);
// XGpio_DiscreteSet(&Lcd_Ctr,CHANNEL,0x8);
delay_us(2);
//XGpio_DiscreteClear(&Lcd_Ctr,CHANNEL,0x8);
CLEAR_EN;
xil_printf("data done: %x \r\n",dat);
}
/******************************************************************
设置在液晶中显疚?
********************************************************************/
void lcd_pos(Xuint8 X,Xuint8 Y)
{
Xuint8 pos;
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
pos = X+Y ;
lcd_wcmd(pos); //显示地址
}
/*******************************************************************
在液晶中输出一串字符
********************************************************************
*/
void print_string(Xuint8 x,Xuint8
y,Xuint8 * str)
{
Xuint8 lcd_temp;
lcd_pos(x,y);
lcd_temp=*str;
while(lcd_temp != 0x00)
{
lcd_wdat(lcd_temp);
lcd_temp=*(++str);
}
}
/*******************************************************************/
/*
*/
/*
LCD初始化设定
*/
/*
*/
/*******************************************************************/
void lcd_init()
{
delay_ms(40);
lcd_wcmd(0x30); //扩充指令操作
delay_ms(5);
lcd_wcmd(0x30); //基本指令操作
delay_ms(5);
lcd_wcmd(0x0f); //显示开,关?
delay_ms(5);
lcd_wcmd(0x01); //清除LCD的允灸谌?
delay_ms(10);
xil_printf("lcd initialization
done!\n\r");
}
void MicroBlaze_Initialize(){
XGpio_Initialize(&Lcd_Data,XPAR_LCD_DATA_DEVICE_ID);
XGpio_SetDataDirection(&Lcd_Data,CHANNEL,0x0);
XGpio_Initialize(&Lcd_Ctr,XPAR_LCD_CTR_DEVICE_ID);
XGpio_SetDataDirection(&Lcd_Ctr,CHANNEL,0x0);
}
//********************************************上述为对液晶的操作
int main(void){
unsigned char i=0;
xil_printf("now begin\r\n");
MicroBlaze_Initialize();
lcd_init();
lcd_pos(1,1);
while(dis!='0')
{
lcd_wdat(dis);
++i;
}
xil_printf("print done\r\n");
while(1);
return 0;
}
/**************************************************************************
用户372435 2010-8-13 21:13