HT1621驱动程序
void SendBit(uchar dat,uchar bitcnt)
{
uchar i;
for(i=0;i<bitcnt;i++)
{
Ht1621_WR = 0; /*置时钟线为高通知被控器开始接收数位*/
if(( dat & 0x80 ) == 0)
Ht1621_Data = 0;
else
Ht1621_Data = 1; /*发送数据由高位到低位传送*/
DelayUS(1);
Ht1621_WR = 1; /*钳住总线准备下一个数据位*/
DelayUS(1);
dat=dat<<1; /*发送数据左移一位*/
}
}
void HT1621_init(void)
{
Ht1621_CS = 1; /*CS 端口为1*/
Ht1621_WR = 1; /*WR 端口为1*/
Ht1621_RD = 1; /*WR 端口为1*/
Ht1621_Data = 1; /*DATA端口为1*/
}
void HT1621_WriteCmd(unsigned char Cmd,unsigned char Cmd_Data)
{
Ht1621_CS = 0;
DelayUS(1);
SendBit(Cmd,4);
SendBit(Cmd_Data,8);
Ht1621_CS = 1;
DelayUS(1);
}
void HT1621_WriteData(unsigned char Waddr,unsigned charWdata,unsigned char Wnum)
{
Ht1621_CS = 0;
DelayUS(1);
SendBit(0xA0,3);
Waddr = Waddr << 2;
SendBit(Waddr,6);
Wdata = Wdata << (8-Wnum);
SendBit(Wdata,Wnum);
Ht1621_CS = 1;
DelayUS(1);
}
void HT1621_Cmd_init(void)
{
HT1621_WriteCmd(Cmd8,SYSEN); //打开系统振荡器命令
HT1621_WriteCmd(Cmd8,LCDON); //打开LCD偏压发生器命令
HT1621_WriteCmd(Cmd8,WDTDIS); //WDT 溢出标志输出失效命令
HT1621_WriteCmd(Cmd8,TIMEREN); //时基输出使能命令
HT1621_WriteCmd(Cmd8,RC256 ); ///系统时钟源片内RC振荡器命令
HT1621_WriteCmd(Cmd8, BIAS ); //LCD1/3偏压选项4个公共口命令
HT1621_WriteCmd(Cmd9, F1 ); /*时基/WDT 时钟输出1Hz WDT设置为4秒溢出*/
HT1621_WriteCmd(Cmd9, IRQEN ); /*时基/WDT 时钟输出1Hz WDT设置为4秒溢出*/