源程序!!
#include
#include
typedef unsigned int uint;
typedef unsigned char uchar;
void Delay(uint m,uint n)
{
uint i,j;
for(i=0;i
for(j=0;j
;
}
void GPIO_Init(void)
{
DDRA=0xFF;
DDRD=0xFF;
DDRB=0xFF;
PORTA&=~BIT(3);//RS
PORTA&=~BIT(4);//RW
PORTA&=~BIT(5);//EN
}
void Read_Busy(void)
{
uchar dat=0;
DDRD=0x00;
PORTA&=~(1<<3);
PORTA|=(1<<4);
PORTA|=(1<<5);//直接上高电平无需上升沿
Delay(10,10);//加一个小小的延时
dat=PIND;
Delay(10,10);
PORTA&=~(1<<5);
DDRD=0xFF;
while(dat&0x80);
}
void Write_Dat(uchar dat)//写数据
{
Read_Busy();
PORTA|=(1<<3);//RS
PORTA&=~(1<<4);//RW
PORTA&=~(1<<5);//EN
Delay(10,10);
PORTD=dat;
Delay(10,10);
PORTA|=(1<<5);
Delay(10,10);
PORTA&=~(1<<5);
}
void Write_Command(uchar com)//写命令
{
Read_Busy();
PORTA&=~(1<<3);
PORTA&=~(1<<4);
PORTA&=~(1<<5);
Delay(10,10);
PORTD=com;
Delay(10,10);
PORTA|=(1<<5);
Delay(10,10);
PORTA&=~(1<<5);
}
void LCD_Init(void)//初始化
{
Write_Command(0x38);
Delay(200,20);
Write_Command(0x06);
Delay(200,20);
Write_Command(0x0C);
Delay(200,20);
Write_Command(0x01);
Delay(200,20);
}
void main(void)
{
GPIO_Init();
LCD_Init();
while(1)
{
Write_Command(0x80+0x40);
Write_Dat(' ');//显示空格
Delay(200,200);
Write_Command(0x80+0x40);
Write_Dat('T');
Delay(200,200);
}
}
时序都一样!