换屏幕驱动芯片,按钮驱动都要连带一起改
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* ht1621.c
|
||||
*
|
||||
* Created on: 2021年10月12日
|
||||
* Author: wuwenfeng
|
||||
*/
|
||||
|
||||
|
||||
#include "ht1621.h"
|
||||
#include "my_code.h"
|
||||
|
||||
#define HT1621_addrbit 6 //驱动ic的ram地址位数 A5-A0
|
||||
|
||||
/**
|
||||
* @brief HT1621 clk
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void WriteClockHT1621(void)
|
||||
{
|
||||
HC595_SCK(0);
|
||||
HC595_SCK(1);
|
||||
}
|
||||
/**
|
||||
* @brief Write HT1621 Command
|
||||
* @param FunctonCode->功能/命令码
|
||||
* @retval None
|
||||
*/
|
||||
void WriteCommandHT1621(unsigned char FunctonCode)
|
||||
{
|
||||
unsigned char Shift = 0x80;
|
||||
unsigned char i;
|
||||
HC595_RCK(0); //CS 片选开
|
||||
HC595_DCK(1); //100
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(0);
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(0);
|
||||
WriteClockHT1621();
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
if(Shift & FunctonCode)
|
||||
{HC595_DCK(1);}
|
||||
else
|
||||
{HC595_DCK(0);}
|
||||
|
||||
WriteClockHT1621();
|
||||
Shift = Shift >> 1;
|
||||
}
|
||||
{HC595_DCK(0);}
|
||||
WriteClockHT1621(); //发送一个 0 命令码中最后一位 X
|
||||
HC595_RCK(1); //CS 片选关
|
||||
HC595_DCK(1);
|
||||
}
|
||||
/**
|
||||
* @brief Write 1 data to HT1621
|
||||
* @param Addr->写入ram的地址
|
||||
* @param Databuf->写入ram的数据
|
||||
* @retval None
|
||||
*/
|
||||
void Write1DataHT1621(unsigned char Addr,unsigned char Dat)
|
||||
{
|
||||
unsigned char i;
|
||||
unsigned char Shift;
|
||||
HC595_RCK(0); //CS 片选开
|
||||
HC595_DCK(1); //101
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(0);
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(1);
|
||||
WriteClockHT1621();
|
||||
Shift = 0x20; //屏蔽高3位 只用5位
|
||||
for( i = 0; i < HT1621_addrbit; i++)
|
||||
{
|
||||
if(Addr & Shift)
|
||||
{HC595_DCK(1);}
|
||||
else
|
||||
{HC595_DCK(0);}
|
||||
WriteClockHT1621();
|
||||
Shift = Shift >> 1;
|
||||
}
|
||||
|
||||
Shift = 0x01;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if( Dat & Shift)
|
||||
{HC595_DCK(1);}
|
||||
else
|
||||
{HC595_DCK(0);}
|
||||
WriteClockHT1621();
|
||||
Shift = Shift << 1;
|
||||
}
|
||||
HC595_RCK(1); //CS 片选关
|
||||
HC595_DCK(1);
|
||||
}
|
||||
/**
|
||||
* @brief Write n data to HT1621
|
||||
* @param Addr->写入ram的起始地址
|
||||
* @param Databuf->写入ram的数据buffer
|
||||
* @param Cnt->写入ram的数据个数
|
||||
* @retval None
|
||||
*/
|
||||
void WritenDataHT1621(unsigned char Addr,unsigned char *Databuf,unsigned char Cnt)
|
||||
{
|
||||
unsigned char i,j;
|
||||
unsigned char Shift;
|
||||
unsigned char dataval;
|
||||
HC595_RCK(0); //CS 片选开
|
||||
HC595_DCK(1); //101
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(0);
|
||||
WriteClockHT1621();
|
||||
HC595_DCK(1);
|
||||
WriteClockHT1621();
|
||||
Shift = 0x20; //屏蔽高3位 只用5位
|
||||
for( i = 0; i < HT1621_addrbit; i++)
|
||||
{
|
||||
if (Addr & Shift)
|
||||
{HC595_DCK(1);}
|
||||
else
|
||||
{HC595_DCK(0);}
|
||||
WriteClockHT1621();
|
||||
Shift = Shift >> 1;
|
||||
}
|
||||
for (j = 0; j < Cnt; j++)
|
||||
{
|
||||
Shift = 0x01;
|
||||
dataval=*Databuf++;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if( dataval & Shift)
|
||||
{HC595_DCK(1);}
|
||||
else
|
||||
{HC595_DCK(0);}
|
||||
WriteClockHT1621();
|
||||
Shift = Shift << 1;
|
||||
}
|
||||
}
|
||||
HC595_RCK(1); //CS 片选关
|
||||
HC595_DCK(1);
|
||||
}
|
||||
/**
|
||||
* @brief 数据交换,自动生成液晶需要的数组,此程序,需要根据液晶图纸修改
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
const unsigned char LED_Tab[]=
|
||||
{
|
||||
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-15 = 0--f
|
||||
0x58, //16=c
|
||||
0x37, //17=N
|
||||
0x40, //18=-
|
||||
0x0E, //19=J
|
||||
0x3E, //20=U
|
||||
0x76, //21=H
|
||||
0x30, //22=I
|
||||
};
|
||||
unsigned char LCD_RAM_Tab[sizeof(LED_Tab)];
|
||||
|
||||
#define LCD_A 0x01
|
||||
#define LCD_B 0x02
|
||||
#define LCD_C 0x04
|
||||
#define LCD_D 0x08
|
||||
#define LCD_E 0x10
|
||||
#define LCD_F 0x20
|
||||
#define LCD_G 0x40
|
||||
#define LCD_P 0x80
|
||||
|
||||
void HT1621_num_init(void)
|
||||
{
|
||||
unsigned char num,LCD_data;
|
||||
|
||||
for(num=0; num<sizeof(LED_Tab); num++)
|
||||
{
|
||||
LCD_data = 0;
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_P)) << 7);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_E)) << 6);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_F)) << 5);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_A)) << 4);
|
||||
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_D)) << 3);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_C)) << 2);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_G)) << 1);
|
||||
LCD_data = LCD_data | ((unsigned char)((char)(LED_Tab[num] & LCD_B)) << 0);
|
||||
|
||||
LCD_RAM_Tab[num] = LCD_data;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief HT1621 Init
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HT1621_Init(void) //退出掉电低功耗状态重新初始化HT1621
|
||||
{
|
||||
HC595_RCK(1);
|
||||
HC595_SCK(1);
|
||||
HC595_DCK(1);
|
||||
|
||||
WriteCommandHT1621(OSC_ON);
|
||||
WriteCommandHT1621(DISP_ON);
|
||||
|
||||
WriteCommandHT1621(COM_1_3__4);
|
||||
|
||||
//上电默认配置(以下未用功能关闭降低功耗)
|
||||
|
||||
WriteCommandHT1621(TIMER_DIS);
|
||||
WriteCommandHT1621(WDT_DIS);
|
||||
WriteCommandHT1621(BUZZ_OFF);
|
||||
WriteCommandHT1621(IRQ_DIS);
|
||||
|
||||
HT1621_num_init(); //自动生成液晶屏需要的数组
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 用户显示程序,需要自己完善
|
||||
* @param None
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void HT1621_Display(void)
|
||||
{
|
||||
|
||||
Write1DataHT1621(0,0x00);
|
||||
Write1DataHT1621(1,0x00);
|
||||
Write1DataHT1621(2,0x00);
|
||||
Write1DataHT1621(3,0x00);
|
||||
Write1DataHT1621(4,0x00);
|
||||
Write1DataHT1621(5,0x00);
|
||||
Write1DataHT1621(6,0x00);
|
||||
Write1DataHT1621(7,0x00);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user