换屏幕驱动芯片,按钮驱动都要连带一起改

This commit is contained in:
2021-10-13 10:16:41 +08:00
parent 0dbc76aad1
commit 3ff28bd9a6
13 changed files with 4280 additions and 3789 deletions
+236
View File
@@ -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);
}
+51
View File
@@ -0,0 +1,51 @@
/*
* ht1621.h
*
* Created on: 2021年10月12日
* Author: wuwenfeng
*/
#ifndef HT1621_H_
#define HT1621_H_
#include "main.h"
//基本命令
#define OSC_OFF 0x00 // 关闭震荡器
#define OSC_ON 0x01 // 开启震荡器
#define DISP_OFF 0x02 // 关LCD Bias
#define DISP_ON 0x03 // 开LCD Bias
#define COM_1_3__4 0x29 // 1/3bias 4com
#define COM_1_3__3 0x25 // 1/3bias 3com
#define COM_1_3__2 0x21 // 1/3bias 2com
#define COM_1_2__4 0x28 // 1/2bias 4com
#define COM_1_2__3 0x24 // 1/2bias 3com
#define COM_1_2__2 0x20 // 1/2bias 2com
//扩展命令,该功能未引出关闭可降低功耗
#define TIMER_DIS 0x04 // 不使 time base 輸出
#define WDT_DIS 0x05 // 不使 WDT 暫停旗標輸出
#define BUZZ_OFF 0x08 // 关闭蜂鸣器
#define RC32K 0X18 //
#define IRQ_DIS 0X80 // 不使 IRQ 輸出
/* Exported functions ------------------------------------------------------- */
void WriteClockHT1621(void);
void WriteCommandHT1621(unsigned char FunctonCode);
void Write1DataHT1621(unsigned char Addr,unsigned char Dat);
void WritenDataHT1621(unsigned char Addr,unsigned char *Databuf,unsigned char Cnt);
void HT1621_num_init(void);
void HT1621_Init(void);
void HT1621_Display(void);
#endif /* HT1621_H_ */
+18 -150
View File
@@ -6,21 +6,13 @@
*/
#include "my_code.h"
#include "button.h"
#define HC595_DCK(x) HAL_GPIO_WritePin(HC595_DLK_GPIO_Port, HC595_DLK_Pin, x);
#define HC595_RCK(x) HAL_GPIO_WritePin(HC595_RLK_GPIO_Port, HC595_RLK_Pin, x);
#define HC595_SCK(x) HAL_GPIO_WritePin(HC595_SLK_GPIO_Port, HC595_SLK_Pin, x);
#define HC595_SCK2(x) HAL_GPIO_WritePin(HC595_SLK2_GPIO_Port, HC595_SLK2_Pin, x);
#define READ_HC595_DCK HAL_GPIO_ReadPin(HC595_DLK_GPIO_Port,HC595_DLK_Pin)
#include "ht1621.h"
extern ADC_HandleTypeDef hadc;
struct button key1,key2,key3,key4,overload;
const char d_num_data[10]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
#define set_filtering_times 50
struct
@@ -32,24 +24,6 @@ struct
}ADCC;
struct
{
char d_num[4];
char button_flag[4];
char dot1:1;
char dot2:1;
char dot3:1;
char dot4:1;
char led_run:1;
char moto1a:1;
char moto1b:1;
char moto2a:1;
char moto2b:1;
}dis_buff;
struct
{
uint32_t moto_run;
@@ -92,39 +66,7 @@ uint8_t Read_Ds()
if(READ_HC595_DCK){return 0;}else{return 1;}
//return READ_HC595_DCK;
}
void Sand_Byte_to_595(uint8_t h,uint8_t l)
{
ds_in_or_out(1);
HC595_DCK(0);
HC595_SCK(0);
HC595_RCK(0);
for(char a=0;a<8;a++)
{
if((h<<a)&0x80)
{
HC595_DCK(1);
}else
{
HC595_DCK(0);
}
HC595_SCK(1);
HC595_SCK(0);
}
for(char a=0;a<8;a++)
{
if((l<<a)&0x80)
{
HC595_DCK(1);
}else
{
HC595_DCK(0);
}
HC595_SCK(1);
HC595_SCK(0);
}
HC595_RCK(1);
HC595_RCK(0);
}
void Sand_Byte_to_595_2(uint8_t h)
{
ds_in_or_out(1);
@@ -146,84 +88,8 @@ void Sand_Byte_to_595_2(uint8_t h)
HC595_RCK(1);
HC595_RCK(0);
}
#define A 0x80
#define B 0x40
#define C 0x20
#define D 0x10
#define E 0x08
#define F 0x04
#define G 0x02
#define H 0x01
const char num_com[4]={0x1,0x2,0x4,0x8};
const char d_com[4]={0x80,0x40,0x20,0x10};
void display_and_button_loop()
{
//Sand_Byte_to_595(0x00,0xff);
//Sand_Byte_to_595(0xff,0x00);
char lcd_buff[4];
char change_buff;
char h,l;
//fast time change 1
for(int a=0;a<4;a++)
{
change_buff=d_num_data[dis_buff.d_num[a]];//num to data model
if(change_buff&&A)
{
lcd_buff[0]|=0x80>>(a*2);
}
if(change_buff&&B)
{
lcd_buff[0]|=0x40>>(a*2);
}
if(change_buff&&C)
{
lcd_buff[2]|=0x40>>(a*2);
}
if(change_buff&&D)
{
lcd_buff[3]|=0x40>>(a*2);
}
if(change_buff&&E)
{
lcd_buff[2]|=0x80>>(a*2);
}
if(change_buff&&F)
{
lcd_buff[1]|=0x80>>(a*2);
}
if(change_buff&&G)
{
lcd_buff[1]|=0x40>>(a*2);
}
}
//Sand_Byte_to_595(0xff,0xff);
//Sand_Byte_to_595(~h,~l);
//Sand_Byte_to_595(0,0);
//Sand_Byte_to_595(0xff,0xff);
for(int a=0;a<4;a++)
{
l=lcd_buff[a];
//h=((~num_com[a])&0x0F);
h=(~d_com[a]&0xf0)|((~num_com[a])&0x0F);
Sand_Byte_to_595(h,l);
dis_buff.button_flag[a]=Read_Ds();
//Sand_Byte_to_595(~h,~l);
}
}
void hc2_sever()
{
char h=0;
@@ -346,8 +212,7 @@ void my_code()
{
uint32_t runtime=0,move=0;
uint8_t mode=0,overload_mode=0;
uint16_t adc,adc_times=0;
uint32_t adc_l;
uint16_t overload_times=0;
long countdown=0;
long countdown_set=15000;
@@ -361,17 +226,19 @@ void my_code()
dis_buff.moto2a=0;
dis_buff.moto2b=0;
moto.moto_run=0;
moto.pwm_run=0;
moto.moto1a=0;
moto.moto1b=0;
moto.moto2a=0;
moto.moto2b=0;
moto.moto_run=0;
moto.pwm_run=0;
moto.moto1a=0;
moto.moto1b=0;
moto.moto2a=0;
moto.moto2b=0;
moto.moto1a_=0;
moto.moto1b_=0;
moto.moto2a_=0;
moto.moto2b_=0;
moto.moto1a_=0;
moto.moto1b_=0;
moto.moto2a_=0;
moto.moto2b_=0;
HT1621_Init();
while(1)
{
//*adc读取 并计滤波 并计算温度*/
@@ -651,7 +518,8 @@ moto.moto2b_=0;
GEI_BUTTON_CODE(&key2,dis_buff.button_flag[1]);
GEI_BUTTON_CODE(&key3,dis_buff.button_flag[2]);
GEI_BUTTON_CODE(&key4,dis_buff.button_flag[3]);
display_and_button_loop();
//display_and_button_loop();
HT1621_Display();
hc2_sever();
moto_server();
}
+25
View File
@@ -11,4 +11,29 @@
void my_code();
#define HC595_DCK(x) HAL_GPIO_WritePin(HC595_DLK_GPIO_Port, HC595_DLK_Pin, x);
#define HC595_RCK(x) HAL_GPIO_WritePin(HC595_RLK_GPIO_Port, HC595_RLK_Pin, x);
#define HC595_SCK(x) HAL_GPIO_WritePin(HC595_SLK_GPIO_Port, HC595_SLK_Pin, x);
#define HC595_SCK2(x) HAL_GPIO_WritePin(HC595_SLK2_GPIO_Port, HC595_SLK2_Pin, x);
#define READ_HC595_DCK HAL_GPIO_ReadPin(HC595_DLK_GPIO_Port,HC595_DLK_Pin)
struct display_penal
{
char d_num[4];
char button_flag[4];
char dot1:1;
char dot2:1;
char dot3:1;
char dot4:1;
char led_run:1;
char moto1a:1;
char moto1b:1;
char moto2a:1;
char moto2b:1;
}dis_buff;
#endif /* MY_CODE_H_ */