作者maxwellyann (不彦其烦)
看板ASM
标题LCD测试问题
时间Thu Sep 30 23:47:14 2010
小弟我写了一个LCD测试的程式码,主要是为了测试LCD能否正常运作,结果经过测试,
LCD完全没有动静,硬体的部分也有用电表测量过,LCD有电压,所以不太清楚是软体硬
体哪里出了问题,希望各位大大帮我看一下,话不多说,奉上程式码,小地不才,写得
不好请见谅!
#include <AT89X52.h>
#include <stdio.h>
sbit RS =P1^1;
sbit RW =P1^0;
sbit Enable =P1^2;
void delay(void);
void InitialLCD(void);
void WriteIns(char);
void WriteData(char);
void WriteString(char,char *);
void CheckBusy(void);
char one=0;
char zero=0;
int KeyData=0xff;
int KeyTemp=0xff;
main()
{
char MSG0[]="0123456789";
InitialLCD();
WriteString(10,MSG0);
} /* main */
void InitialLCD(void)
{
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x08); /* off display */
WriteIns(0x01); /* clear buffer */
WriteIns(0x0e); /* on display */
WriteIns(0x06); /* set input mode */
} /* InitialLCD */
void WriteIns(char instruction)
{
RS=0;
RW=0;
Enable=1;
P1=instruction;
Enable=0;
CheckBusy();
} /* WriteIns */
void WriteData(char i)
{
RS=1;
RW=0;
Enable=1;
P1=i;
Enable=0;
CheckBusy();
} /* WriteData */
void WriteString(count,MSG)
char count;
char MSG[];
{
char i;
for(i=0;i<count;i++)
WriteData(MSG[i]);
} /* WriteString */
void CheckBusy(void)
{
char i=0x80;
while(i&0x80)
{
RS=0;
RW=1;
Enable=1;
i=P1;
Enable=0;
delay();
}
} /* CheckBusy */
void delay(void)
{
int i;
for(i=0;i<500;i++)
;
} /* delay */
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.248.7.77
1F:推 WolfLord:LCD动作很慢的,你看清楚那个范例的INIT程式.DELAY很久喔 10/01 00:07
2F:→ maxwellyann:好低 那我在试试看先! 10/01 11:52