?? 12864.c
字號:
#include "12864.h"
//#include <reg52.h>
#define ShortDelay()\
{\
unsigned char t =20;\
while ( --t != 0 );\
}
void SPI_Write(char dat) //reentrant
{
unsigned char t = 8;
do
{
DATA = (bit)(dat & 0x80);
dat <<= 1;
CLK = 1;
ShortDelay();
CLK = 0;
ShortDelay();
} while ( --t != 0 );
}
char SPI_Read()// reentrant
{
char dat;
unsigned char t = 8;
DATA = 1; //讀取數據之前DIO 引腳要置1 以切換到輸入狀態
do
{
CLK = 1;
ShortDelay();
dat <<= 1;
if ( DATA) dat++;
CLK = 0;
ShortDelay();
} while ( --t != 0 );
return dat;
}
void SPIWR(uchar Wdata,uchar RS)
{
SPI_Write(0xf8+(RS<<1));
SPI_Write(Wdata&0xf0);
SPI_Write((Wdata<<4)&0xf0);
}
void WriteInstruction(uchar cmd)//寫指令
{
Delay(5000);
// E=0;
// RW=0;
// RS=0;
// E=1;
SPIWR(cmd,0);
Delay(50);
// E=0;
}
void WriteData(uchar dat)//寫數據
{
Delay(50);
// E=0;
// RW=0;
// RS=1;
// E=1;
SPIWR(dat,1);
Delay(50);
// E=0;
}
void LCDInit(void)//初始化LCD
{
CS=0;
Delay(600);
CS=1;
WriteInstruction(0x30);
WriteInstruction(0x30);
Delay(5000);
WriteInstruction(0x30);
Delay(5000);
WriteInstruction(0x0c);
Delay(2000);
WriteInstruction(0x01);
Delay(2000);
WriteInstruction(0x06);
Delay(2000);
}
/*void CLS(void)//清屏指令
{
WriteInstruction(0x1);
}*/
void ShowSingle(uchar x,uchar y,uchar z)//X表示第幾個字,Y表示第幾行,Z表示字符;
{
switch (y)
{
case 1:WriteInstruction(0x80+x-1);break;
case 2:WriteInstruction(0x90+x-1);break;
case 3:WriteInstruction(0x88+x-1);break;
case 4:WriteInstruction(0x98+x-1);break;
default:break;
}
WriteData(z);
}
//show_group()顯示一行字或字符程序;X:從第幾個字開始顯示(1~8);Y:第幾行(1~4);n:一行有幾個字符
void ShowGroup(uchar x,uchar y,uchar *p)
{
switch (y)
{
case 1:WriteInstruction(0x80+x-1);break;
case 2:WriteInstruction(0x90+x-1);break;
case 3:WriteInstruction(0x88+x-1);break;
case 4:WriteInstruction(0x98+x-1);break;
default:break;
}
while(*p)
{
WriteData(*p++);
}
}
//延時
void Delay(uint i)
{
while(i--);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -