#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcd_rs=P2^6;
sbit lcd_en=P2^7;
sbit lcd_rw=P2^5;
sbit PSB= P3^2;
sbit LCD12864_RSET=P3^3;
uchar table1[]=
"哈哈哈哈哈哈哈哈";
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void write_cmd(uchar cmd)
{ LCD12864_RSET = 1;
lcd_rs=0;
lcd_rw=0;
_nop_();
_nop_();
P0=cmd;
_nop_();
_nop_();
lcd_en=1;
delayms(2);
lcd_en=0;
delayms(2);
}
void write_data(uchar dat)
{ LCD12864_RSET = 1;
lcd_rs=1;
lcd_rw=0;
_nop_();
_nop_();
P0=dat;
_nop_();
_nop_();
lcd_en=1;
delayms(5);
lcd_en=0;
delayms(1);
}
void init()
{
uchar i;
PSB=1;
LCD12864_RSET = 0;
for (i=0; i<100; i++);
lcd_rs=0;
LCD12864_RSET = 1;
delayms(1);
write_cmd(0x30);
delayms(1);
write_cmd(0x30);
delayms(1);
write_cmd(0x0f);
delayms(1);
write_cmd(0x01);
delayms(1);
write_cmd(0x06);
delayms(1);
}
void display1(void)
{
uchar i;
write_cmd(0x80);
for(i=0;i<16;i++)
{
write_data(table1[i]);
delayms(1);
}
}
void main()
{
init();
while(1)
{
display1();
}
}
|