📄 ht1621b.c
字号:
/*
***************************************************************************************************
* Copyright (C),2007
* Author : YanZhongsan
* Email : yanzhongsan@gmail.com
* Date : 2007-10-17
* File name : HT1621B.c
* Description : HT1621B driver file
* Version : V1.0
* Others : Before any command or read/write ,should initialized the chip by Init_HT1621B
* : function
***************************************************************************************************
*/
/** include files **/
#include "includes.h"
#include "HT1621B.h"
/*
***************************************************************************************************
* Function name : Init_HT1621B
* Description : Initialized the TH1621B
* Note : After Power on reset or disable display shoule reinitialized the chip
* Parameters : None
* Returns : None
* Attribute : Public function
* Others : None
***************************************************************************************************
*/
void Init_HT1621B(void)
{
HT1621BSendCommand(HT_SUB_NORMAL);
HT1621BSendCommand(HT_SUB_SYS_ENABLE);
HT1621BSendCommand(HT_SUB_LCD_ON);
HT1621BSendCommand(HT_SUB_BIAS13_4);
HT1621BSendCommand(HT_SUB_BIAS12_4);
}
/*
***************************************************************************************************
* Function name : HT1621BClearAll
* Description : Clear all data in RAM,nothing displaying
* Note : The data in the display RAM control display,1:display,0:nodisplay
* Parameters : None
* Returns : None
* Attribute : Public function
* Others : If can't run,shoule modify the WR clock by DELAY_1us
***************************************************************************************************
*/
void HT1621BClearAll(void)
{
UCHAR_8 counter;
//Enable the serial interface first
SET_HT_CS_LOW;
//Send command 101
SET_HT_WR_LOW;
SET_HT_DATA_HIGH;
DELAY_1us(2);
SET_HT_WR_HIGH;
DELAY_1us(2);
SET_HT_WR_LOW;
SET_HT_DATA_LOW;
DELAY_1us(2);
SET_HT_WR_HIGH;
DELAY_1us(2);
SET_HT_WR_LOW;
SET_HT_DATA_HIGH;
DELAY_1us(2);
SET_HT_WR_HIGH;
DELAY_1us(2);
//Set the data wire to logic 0
SET_HT_DATA_LOW;
//Send the address and data,All 0,address will auto increase
for (counter=0;counter<134;counter++)
{
SET_HT_WR_LOW;
DELAY_1us(3);
SET_HT_WR_HIGH;
DELAY_1us(3);
}
//Disable the serial interface
SET_HT_CS_HIGH;
}
/*
***************************************************************************************************
* Function name : HT1621BSendCommand
* Description : Send command to the HT1621B,and just send the command!
* Note : The sub-command is 9 bits,but bit0 is don't care,so,Just transfer 8bits
* : subcommand's bit7-bit0 use as command's bit8-bit1
* Parameters : UCHAR_8 sub_command,the real command that config the chip
* Returns : None
* Attribute : Public function
* Others : The command is like this: 100-dddd-dddd-X
* : d:sub-command bit,0 or 1
* : X:don't care about it
***************************************************************************************************
*/
void HT1621BSendCommand(UCHAR_8 subcommand)
{
SCHAR_8 counter;
UINT_16 temp;
temp = HT_COMMAND_COMMAND|(subcommand<<1);
// Enable the serial interface first
SET_HT_CS_LOW;
for (counter=11;counter>=0;counter--)
{
SET_HT_WR_LOW;
if (0x00==TESTBIT(temp,counter))
{
SET_HT_DATA_LOW;
}
else
{
SET_HT_DATA_HIGH;
}
DELAY_1us(3);
SET_HT_WR_HIGH;
DELAY_1us(3);
}
//Disable the serial interface at end
SET_HT_CS_HIGH;
}
/*
***************************************************************************************************
* Function name : HT1621BWritedata
* Description : write data to HT1621B
* Note : This function is just used to write data to HT1621B,Don't used to
* : send command,That is another one's work!!!!!
* Parameters : UCHAR_8 addr,the address of HT1621's RAM,bit5-bit0 useful only
* : UCHAR_8 data,will send to HT1621B,Two cells will be write
* Returns : None
* Attribute : Public function
* Others : 1.CS signal low active the ship first
* : 2.DATA signal will be clock into the HT1621 on the rising edge of WR signal
* : 3.CS signal high terminate the data transmission,disable the serial interface
***************************************************************************************************
*/
void HT1621BWritedata(UCHAR_8 addr,const UCHAR_8 data)
{
SCHAR_8 counter;
UINT_16 temp;
temp = HT_WRITE_COMMAND|(addr&0x3F);
//Enable the serial interface
SET_HT_CS_LOW;
//Set the data line output
SET_HT_DATA_OUT;
//Send the command and address
for (counter=8;counter>=0;counter--)
{
SET_HT_WR_LOW;
if (0x00==TESTBIT(temp,counter))
{
SET_HT_DATA_LOW;
}
else
{
SET_HT_DATA_HIGH;
}
DELAY_1us(3);
SET_HT_WR_HIGH;
DELAY_1us(3);
}
//Send the data,LSB first
for (counter=0;counter<8;counter++)
{
SET_HT_WR_LOW;
if (0x00==TESTBIT(data,counter))
{
SET_HT_DATA_LOW;
}
else
{
SET_HT_DATA_HIGH;
}
DELAY_1us(3);
SET_HT_WR_HIGH;
DELAY_1us(3);
}
//Disable the serial interface
SET_HT_CS_HIGH;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -