您的位置 首页 发布

51单片机ST7565C言语驱动程序

includereg51h>includeintrinsh>defineucharunsignedchardefineuintunsignedintSer

#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);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/fabu/255876.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部