📄 lcd.c
字号:
#include<reg51.h>
sbit SLCD_CS = P2^5;
sbit SLCD_STD = P2^4;
sbit SLCD_SCLK = P2^3;
#define SLCD_WIDTH 15
#define SLCD_NextLine SLCDSendCmd(0x00,0x90) //换行
void SLCDSendCmd(unsigned char cmd,unsigned char param);
void SLCDInit(unsigned char mode);
void SLCDCls(void);
void SLCDSendChar(unsigned char);
void SLCDSendString(const unsigned char*);
void SLCDSendNum(unsigned char num);
void SLCDSendByte(unsigned char dat)
{
unsigned char i=0;
unsigned char a=0;
SLCD_CS=1;
for(;i<8;i++)
{
if(dat&0x80)
SLCD_STD=1;
else SLCD_STD=0;
SLCD_SCLK=1;
SLCD_SCLK=0;
dat<<=1;
for(a=0;a<10;a++);
}
SLCD_CS=0;
}
void SLCDSendString(unsigned char* s)
{
unsigned char i=0;
while(s[i])
{
if(s[i]=='\n') SLCD_NextLine;
else SLCDSendCmd(0x02,s[i]);
i++;
if(i%15==0)SLCD_NextLine;
};
}
void SLCDSendChar(unsigned char ch)
{
if(ch=='\n') SLCD_NextLine;
else SLCDSendCmd(0x02,ch);
}
void SLCDSendNum(unsigned char num)
{
unsigned char a,b,c;
a=num/100;
b=(num%100)/10;
c=num%10;
if(a!=0)SLCDSendCmd(0x02,a+'0');
if(b!=0||a!=0)SLCDSendCmd(0x02,b+'0');
SLCDSendCmd(0x02,c+'0');
}
void SLCDSendCmd(unsigned char cmd,unsigned char param)
{
unsigned char a;
a=cmd;
cmd&=0x02;
a&=0x01;
a<<=2;
cmd|=a;
cmd|=0xf8;
SLCDSendByte(cmd);
a=param;
a&=0xf0;
param<<=4;
param&=0xf0;
SLCDSendByte(a);
SLCDSendByte(param);
SLCD_CS=0;
}
void SLCDCls(void)
{
SLCDSendCmd(0x00,0x01);
}
void SLCDInit(unsigned char mode)
{
SLCDSendCmd(0x00,0x30);
SLCDSendCmd(0x00,0x01);
SLCDSendCmd(0x00,0x06);
SLCDSendCmd(0x00,0x0c);
if(mode==0)
{
SLCDSendCmd(0x00,0x30);
SLCDSendCmd(0x00,0x80);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -