/********************************************************************
*文件名:lcdDriver.c
*文件描述:
*创建人:Sha zq
*创建日期: 2008年05月12日
*版本号:1.0.01
*E-mail:
********************************************************************/
#include "Board.h"
#include "lcddriver.h"
#include "sed1335.h"
//////////////////////////////////////////////////////////////////////
AT91PS_PIO pPioZL = AT91C_BASE_PIOA;
void long_delay(int t)
{
int i=0;
int n;
for(i=0;i<t;i++)
{
for(n=0;n<5;n++);
}
}
/*============================================================
* 函 数 名: sendData
* 参 数:data
* 功能描述:
* 通过Atmel256,的GPIO口模拟并行口,与LCM模块通信
* 返 回 值:Null
* 作 者:Sha zq 日期:2008/01/11
=============================================================*/
void sendData(unsigned char data)
{
pPioZL->PIO_OER = 0xff000000; // Configure in Output
//pPio->PIO_OER =(AT91C_PIO_PA24 | AT91C_PIO_PA25 | AT91C_PIO_PA26 | AT91C_PIO_PA27 | AT91C_PIO_PA28 | AT91C_PIO_PA29 | AT91C_PIO_PA30 | AT91C_PIO_PA31);
pPioZL->PIO_ODSR=(data<<24);
}
void sed1335_writecmd(char commandcode)
{
//a0=1;
pPioZL->PIO_SODR=AT91C_PIO_PA17; // A0 =1
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=commandcode;
//数据输出到数据口
long_delay(10);
sendData(commandcode);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
}
void sed1335_writedata(char data)
{
//a0=1;
pPioZL->PIO_CODR=AT91C_PIO_PA17; // A0 =1
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=commandcode;
//数据输出到数据口
long_delay(10);
sendData(data);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
}
void sed1335_write(char commandcode, unsigned char *parameter,int n)
{
int i=0;
//a0=1;
pPioZL->PIO_SODR=AT91C_PIO_PA17; // A0 =1
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=commandcode;
//数据输出到数据口
long_delay(10);
sendData(commandcode);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
for(i=0;i<n;i++)
{
//a0=0;
pPioZL->PIO_CODR=AT91C_PIO_PA17; // A0 =0
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=parameter[i];
long_delay(10);
sendData(parameter[i]);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
}
}
//在图形层写一个汉字//
void sed1335_write1(char commandcode,int low,int high)
{
//a0=1;
pPioZL->PIO_SODR=AT91C_PIO_PA17; // A0 =1
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=commandcode;
long_delay(10);
sendData(commandcode);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
//a0=0;
pPioZL->PIO_CODR=AT91C_PIO_PA17; // A0 =0
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=low;
long_delay(10);
sendData(low);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
//a0=0;
pPioZL->PIO_CODR=AT91C_PIO_PA17; // A0 =0
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=high;
long_delay(10);
sendData(high);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
long_delay(10);
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
}
/*
//写任何大小的一块, i为高度,j*8为宽度
wr_any(int low,int high, unsigned char word[],int i,int j)
{
int k=0;
for( k=0;k<j;k++)
{
sed1335_write1(csrw,low,high);
sed1335_write(csrdir_down,null,1);
sed1335_write(mwrite,word+i*k,i);
low=low-1;
if(low==0xff+1)
{
low=0;high=high+1;
}
}
}
*/
void ClearLcd()
{
unsigned int i=0;
//unsigned int temp;
sed1335_write(csrdir_right,null,1); //光标移动方向设置
sed1335_write(csrw,cur_set_ini1,2); //光标指针设置
//a0=1;
pPioZL->PIO_SODR=AT91C_PIO_PA17; // A0 =1
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
//databus=mwrite;
sendData(mwrite); //数据写入
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
//write=1;
pPioZL->PIO_SODR=AT91C_PIO_PA18;
for(i=0;i<9600;i++)
{
//a0=0;
pPioZL->PIO_CODR=AT91C_PIO_PA17; // A0 =0
//read=1;
pPioZL->PIO_SODR=AT91C_PIO_PA19; //RD =1
long_delay(10);
//databus=0x00;
sendData(0x00);
long_delay(10);
//write=0;
pPioZL->PIO_CODR=AT91C_PIO_PA18;
//write=1;
long_delay(10);
pPioZL->PIO_SODR=AT91C_PIO_PA18;
}
sed1335_write(csrw,cur_set_ini1,2); ////光标指针设置
}
/*
//清除图形层
clrgrp_scr()
{
int j=0;
sed1335_write(csrw,cur_set_ini3,2);
for(j=0;j<9600;j++)
sed1335_write(mwrite,word3,1);
}
*/
/*
wr_word(int low,int high, unsigned char word[],int i,int j)
{
int k=0;
for( k=0;k<j;k++)
{
sed1335_write1(csrw,low,high);
sed1335_write(csrdir_down,null,1);
sed1335_write(mwrite,word+i*k,i);
//low=low+1;
low=low-1;
}
}
*/
wr_wordN(int address , unsigned char word[],unsigned char i,unsigned char j,unsigned char mode)
{
int low, high;
int k=0;
unsigned char loop;
low = (address &0xff);
high= ((address>>8) &0xff);
for(loop=0;loop<32;loop++)
word[loop]=((word[loop]^mode));
for( k=0;k<j;k++)
{
sed1335_write1(csrw,low,high);
sed1335_write(csrdir_down,null,1);
sed1335_write(mwrite,word+i*k,i);
//low=low+1;
low=low-1;
}
}
// sed1335 initial
void AdvWritechinese(unsigned int x,unsigned int y,unsigned char *word,unsigned char mode)
{
unsigned int position;
unsigned char m,n;
m=16;
n=2;
//position=x*20+(19-y);
position=(x<<4)+(x<<2)+(19-y);
wr_wordN(position,word,m,n,mode);
}
void AdvWriteChar(unsigned int x,unsigned int y,unsigned char *word,unsigned char mode)
{
unsigned int position;
unsigned char m,n;
m=8;
n=2;
//position=x*20+(19-y);
position=((x*8)<<4)+((x*8)<<2)+(19-y); //add x * 8 data 08-05-12
wr_wordN(position,word,m,n,mode);
}
void MenuSysSet(unsigned char x,unsigned char y)
{
unsigned char m,n;
m=x*16; //48;
n=y;//*2; //0;
AdvWritechinese(m,n,xi,NOR);
m=m+16;
AdvWritechinese(m,n,tong,NOR);
m=m+16;
AdvWritechinese(m,n,she,NOR);
m=m+16;
AdvWritechinese(m,n,zhi,NOR);
}
void MenuCheckRecord(unsigned char x,unsigned char y)
{
unsigned char m,n;
m=x*16; //48;
n=y;//*2; //0;
AdvWritechinese(m,n,cha,NOR);
m=m+16;
AdvWritechinese(m,n,xun,NOR);
m=m+16;
AdvWritechinese(m,n,ji,NOR);
m=m+16;
AdvWritechinese(m,n,lu,NOR);
}
void MenuReadTag(unsigned char x,unsigned char y)
{
unsigned char m,n;
m=x*16; //48;
n=y;//*2; //0;
AdvWritechinese(m,n,kai,NOR);
m=m+16;
AdvWritechinese(m,n,shi,NOR);
m=m+16;
AdvWritechinese(m,n,du,NOR);
m=m+16;
AdvWritechinese(m,n,ka,NOR);
}
void test(void)
{
int i;
for (i=0;i<30;i++)
{
AdvWriteChar(i,10,A,NOR);
}
AdvWriteChar(8,8,A,NOR);
AdvWriteChar(9,8,C,NOR);
AdvWriteChar(10,8,D,NOR);
AdvWriteChar(11,8,E,NOR);
AdvWriteChar(12,8,F,NOR);
}
void test2(void)
{
int i;
unsigned char* vec[]={A,B,C,E,D,F};
for(i=0;i<6;i++)
{
AdvWriteChar(i+6,8,*(vec+i),NOR);
}
}
void LcdInit(void)
{
unsigned int loop;
/////////////////////////////////////////////
long_delay(10);
//rst=0;
pPioZL->PIO_CODR=AT91C_PIO_PA0; // rst =0
long_delay(30);
//rst=1;
pPioZL->PIO_SODR=AT91C_PIO_PA0; // rst =1
long_delay(10);
//cs=0;
pPioZL->PIO_CODR=AT91C_PIO_PA1; // cs = 0
////////////////////////////////////////////////
sed1335_write(system_set,system_set_ini,8);
sed1335_write(scroll,scroll_ini1,10);
sed1335_writecmd(0x5a); // 设置点单元卷动位置
sed1335_writedata(0x00);
sed1335_writecmd(0x5b); // 设置合成显示方式
sed1335_writedata(0x0c);
sed1335_writecmd(0x59); //开显示
sed1335_writedata(0x55);
sed1335_writecmd(0x4c); //设置光标移动方向
sed1335_writecmd(0x46); //设置光标地址
sed1335_writedata(0x00);
sed1335_writedata(0x00);
sed1335_writecmd(0x42); // 数据写入显示缓冲区
for (loop=0;loop<9600;loop++)
sed1335_writedata(0xaa);
}
/***************************************************************
* main program *
****************************************************************/
void show_Menu(void)
{
ClearLcd();
test2();
}
程序还是比较粗遭,但完全可以用的,我都是实验过了, LCD 大小 240*160
欢迎交流,