#include <reg51.h>
#include <intrins.h>
#define BIAS 0x29 //1/3duty 4com
#define SYSEN 0X01
#define LCDON 0X03
#define RC256 0X18
sfr CLK_DIV = 0xc7; //STC时钟分频寄存器
sbit HT1621_DAT=P0^2;
sbit HT1621_CS=P1^4;
sbit HT1621_WR=P1^3;
sbit BL1=P1^1;
sbit BL2=P2^4;
void Delay(uchar us)
{
while(--us);
}
void DelayMS(uint iMs)
{
uint i,j;
for(i=0;i<iMs;i++)
for(j=0;j<65;j++) Delay(1);
}
void Ht1621Wr_Data(uchar Data,uchar cnt)
{
uchar i;
for (i=0;i<cnt;i++)
{
HT1621_WR=0;
if(Data&0x01)
HT1621_DAT = 1;
else
HT1621_DAT = 0;
Delay(10);
HT1621_WR=1;
Delay(10);
Data >>= 1;
}
}
void Ht1621Wr_AddrCmdData(uchar Data,uchar cnt)
{
uchar i;
for (i=0;i<cnt;i++)
{
HT1621_WR=0;
if(Data&0x80)
HT1621_DAT = 1;
else
HT1621_DAT = 0;
Delay(10);
HT1621_WR=1;
Delay(10);
Data<<=1;
}
if(cnt == 8)
{
HT1621_WR=0;
HT1621_DAT = 0;
Delay(10);
HT1621_WR=1;
Delay(10);
}
}
void Ht1621WrCmd(uchar Cmd)
{
HT1621_CS=0;
Ht1621Wr_AddrCmdData(0x80,3);
Ht1621Wr_AddrCmdData(Cmd,8);
HT1621_CS=1;
Delay(10);
}
void Ht1621WrOneData(uchar Addr,uchar Data)
{
HT1621_CS=0;
Ht1621Wr_AddrCmdData(0xa0,3);
Ht1621Wr_AddrCmdData(Addr<<2,6);
Ht1621Wr_Data(Data<<4,4);
HT1621_CS=1;
Delay(10);
}
void Ht1621_all_dispaly()
{
uchar i;
uchar Addr = 0;
for(i=0;i<32;i++)
{
Ht1621WrOneData(Addr,0xff);
Addr += 1;
}
}
void Ht1621_Init(void)
{
BL1=0; //背光灯亮
BL2=0;
HT1621_CS=1;
HT1621_WR=1;
HT1621_DAT=1;
DelayMS(200);
Ht1621WrCmd(SYSEN);
Ht1621WrCmd(LCDON);
Ht1621WrCmd(BIAS);
Ht1621WrCmd(RC256);
}
void main()
{
CLK_DIV = 0x07;
Ht1621_Init();
DelayMS(200);
Ht1621_all_dispaly();
while(1);
}
|