2010年4月6日 星期二

液晶(LCD)顯示器實驗



今天跟大家分享如何撰寫LCD控制程式,控制LCD很簡單,必須瞭解2個函式:wr_inst和wr_data,前者是送命令給LCD,而後者是送資料給LCD。相關LCD控制命令可以查http://www.8051projects.net/lcd-interfacing/commands.php。完整程式列表如下:

xdata volatile char PORTACFG _at_ 0x7F93;
xdata volatile char PORTBCFG _at_ 0x7F94;
xdata volatile char PORTCCFG _at_ 0x7F95;
xdata volatile char OUTA _at_ 0x7F96;
xdata volatile char OUTB _at_ 0x7F97;
xdata volatile char OUTC _at_ 0x7F98;
xdata volatile char PINSA _at_ 0x7F99;
xdata volatile char PINSB _at_ 0x7F9A;
xdata volatile char PINSC _at_ 0x7F9B;
xdata volatile char OEA _at_ 0x7F9C;
xdata volatile char OEB _at_ 0x7F9D;
xdata volatile char OEC _at_ 0x7F9E;
xdata volatile char OUTD _at_ 0x7841;
xdata volatile char PINSD _at_ 0x7842;
xdata volatile char OED _at_ 0x7843;

static const char T1[]="LiNe_1";
static const char T2[]={0X4C,0X69,0X4E,0X65,0X5F,0X31};

void DELAY(unsigned int value) //10us
{
while (value!=0) value--;
}

void wr_inst(char c)
{
OUTB=0x40;
OUTA=c;
DELAY(40);
OUTB=0x00;
}

void wr_data(char c)
{
OUTB=0x50;
OUTA=c;
DELAY(40);
OUTB = 0x10;
}

main()
{
unsigned int i;
PORTACFG = 0x00;
OEA = 0xFF;
PORTBCFG = 0x00;
OEB = 0xFF;

wr_inst(0x01);
DELAY(4000);
wr_inst(0x38);
wr_inst(0x0F);
wr_inst(0x06);

wr_inst(0x80);
for(i=0;i<6;i++)
wr_data(T1[i]);

wr_inst(0xC3);
for(i=0;i<6;i++)
wr_data(T2[i]);

while(1) {}
}

沒有留言:

張貼留言