合泰 HT1632顯示 驅動程式碼
void DisplayDriverProcess(void)
{
LCD_CS1=0;
HT1632C_Writer_AllDATA(0x00, image1, 48);
LCD_CS1=1;
LCD_CS2=0;
HT1632C_Writer_AllDATA(0x00, image2, 48);
LCD_CS2=1;
}
void HT1632C_Writer_AllDATA(unsigned char Addr,unsigned char* p,unsigned char cnt)
{ //指定起始地址連續寫入資料,cnt為寫入資料個數,每個資料按位算
unsigned char i;
SBR_PREDATA_1632();
// HT1632C_Writer(0xa0,3);
HT1632C_Writer(Addr<<1,7);
for(i=0;i<cnt;i++)
{
HT1632C_Writer(p[i],8);
}
}
void SBR_PREDATA_1632(void)
{
LCD_CLOCK = 0;
LCD_DATA = 1; // 1
LCD_Delay(10);
LCD_CLOCK = 1;
LCD_Delay(10);
LCD_Delay(10);
LCD_CLOCK= 0;
LCD_DATA = 0; // 0
LCD_Delay(10);
LCD_CLOCK = 1;
LCD_Delay(10);
LCD_Delay(10);
LCD_CLOCK = 0;
LCD_DATA = 1; // 1
LCD_Delay(10);
LCD_CLOCK = 1;
LCD_Delay(10);
LCD_Delay(10);
}
void HT1632C_Writer(unsigned char Data,unsigned char cnt)
{
unsigned char i,temp;
temp = 0x01;
for(i=0 ; i<cnt ; i++)
{
LCD_CLOCK = 0; //clk = 0 for data ready
if((temp & Data) == 0) LCD_DATA = 0;
else LCD_DATA = 1;
LCD_CLOCK = 1; //clk = 1 for data write into 1632
temp <<= 1;
}
}
void DisplayDriverInitialize(void)
{
uchar LED_T;
uchar i;
#if 1
LCD_CS1=0;
LCD_CS2=0;
//LCD_CLOCK=1;
//LCD_DATA=1;
SBR_PRECOMMAND_1632();
HT1632C_Writer_CMD(SYS_EN); //關閉HT1632C內部RC時鐘
HT1632C_Writer_CMD(COM_OPTION); //選擇HT1632C工作模式,COM,NMOS模式
HT1632C_Writer_CMD(LED_ON); //選擇內部RC時鐘
HT1632C_Writer_CMD(BLINK_OFF); //開啟HT1632C內部RC時鐘
HT1632C_Writer_CMD(COM_OPTION); //PWM亮度設定
HT1632C_Writer_CMD(PWM_DUTY); //PWM亮度設定
//HT1632C_Writer_CMD(PWM_DUTY); //PWM亮度設定
// Delay(1000);
// HT1632C_Writer_CMD(BLINK_OFF); //關閉閃爍
// Delay(1000);
// HT1632C_Writer_CMD(LED_ON); //開啟LED顯示
LCD_CS1=1;
LCD_CS2=1;
LED_T= 30;
for(i=0;i<LED_T;i++)
{
//image1[i]=0x0;
}
#else
LCD_CS1=0;
LCD_CS2=0;
//LCD_CLOCK=1;
//LCD_DATA=1;
SBR_PRECOMMAND_1632();
HT1632C_Writer_CMD(SYS_EN); //關閉HT1632C內部RC時鐘
HT1632C_Writer_CMD(COM_OPTION); //選擇HT1632C工作模式,COM,NMOS模式
HT1632C_Writer_CMD(LED_ON); //選擇內部RC時鐘
HT1632C_Writer_CMD(BLINK_OFF); //開啟HT1632C內部RC時鐘
HT1632C_Writer_CMD(PWM_DUTY); //PWM亮度設定
//HT1632C_Writer_CMD(PWM_DUTY); //PWM亮度設定
// Delay(1000);
// HT1632C_Writer_CMD(BLINK_OFF); //關閉閃爍
// Delay(1000);
// HT1632C_Writer_CMD(LED_ON); //開啟LED顯示
LCD_CS1=1;
LCD_CS2=1;
#endif
}
//指令表
#define SYS_DIS 0x00 //關閉系統震盪
#define SYS_EN 0x01 //開啟系統震盪
#define LED_OFF 0x02 //關閉LED顯示
#define LED_ON 0x03 //開啟LED顯示
#define BLINK_OFF 0x08 //關閉閃爍
#define BLINK_ON 0x09 //開啟閃爍
#define SLAVE_MODE 0x10 //從模式
#define RC_MASTER_MODE 0x18 //內部RC時鐘
#define EXT_CLK_MASTER_MODE 0x1C //外部時鐘
//#define COM_OPTION 0x2C //8COM n-mos模式 // 16--com--p模式
#define COM_OPTION 0x2c //8COM n-mos模式 // 16--com--p模式
//#define PWM_DUTY 0XA0 //PWM亮度控制
#define PWM_DUTY 0xAf // 0xAF //PWM亮度控制