我用128 64的时候一般是用的串行输入数据。这样连线很方便。
***it CS =P2^3;
***it SCK=P2^5;
***it SID=P2^4;
下面是我的程序,在我的板子上工作正常,希望对你有用。
#include
#include
#include
#include
***it CS =P2^3;
***it SCK=P2^5;
***it SID=P2^4;
***it Key=P1^0;
unsigned char code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行汉字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行汉字位置
};
unsigned char code str2[]="欢迎光临sunson!!";
//串口发送一个字节
void SendByte(unsigned char Dbyte)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCK = 0;
Dbyte=Dbyte<<1; //左移一位
SID = CY; //移出的位给SID
SCK = 1;
SCK = 0;
}
}
//串口接收一个字节
//仅在读取数据的时候用到
//而读出的数据是一次只能读出4bit的
unsigned char ReceiveByte(void)
{
unsigned char i,temp1,temp2;
temp1=temp2=0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
void CheckBusy( void )
{
do SendByte(0xfc); //11111,RW(1),RS(0),0
while(0x80&ReceiveByte()); //BF(.7)=1 Busy
}
void WriteCommand( unsigned char Cbyte )
{
CS = 1;
CheckBusy();
SendByte(0xf8); //11111,RW(0),RS(0),0
SendByte(0xf0&Cbyte); //高四位
SendByte(0xf0&Cbyte<<4);//低四位(先执行<<)
CS = 0;
}
void WriteData( unsigned char Dbyte )
{
CS = 1;
CheckBusy();
SendByte(0xfa); //11111,RW(0),RS(1),0
SendByte(0xf0&Dbyte); //高四位
SendByte(0xf0&Dbyte<<4);//低四位(先执行<<)
CS = 0;
}
unsigned char ReadData( void )
{
CheckBusy();
SendByte(0xfe); //11111,RW(1),RS(1),0
return ReceiveByte();
}
void LcmInit( void )
{
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(0x03); //AC归0,不改变DDRAM内容
WriteCommand(0x0C); //显示ON,游标OFF,游标位反白OFF
WriteCommand(0x01); //清屏,AC归0
WriteCommand(0x06); //写入时,游标右移动
}
void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{
WriteCommand(0x30); //8BitMCU,基本指令集合
WriteCommand(AC_TABLE[8*row+col]); //起始位置
while(*puts != ' |