#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigened int
#define out P2
sbit RS=P3^0;
sbit RW=P3^1;
sbit E=P3^2;
void lcd_initial(void);
void check_busy(void);
void write_command(uchar com);
void write_data(uchar dat);
void string(uchar ad,uchar*s);
void delay (uint); //LCD1602.C(14): error C141: syntax error near 'int', expected ')'
void main(void)
{
lcd_initial();
while(1)
{
string(0x85,"Welcome To");
string(0xc2,"Harbin Institute");
Delay(100);
write_command(0x01);
Delay(100);
}
}
void Delay(uint j)
{
uchar i=250;
for(;j>0;j--)
{
while(--i);
i=249;
while(--i);
i=250;
}
}
void check_busy(void)
{
uchar dt;
do
{
dt=0xff;
E=0;
RS=0;
RW=1;
E=1;
dt=out;
}while(dt&0x80);
E=0;
}
void write_command(uchar com)
{
check_busy();
E=0;
RS=0;
RW=0;
out=com;
E=1;
_nop_();
E=0;
delay(1);
}
void write_data(uchar dat)
{
check_busy();
E=0;
RS=1;
RW=0;
out=dat;
E=1;
_nop_();
E=0;
delay(1);
}
void lcd_initial(void)
{
write_command(0x38);
write_command(0x0c);
write_command(0x06);
write_command(0x01);
delay(1);
}
void string(uchar ad,uchar*s)
{
write_command(ad);
while(*s>0)
{
write_data(*s++);
delay(100);
}
} |