||
#include <reg52.h>
#include <intrins.h>
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
#define DATA P1
sbit RS=P3^7;
sbit RW=P3^6;
sbit E =P3^5;
sbit BS=P1^7;
void busy() //???????
{
do
{
DATA=0xFF;
RS=0;
RW=1;
E=0;
_nop_();
E=1;
}while(BS);
}
void command(uchar dat)
{
DATA=dat;
RS=0;
RW=0;
E=0;
busy();
E=1;
}
void write(uchar dat)
{
DATA=dat;
RS=1;
RW=0;
E=0;
busy();
E=1;
}
void clear(uchar dat) //??? 1 ??
{
command(dat);
}
void back(uchar a) //????
{
a;
command(0x02);
}
void mov(uchar id,uchar s) //id ?????????1?? 0 ??
{ //s???????????1? 0 ?
command(0x04|(id<<1)|s);
}
void run(uchar d,uchar c,uchar b) //??????
{ //d ?????? 1 ? 2 ?
command(0x08|(d<<2)|(c<<1)|b); //c ?????? 1 ? 2 ?
}
//b ?????? 1 ? 2 ?
void shift(uchar sc,uchar rl) //sc 1 ?????? 0 ??????
{ //rl 1 ?? 0 ??
command(0x10|(sc<<3)|(rl<<2));
}
void function(uchar dl,uchar n,uchar f) //dl 1 ???? 0 ????
//??dl 1???? 0 ???? ????????
{ //n 1 ???? 0 ????
command(0x20|(dl<<4)|(n<<3)|(f<<2)); //f 1 5*10?? 0 5*7 ??
}
void charaddr(uchar agg) //????????
{
command(0x40|agg);
}
void dataaddr(uchar add) //?????????
{
command(add|0x80);
}
void text(uchar dat) //?????
{
write(dat);
}
void delay(uint t)
{
uint i;
while(!((t--)==0x0))
{
for(i=0;i<0xffff;i++);
}
}
void print(uchar row ,char *p) //???? row?????? *p??????
{
uchar a=0x0;
dataaddr(row);
while((*p)!='\0')
{
text(*p++);
a++;
if(((a+row)>=16)||((*p)=='\n'))
{dataaddr(0x40);a=0;}
}
}
/*main.c**************************************/
#define uchar unsigned char
#define uint unsigned int
void initial()
{
clear(1);
clear(1);
clear(1);
function(1,1,0);
run(1,0,1);
clear(0);
}
void main()
{
uchar s;
s=1;
initial();
do
{
clear(1);
back(2);
print(0x00,"hello everyone !\n welcome!");
delay(1);
_nop_();
delay(0x00);
clear(1);
clear(1);
clear(1);
back(2);
print(0x00," I can ! \n belive me!");
delay(1);
_nop_();
delay(0x00);
}
while(s--);
while(1);
}