参考程序:
#include<reg51.h>
#include"DELAY.h"
sbit SCLK = P2^3;
sbit SDIN = P2^4;
sbit DC = P2^5;
sbit SCE = P2^6;
sbit RES = P2^7;
void LCD_write_byte (unsigned char outdata, unsigned char command);
void LCD_init(void);
void clear(void);
void set_xy(unsigned char x,unsigned char y);
void LCD_init(void)
{
RES = 0;
delay_1us();
RES = 1;
LCD_write_byte(0x21, 0);// 芯片是活动的 水平寻址 使用扩展命令设置LCD模式
LCD_write_byte(0xd5, 0);
LCD_write_byte(0x20, 0);// 使用基本命令
LCD_write_byte(0x0c, 0);// 设定显示模式,正常显示
}
void LCD_write_byte (unsigned char outdata, unsigned char command)
{
unsigned char i;
DC = command;
SCE = 0;
for (i=1;i<8;i++)
{
SDIN = (bit)(outdata&0x80);
SCLK = 1;
_nop_();
SCLK = 0;
outdata <<= 1;
}
SCE = 1;
}
void write_english_char(unsigned char x,unsigned char y,char *s)
{
set_xy(x,y);
while(*s)
{
//write_char(x,y,*s);
LCD_write_byte(*s);
s++;
// x+=6;
// if(x>84) y++;
}
}
/*
清除屏幕函数
*/
void clear(void)
{ unsigned int i,j;
for(i=0;i<6;i++)
{ for(j=0;j<84;j++)
{
set_xy(j,i);
LCD_write_byte(0,1);
}
}
}
void set_xy(unsigned char x,unsigned char y)
{
LCD_write_byte(y|0x40,0);//设置y轴。
LCD_write_byte(x|0x80,0);//设置x轴。
}
void main()
{
LCD_init();
clear();
while(1)
{
write_english_char(0,4,"0123456789");
}
} |