微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机ST7565C语言驱动程序

51单片机ST7565C语言驱动程序

时间:11-28 来源:互联网 点击:
#include
#include
#defineuchar unsigned char
#defineuint unsigned int
/////////////////////////////////Serial///////////////////////////////////////////////////


sbitR_S=P3^5;//指令/数据选择信号
sbitRES=P3^4;//复位信号
sbitSCK=P1^6;
sbitSDA=P1^7;
sbitC_S=P3^7;//片选

//////////////////////////////////////////////////////////////////////////////////////////////


uchar Page = 0xb0;
///12345678910111213141516///
unsigned char code Number[][16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 1
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 2
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 3
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 4
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 5
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 6
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 27
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 28
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 29
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 30
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 31
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00//f 32
};

void delay(uint ms)
{
uchar j;
while(ms--)
for(j=0;j=20;j++); //20us=0.02ms//

}

/////////////////////////Serial///////////////////////////

void WrateC(uchar com)

{
unsigned char data i,j;
C_S=0;
R_S=0;
SCK=0;
for(i=0;i<8;i++)
{
j=com;
SCK=0;
SDA=com&0x80;
SCK=1;
com=j<1;
}
C_S=1;
R_S=1;
}

void WrateD(uchar dat)
{
unsigned char data i,j;
C_S=0;
R_S=1;
SCK=0;
for(i=0;i<8;i++)
{
j=dat;
SCK=0;
SDA=dat&0x80;
SCK=1;
dat=j<1;
}
C_S=1;
R_S=0;
}

void ClearDisplay()
{
unsigned chari,j;
for(i=0;i<8;i++)
{
WrateC(Page+i);// (Page = 0xB0)//设置位置
WrateC(0x10);
WrateC(0x00);
for(j=0;j<132;j++)//发送数据
{
WrateD(0);
}
}
}
void LcdInit()
{
RES=0;
delay(50);//最少2um
RES=1;
delay(20);

WrateC(0xe2);//软件复位
WrateC(0xA3);//Bais set显示偏压
WrateC(0xA1);//ADC seg镜像选择 0xa0正常,0xA1左右镜像
WrateC(0xc0);//com output scan direction,com镜像选择 0xc0正常,0xC8上下镜像
/////////Select internal resistor ratio/////////
WrateC(0x2c);//内部电源管理
WrateC(0x2e);//三条指令间隔时间2um
WrateC(0x2F);//
//////////////////////////////////////////////////////////////////////////////

WrateC(0x81);//电压模式选择
WrateC(0x16);//电压调整寄存器低位 范围:0x00-0x3f
WrateC(0x24);//电压调整寄存器高位 范围:0x21-0x27 ,值越大,显示效果越浓(底影越浓)

WrateC(0xAF);//显示开
WrateC(0x40);//从首行开始显示

ClearDisplay();
}

void Setadd(uchar xl,uchar yl)
{uchar i;
i=xl&0x0f;
xl=(xl>>4)+0x10;

WrateC(0xb0+yl);
WrateC(xl);
WrateC(i);
}

void ShowOneDig(uchar col,uchar pag,uchar d)
{
uchar i = 0 ;
uchar j;
if(col>0x7f)
{
col=0;
pag+=2;
}
Setadd(col,pag);
for(j=0;j<8;j++)
{
WrateD(Number[d][i++]);
}
pag++;
Setadd(col,pag);
for(j=0;j<8;j++)
{
WrateD(Number[d][i++]);
}
pag++;
}

void main()
{
unsigned char a = 0 ;
LcdInit();
ClearDisplay();
ShowOneDig(80,3,10);
ShowOneDig(88,3,9);
ShowOneDig(72,3,5);
while(1);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top