#include<reg51.h>
#define RAMSIZE 16 //RAM区16字节
#define BIAS 0x52
#define RC256K 0x30
#define LCDON 0x06
#define SYSEN 0x02
#define SYSDIS 0x00
#define uchar unsigned char
#define uint unsigned int
sbit ht_wr=P1^2;
sbit ht_cs=P1^4;
sbit ht_da=P1^3;
void delay(void){ ; ; }
void enable(void);
void sendbit(uchar nbit,uchar n);
void sendcommand(uchar command);
void reset(void);
void setup(void);
void sendbyte(uchar addr,uchar byte);
void sendstring(uchar addr,uchar *ptr,uchar len);
;http://www.51hei.com出品
;HT1621 32字节×4位LCD液晶驱动芯片程序,程序没有注释原理请读者自行分析。
void enable(void)
{
ht_cs=0;
ht_wr=1;
delay();
ht_wr=0;
delay();
}
void sendbit(uchar nbit,uchar n)
{
uchar i;
for(i=0;i<n;i++)
{
if(nbit&0x80)
ht_da=1;
else ht_da=0;
ht_wr=0;
delay();
ht_wr=1;
delay();
nbit<<=1;
}
ht_cs=1;
ht_da=1;
}
void sendcommand(uchar command)
{
enable();
sendbit(0x80,4);
sendbit(command,8);
ht_wr=1;
delay();
ht_cs=1;
delay();
ht_da=1;
}
void reset(void)
{
ht_wr=1;
delay();
ht_cs=1;
delay();
ht_da=1;
}
void setup(void)
{
sendcommand(BIAS);
sendcommand(RC256K);
sendcommand(SYSEN);
sendcommand(LCDON);
}
void sendbyte(uchar addr,uchar byte)
{
addr<<=3;
enable();
sendbit(0xA0,3);
sendbit(addr,6);
sendbit(byte,8);
ht_wr=1;
delay();
ht_cs=1;
}
void sendstring(uchar addr,uchar *ptr,uchar len)
{
uchar i;
addr<<=2;
enable();
sendbit(0xa0,3);
sendbit(addr,6);
if((len+addr)>RAMSIZE)len=RAMSIZE-addr;
for(i=0;i<len;i++)
{
sendbit(ptr[i],8);
}
ht_cs=1;
}
void main()
{
setup();
sendbyte(0x04,0x11);
}