本帖最后由 zage2009 于 2011-10-9 12:36 编辑
写了个操作1602显示字符的程序,烧写后运行正常,不过断电后,再上电,1602就无显示内容,需要按一下复位键后,液晶才显示,请问哪里没有设置好?程序如下#include<avr/io.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=1140;j>0;j--);
}
void write_com(uchar com)
{
PORTA&=~(1<<4);//lcdrs=0;
PORTB=com;
delay(5);
PORTA|=(1<<6);//lcden=1
delay(5);
PORTA&=~(1<<6);//lcden=0;
}
void write_data(uchar data)
{
PORTA|=(1<<4);//lcdrs=1;
PORTB=data;
delay(5);
PORTA|=(1<<6);//lcden=1;
delay(5);
PORTA&=~(1<<6);//lcden=0;
}
void init(void)
{
DDRA=0xff;
DDRB=0xff;
PORTA&=~(1<<5);//lcdwr=0;
PORTA&=~(1<<6);// lcden=0;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80);
}
int main(void)
{
uchar num;
const char * p="I like mcu";
init();
while(1)
{
while(*p)
{
write_data(*p);
delay(30);
p++;
}
}
}
|