|
没有做过硬件仿真,忙判断函数是有的
void main()
{
InitLCD();
ClearScreen(0);
SetStartLine(0);
while(1){
Write16(1,0,0,0,encoding_00);
Write16(1,0,1,0,encoding_01);
Write16(1,0,2,0,encoding_02);
Write16(1,0,3,0,encoding_03);
Write16(2,0,0,0,encoding_04);
Write16(2,0,1,0,encoding_05);
Write16(2,0,2,0,encoding_06);
Write16(2,2,0,0,encoding_11);
Write16(2,2,0,0,encoding_14);
};
}
void Delay(uchar n)
{
uchar s;
for(s=0;s
}
void CheckState()
{
LCD_RS=0;
LCD_RW=1;
P1=P1 & 0x00;
while(P1&0x80)
{
LCD_E=1;
LCD_E=0;
}
}
void SendCommandToLCD(uchar command)
{
CheckState();
LCD_RS=0;
LCD_RW=0;
Delay(4);
P1=command;
LCD_E=1;
LCD_E=0;
}
void SetLine(uchar page)
{
page=0xb8|page;
SendCommandToLCD(page);
}
void SetStartLine(uchar idata startline)
{
startline=0xc0|startline;
SendCommandToLCD(startline);
}
void SetColumn(uchar idata column)
{
column=column &0x3f;
column=0x40|column;
SendCommandToLCD(column);
}
void SetOnOff(uchar idata onoff)
{
onoff=0x3e|onoff;
SendCommandToLCD(onoff);
}
void WriteByte(uchar idata dat)
{
CheckState();
LCD_RS=1;
LCD_RW=0;
Delay(4);
P1=dat;
LCD_E=1;
LCD_E=0;
}
void SelectScreen(uchar idata screen)
{
switch(screen)
{
case 0: cs1=0;
Delay(1);
cs2=0;
Delay(1);
break;
case 1: cs1=0;
Delay(1);
cs2=1;
Delay(1);
break;
case 2: cs1=1;
Delay(1);
cs2=0;
Delay(1);
break;
}
}
void ClearScreen(uchar idata screen)
{
uchar idata i,j;
SelectScreen(screen);
for(i=0;i<8;i++)
{
SetLine(i);
SetColumn(0);
for(j=0;j<64;j++)
{
WriteByte(0x00);
}
}
}
void InitLCD(void)
{
CheckState();
SelectScreen(0);
SetOnOff(0);
SelectScreen(0);
SetOnOff(1);
SelectScreen(0);
ClearScreen(0);
SetStartLine(0);
}
void Write16(uchar ss,uchar page,uchar column,uchar menu,uchar hz[])
{
uchar i;
SelectScreen(ss);
column=16*column;
column=column&0x3f;
SetLine(page);
SetColumn(column);
if(menu==1)
for(i=0;i<16;i++)
{
WriteByte(0xff-hz);
}
else
for(i=0;i<16;i++)
{
WriteByte(hz);
}
SetLine(page+1);
SetColumn(column);
if(menu==1)
for(i=0;i<16;i++)
{
WriteByte(0xff-hz[i+16]);
}
else
for(i=0;i<16;i++)
{
WriteByte(hz[i+16]);
}
}
做了单步执行,也是正常的,数据线上也有高低电平变化,就是LCD一片黑。 |
|