#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define PSB PORTD=BIT(7)
const uchar table1[]="小葵花妈妈开课了";
void lcd_busy(void)
{
}
//液晶命令数据选择端
#define rs_0 PORTA&=~BIT(0)
#define rs_1 PORTA|=BIT(0)
#define rs_t DDRA|=BIT(0)
//液晶使能端
#define lcden_0 PORTA&=~BIT(2)
#define lcden_1 PORTA|=BIT(2)
#define lcden_t DDRA|=BIT(2)
//并口数据口
#define binko PORTB
#define binko_t DDRB=0xff
//液晶读写选择口
#define rw_0 PORTA&=~BIT(1)
#define rw_1 PORTA|=BIT(1)
#define rw_t DDRA|=BIT(1)
void delayms(uint x) //毫秒延时子函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=1141;j>0;j--);
}
//读 忙 函数
/*void Read_busy()
{
uchar temp;
uchar flag=1;
while(flag==1)
{
DDRB=0X00;//b口设为输入,,准备读数据
//PINB=0XFF;//C口设为输出
delayms(1);
rs_0; //RS=0
delayms(1);
rw_1; //RW=1
delayms(1);
lcden_1; //EN=1
delayms(1);
temp=PINB; //读端口A
//delayms(100);
//DDRB=0XFF; //端口A改为
delayms(1);
//lcden_0; //EN=0
//delayms(10);
if(temp&0x80)
flag =1;
else
flag=0;
}
}*/
void write_com(uchar com) //写命令子函数
{
//Read_busy();
rs_0;
rw_0;
//把rs拉低,写命令
delayms(5);
binko=com;
delayms(5); //写入命令
lcden_1; //拉高使能端
delayms(5); //延时1毫秒
lcden_0;
delayms(1); //拉低使能端
}
/*void write_date(uchar dat) //写数据子函数
{
//Read_busy();
rs_1;
rw_0;
lcden_1;
delayms(5); //把rs拉高,写数据
binko=dat;
delayms(5); //写入数据
//lcden_1; //拉高使能端
delayms(5); //延时1毫秒
lcden_0; //拉低使能端
}*/
uchar lcd_pos(uchar X,uchar Y)
{
uchar 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;
write_com(pos);
}
void write_date(uchar dat) //写数据子函数
{
//Read_busy();
rs_1;
rw_0;
//lcden_1;
delayms(5); //把rs拉高,写数据
binko=dat;
lcden_1;
//delayms(5); //写入数据lcden_1; //拉高使能端
delayms(5); //延时1毫秒
lcden_0;
delayms(1); //拉低使能端
}
void lcd_init()
{
rs_t;
rw_t;
lcden_t;
binko_t;
DDRD=BIT(7);
PORTD=BIT(7);
lcden_0;
delayms(5);
write_com(0x30);
delayms(5);
write_com(0x0C);
delayms(5);
write_com(0x01);
delayms(5);
write_com(0x34);
delayms(5);
write_com(0x06);
delayms(5);
}
void main()
{
//binko_t;
uchar i;
delayms(5);
lcd_init();
lcd_pos(1,0);
//write_com(0x80);
// delayms(100);
delayms(10);
i=0;
while(table1[i]!=' ')
{
write_date(table1[i]);
i++;
}
/* lcd_pos(2,0);
i=0;
while(table2[i]!=' ')
{
write_date(table2[i]);
i++;
}
lcd_pos(3,0);
i=0;
while(table3[i]!=' ')
{
write_date(table3[i]);
i++;
}
lcd_pos(4,0);
i=0;
while(table4[i]!=' ')
{
write_date(table4[i]);
i++;
}*/
}
感觉地址设置没用啊
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
,
一周热门 更多>