咨询热线:18926046819

工业液晶屏(LCD)定制专家

首页液晶模块技术参考 段码液晶屏驱动程序范例

段码液晶屏驱动程序范例

2016年08月03日18:25 

段码液晶屏驱动程序。很多客户在初次使用段码液晶屏的时候,总问我有没有可以参考的C语言驱动程序。因为驱动IC有很多,这里就以驱动IC HT1621,驰宇微CYW-D327段码液晶屏为例,做一个参考程序。

/*IC :HT1621*/

#include
#include
#include

#define uchar unsigned char
#define uint unsigned int
//-----------------------------------------------------------------------------
sbit DATAB =P3^7;
sbit WRB =P3^6;
sbit CSB =P2^7;



//uchar zz;

//Control the program to run

#define BIAS 0x52 /*定义1 3 偏压4 背极*/
#define XTAL32 0x28 /*使用外部晶振*/
#define RC256 0x30 /*使用内部256KRC 振荡器*/
#define SYSEN 0x02 /*打开振荡发生器*/
#define LCDON 0x06 /*打开LCD*/
#define SYSDIS 0x00 /*关闭振荡发生器*/
#define LCDOFF 0x04 /*显示关闭*/
#define TONE4 0x80 /*设置BZ 输出频率为4K*/
#define TONEON 0x12 /*打开BZ 音频输出*/
#define TONEOFF 0x10 /*关闭BZ 音频输出*/
#define CLRWDT 0x1c /*清零WDT*/
#define IRQEN 0x10 /*IRQ 输出禁止*/
#define IRQDIS 0x00 /*IRQ 输出允许*/
#define WDTEN 0x0e /*打开WDT*/
#define WDTDIS 0x0a /*关闭WDT*/
#define TIMERDIS 0x08 /*关闭时基输出*/
//-----------------------------------------------------------------------------

uchar code TAB0[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
uchar code TAB1[]={0xda,0x3c,0x83,0xc8,0x3c,0x83,0xc8,0x3c,0x83,0xc8,0x3b,0x96,0x4f,0x35,0xd3,0xfb,};
uchar code TAB2[]={0x3a,0xa5,0x8a,0x58,0xa5,0x8a,0x58,0xa5,0x8a,0x58,0xa4,0x69,0xbf,0xdb,0xdd,0xf7,};
uchar code TAB3[]={0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x6f,0x76,0xf7,0x13,};

//-----------------------------------------------------------------------------
void delay_us(uchar us_value) //delay about 1 us
{
while(us_value--)
{
_nop_();
_nop_();
_nop_();
}
}
//-----------------------------------------------------------------------------
void delay_ms(uint ms_value) //delay about 1 ms
{
uint k;

for(k=0;k<ms_value;k++)
{
delay_us(200);
}
}
//-----------------------------------------------------------------------------
void init_cpu() //Initial 89C52
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
}
//-----------------------------------------------------------------------------
void wr_cmd(uchar x)
{
uchar i,j=0x80;
CSB=0;

_nop_();
_nop_();

for(i=0;i<4;i++)
{
if(j&0x80)
DATAB=1;
else DATAB=0;
WRB=0;
_nop_();
_nop_();
WRB=1;
_nop_();
j<<=1;
}

for(i=0;i<8;i++)
{
if(x&0x80)
DATAB=1;
else DATAB=0;
WRB=0;
_nop_();
_nop_();
WRB=1;
_nop_();
x<<=1;
}
CSB=1;

_nop_();
_nop_();
}
//-----------------------------------------------------------------------------
void wr_add(uchar y)
{
uchar i,j=0xa0;

for(i=0;i<3;i++)
{
if(j&0x80)
DATAB=1;
else DATAB=0;
WRB=0;
_nop_();
_nop_();
WRB=1;
_nop_();
j<<=1;
}

y<<=2;
for(i=0;i<6;i++)
{
if(y&0x80)
DATAB=1;
else DATAB=0;
WRB=0;
_nop_();
_nop_();
WRB=1;
_nop_();
y<<=1;
}
}
//-----------------------------------------------------------------------------
void wr_byte(uchar z)
{
uchar i;
for(i=0;i<8;i++)
{
if(z&0x80)
DATAB=1;
else DATAB=0;
WRB=0;
_nop_();
_nop_();
WRB=1;
_nop_();
z<<=1;
}
}

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
void disp_all()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(0xff);
}

CSB=1;

}


//-----------------------------------------------------------------------------
void disp_off()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(0x00);
}

CSB=1;

}



//-----------------------------------------------------------------------------
void disp_bm0()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(TAB0[i]);
}

CSB=1;
}
//-----------------------------------------------------------------------------
void disp_bm1()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(TAB1[i]);
}

CSB=1;

}
//-----------------------------------------------------------------------------
void disp_bm2()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(TAB2[i]);
}

CSB=1;

}
//-----------------------------------------------------------------------------
void disp_bm3()
{

uchar i;
CSB=0;
wr_add(0);
for(i=0;i<16;i++)
{
wr_byte(TAB3[i]);
}

CSB=1;

}
//-----------------------------------------------------------------------------
void init_lcd()
{


CSB=1;
WRB=0;
DATAB=1;
delay_ms(100);
wr_cmd(BIAS);
wr_cmd(SYSEN);
wr_cmd(TIMERDIS);
wr_cmd(LCDON);
delay_ms(10);
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void main(void)
{

init_cpu();
init_lcd();

while(1)
{


disp_all();
delay_ms(500);

disp_bm0();
delay_ms(500);

disp_bm1();
delay_ms(500);

disp_bm2();
delay_ms(500);

disp_bm3();
delay_ms(500);

disp_off();
delay_ms(300);



}


}

网友热评