#include <reg52.h>
#include<intrins.h>
sbit RS = P3 ^ 0;//?? H ?? L
sbit RW = P3 ^ 1;//? H ? L
sbit E = P3 ^ 2;//??? H ??
#define DATA P2
void delayms(char ms);
char is_busy();
void write_cmd(unsigned char cmd);
void write_data(unsigned char dat);
void pos (unsigned char pos);
void main()
{
write_cmd(0x38);/
delayms(1);
write_cmd(0x0c)
delayms(1);
write_cmd(0x06)
delayms(1);
write_cmd(0x01)
delayms(1);
pos (0);
write_data('1');
write_data('2');
write_data('3');
write_data('4');
write_data('5');
write_data('6');
write_data('7');
write_data('8');
write_data('9');
write_data('0');
pos (0x40);
write_data('1');
write_data('2');
write_data('3');
write_data('4');
write_data('5');
while(1);
}
void pos (unsigned char pos)
{
write_cmd(pos|0x80);
}
void write_data(unsigned char dat)
{
while(is_busy());
RS = 1;
RW = 0;
E = 0;
//_nop_();
DATA = dat;
_nop_();
E = 1
E = 0;
}
void write_cmd(unsigned char cmd)
{
while(is_busy());
RS = 0;
RW = 0;
E = 0;
//_nop_();
DATA = cmd;
_nop_();
E = 1
E = 0;
}
char is_busy()
{
int a=0;
char result;
RS = 0
RW = 1;//?
//_nop_();
E = 1;//??
_nop_();
result = (1<<7 & DATA)
E = 0;//????
return result;
}
void delayms(char ms) //@12.000MHz
{
while(ms--)
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
}
|