现在有一个12864的屏,采用的是双595扩展的串口,单片机采用的是IAP15W4K61S4,选用的是内部24MHZ的晶振。调了两天没调出来,不知道哪里出了问题!还请大家帮忙看一下。12864采用的是不带字库的,RST脚没接
#include<stc15.h>
#define uchar unsigned char
#define uint unsigned int
sbit EXP_CLK = P3^6;
sbit EXP_DATA = P3^7;
sbit KEY_D_ST1 = P3^4;
sbit KEY_C_ST1 = P3^5;
uchar Port;
void SendCommand(uchar command);
void WriteData(uchar dat);
void LcdDelay(uchar time);
void SetOnOff(uchar onoff);
void ClearScreen(uchar screen);
void SetLine(uchar line);
void SetColum(uchar colum);
void SetStartLine(uchar startline);
void SelectScreen(uchar screen);
void Show1616(uchar lin,uchar colum,uchar *address);
void InitLcd();
void Show_english(uchar lin,uchar colum,uchar *address);
void SendChrToPeriphery(uchar chr);
void SetKeyDisCT(bit bbit);
void delayms(uint ms);
void delayus(uint us);
void InitPort(void)
{
P0M1 = 0x00;
P0M0 = 0x00;
P0 = 0xe0;
P1M1 = 0xc0;
P1M0 = 0x00;
P1 = 0xeb;
P2M1 = 0x00;
P2M0 = 0x00;
P2 = 0xfa;
P3M1 = 0x00;
P3M0 = 0x00;
P3 = 0;
P4M1 = 0x00;
P4M0 = 0x00;
P4 = 0xe7;
P5M1 = 0x00;
P5M0 = 0x00;
P5 = 0xf9;
P6M1 = 0x00;
P6M0 = 0x00;
P6 = 0x7e;
P7M1 = 0x00;
P7M0 = 0x00;
P7 = 0xff;
WDT_CONTR = 0x35;
}
const uchar code hzk[] =
{
};
void main()
{
uchar i,line,colum,j ;
uchar *address ;
InitPort();
Port=0xff;
SendChrToPeriphery(Port); //ê1Äü
SetKeyDisCT(1);
WDT_CONTR = 0x35;
InitLcd();
while(1)
{
WDT_CONTR = 0x35;
line=1;
colum=0;
address=hzk;
SetOnOff(1);
for(i=0;i<14;i++)
{
if(i<8)
{
SelectScreen(0);
Show_english(line,colum,address);
address+=16;
colum+=8;
}
else if(i>=8)
{
if(i<13)
{
SelectScreen(1);
Show_english(line,colum,address);
address+=16;
colum+=8;
}
else
{
Show1616(line,colum,address);
address+=32;
colum+=16;
}
}
}
}
}
void SendChrToPeriphery(unsigned char chr)
{
unsigned char cthr;
for ( cthr = 0 ;cthr < 8;cthr ++ )
{
EXP_DATA = chr & 0x80;
chr <<= 1;
EXP_CLK = 1;
EXP_CLK = 0;
};
}
void SetKeyDisCT(bit bbit) //μØÖ·ê1Äü½Å
{
KEY_C_ST1 = bbit;
LcdDelay(5);
KEY_C_ST1=0;
}
void SetKeyDisDT(bit bbit) //êy¾Yê1Äü½Å
{
KEY_D_ST1 = bbit;
LcdDelay(5);
KEY_D_ST1=0;
}
void LcdDelay(uchar time)
{
while(time--);
}
void delayus(uint us)
{
uint m;
for(m=0;m<us;m++)
{
LcdDelay(24);
}
}
void delayms(uint ms)
{
uint m;
for(m=0;m<ms;m++)
{
delayus(1000);
}
}
void SendCommand(uchar command) //·¢ËíÃüáî
{
Port&=0xe3;
SendChrToPeriphery(Port); //
SetKeyDisCT(1);
delayus(500);
SendChrToPeriphery(command);
SetKeyDisDT(1);
Port&=0xeb;
SendChrToPeriphery(0xeb); //ê1Äü
SetKeyDisCT(1);
Port&=0xeb;
SendChrToPeriphery(0xe3); //ê1Äü
SetKeyDisCT(1);
delayms(10);
}
void WriteData(uchar dat) //·¢Ëíêy¾Y
{
Port&=0xe7;
SendChrToPeriphery(0xe7);
SetKeyDisCT(1);
delayus(500);
SendChrToPeriphery(dat);
SetKeyDisDT(1);
Port&=0xef;
SendChrToPeriphery(0xef);
SetKeyDisCT(1);
LcdDelay(130);
Port&=0xe7;
SendChrToPeriphery(0xe7);
SetKeyDisDT(1);
delayms(10);
}
void SetOnOff(uchar onoff)
{
if(onoff==1)
{
SendCommand(0x3f);
}
else
{
SendCommand(0x3e);
}
}
void SetLine(uchar line)
{
line=line&0x07;
line=line|0xb8;
SendCommand(line);
}
void SetColum(uchar colum)
{
colum=colum&0x3f;
colum=colum|0x40;
SendCommand(colum);
}
void SetStartLine(uchar startline)
{
startline=startline&0x3f;
startline=startline|0xc0;
SendCommand(startline);
}
void SelectScreen(uchar screen) //Ñ¡ÔñÆá
{
switch(screen)
{
case 0:
Port&=0xfd;
SendChrToPeriphery(Port);
SetKeyDisCT(1);
break;
case 1:
Port&=0xfe;
SendChrToPeriphery(Port);
SetKeyDisCT(1);
break;
case 2:
Port&=0xfc;
SendChrToPeriphery(Port);
SetKeyDisCT(1);
break;
}
}
void Show1616(uchar lin,uchar colum,uchar *address) //ÏÔê¾oo×Ö
{
uchar i;
SetLine(lin);
SetColum(colum);
for(i=0;i<16;i++)
{
WriteData(*address);
address++;
}
SetLine(lin+1);
SetColum(colum);
for(i=0;i<16;i++)
{
WriteData(*address);
address++;
}
}
void Show_english(uchar lin,uchar colum,uchar *address) //ÏÔê¾ó¢ÎÄ
{
uchar i;
SetLine(lin);
SetColum(colum);
for(i=0;i<8;i++)
{
WriteData(*address);
address++;
}
SetLine(lin+1);
SetColum(colum);
for(i=0;i<8;i++)
{
WriteData(*address);
address++;
}
}
void ClearScreen(uchar screen) //ÇåÆá
{
uchar i,j;
SelectScreen(screen);
for(i=0;i<8;i++)
{
SetLine(i);
SetColum(0);
for(j=0;j<64;j++)
{
WriteData(0);
}
}
}
void InitLcd()
{
SetOnOff(0);
ClearScreen(2);
SetLine(0);
SetColum(0);
SetStartLine(0);
SetOnOff(1);
}
此帖出自
小平头技术问答
恩,是的现在就是缩小了很多,可还是不行的
不知道什么原因,RST通过203电阻接的高电平,不测忙,只通过延时函数
一周热门 更多>