Board logo

标题: S08AW IO口驱动液晶,需要怎么设置? [打印本页]

作者: pjcucumber    时间: 2009-2-25 14:32     标题: S08AW IO口驱动液晶,需要怎么设置?

用S08AW32   PTC 口驱动LCD1602 发现  液晶没有显示。。。会有哪些问题呢?有朋友遇到过同样的问题吗?
作者: pjcucumber    时间: 2009-2-26 15:43

上传一个LCD1602的代码,调通了的。

#define lcd_RS PTGD_PTGD0 //lcd输入选项( 0:指令 1:数据)
#define lcd_RW PTGD_PTGD1 //读写信号 (0 写LCD 1 读LCD)
#define lcd_E PTGD_PTGD2 //lcd使能信号( 1->0时执行指令)
// PTF0 PTF1 PTF4 PTF5 PTC0 PTC1 PTC2 PTC3 接数据口
void wr_dir(unsigned char dir) ;
void wr_data(unsigned char dat);
void lcd_init(void);

void delay_50us(unsigned int t) //延时50us
{
unsigned int j;
for(;t>0;t--)
for(j=9;j>0;j--);
}

//===========================
//函数名:Init_io
//作用:初始化IO
//============================
void Init_io(void)
{
PTBD = 0X01; //端口A数据寄存器初始化为0
PTBDD_PTBDD0=1; //引脚PTA0作为输出引脚
PTGDD_PTGDD0=1;
PTGDD_PTGDD1=1;
PTGDD_PTGDD2=1;
// PTFPE=0X07;
PTFDS=0X07;
PTCDD=0X0F;
PTFDD=0X33;
// PTCPE=0X0F;
// PTFPE=0X33;
PTCDS=0X0F;
PTFDS=0X33;
PTCSE=0X0F;
PTFSE=0X33;
}

//==============================================================
//Init_FEI
//作用:无外接晶振;FLL使能,系统时钟倍频到10.8M(总线频率5.4M)
//===============================================================
void Init_FEI()
{
byte i=0;
ICGC1=0x08; //p=64 // system clock =20.37 MHZ
ICGC2=0x30; //ICGC2=0x31; //N=10,R=2,系统时钟=(243k/7)*64*(10/2)=(18/2)
while((i&0x08)==0x00)
{
i=ICGS1;
}
PTBD_PTBD0=1;
}

void main(void)
{ unsigned int i;
DisableInterrupts;
Init_io();
Init_FEI();
SOPT_COPE=0;
delay_50us(1);
lcd_init();

wr_dir(0x80+0x01);
for(i=0;i<5;i++)
{
wr_data(0X24);
delay_50us(1);
}
wr_dir(0xC0+0x02);
for(i=0;i<5;i++)
{
wr_data(0X21);
delay_50us(1);
}
// for(i=0;i<16;i++)
// {
// wr_dir(0x1c);
// delay_50us(1);
// }
EnableInterrupts; /* enable interrupts */
/* include your code here */
for(;;)
{
delay_50us(1);
PTBD_PTBD0=~PTBD_PTBD0;
delay_50us(1);
PTBD_PTBD0=~PTBD_PTBD0;
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
void lcd_init(void)
{
PTFD=0x00;
PTCD=0X00;
lcd_E=0;
lcd_RS=0;
lcd_RW=0;
delay_50us(300); //15ms
wr_dir(0x38); //可以不要/不影响
delay_50us(100); //
wr_dir(0x38); //
delay_50us(100); //时序很重要
wr_dir(0x38); //16*2显示,5*7点阵,8位数据
delay_50us(5);
wr_dir(0x0f); //设置显示和光标
delay_50us(5);
wr_dir(0x01); //设置输入方式
delay_50us(5);
wr_dir(0x06); //设置输入方式
delay_50us(30);
wr_dir(0x80); //起始RAM的ADDRSS设置
delay_50us(5);
}

void wr_dir(unsigned char dir) //write diruction
{ unsigned char T,M;
T=0X00;
M=0X00;
T|=(dir&0X03);
T|=((dir&0X0C)<<2);
M|=((dir&0XF0)>>4);
delay_50us(3);
lcd_RS=0;
lcd_RW=0; //让lcd工作在写指令/数据的状态
asm(NOP);
asm(NOP);
asm(NOP);
asm(NOP);
lcd_E=1;
asm(NOP);
asm(NOP);
asm(NOP);
asm(NOP);
//delay_50us(1);
PTFD=T;
PTCD=M;
asm(NOP);
asm(NOP);
asm(NOP);
//delay_50us(1);
lcd_E=0;
asm(NOP);
asm(NOP);
asm(NOP);
}

void wr_data(unsigned char dat) //write data
{ unsigned char T,M;
T=0X00;
M=0X00;
T|=(dat&0X03);
T|=((dat&0X0C)<<2);
M|=((dat&0XF0)>>4);
delay_50us(3);
lcd_RS=1;
lcd_RW=0; //让lcd工作在写指令/数据的状态
asm(NOP);
asm(NOP);
asm(NOP);
asm(NOP);
lcd_E=1;
asm(NOP);
asm(NOP);
asm(NOP);
asm(NOP);
//delay_50us(1);
PTFD=T;
PTCD=M;
asm(NOP);
asm(NOP);
asm(NOP);
asm(NOP);
// delay_50us(1);
lcd_E=0;
asm(NOP);
asm(NOP);
asm(NOP);
/*delay_50us(10);
lcd_E=1;
delay_50us(10);
lcd_E=0;*/
}


作者: fjczd    时间: 2009-2-27 08:52

多谢分享






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0