好像硬件设计错了。。
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* my_code.c
|
||||
*
|
||||
* Created on: Oct 2, 2021
|
||||
* Author: wuwenfeng
|
||||
*/
|
||||
#include "my_code.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)
|
||||
const char d_num_data[10]=
|
||||
{
|
||||
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
char d_num[4];
|
||||
char dot1:1;
|
||||
char dot2:1;
|
||||
char dot3:1;
|
||||
char dot4:1;
|
||||
char led_run:1;
|
||||
char led_p:1;
|
||||
char led_n:1;
|
||||
char led_err:1;
|
||||
}dis_buff;
|
||||
|
||||
void ds_in_or_out(char a)//change the io function
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = HC595_DLK_Pin;
|
||||
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
if(a==0)
|
||||
{
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
}
|
||||
if(a==1)
|
||||
{
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
}
|
||||
HAL_GPIO_Init(HC595_DLK_GPIO_Port, &GPIO_InitStruct);
|
||||
}
|
||||
uint8_t Read_Ds()
|
||||
{
|
||||
ds_in_or_out(0);
|
||||
if(READ_HC595_DCK){return 0;}else{return 1;}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
#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};
|
||||
|
||||
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];
|
||||
Sand_Byte_to_595(h,l);
|
||||
|
||||
Sand_Byte_to_595(~h,~l);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void my_code()
|
||||
{
|
||||
|
||||
dis_buff.d_num[0]=1;
|
||||
dis_buff.d_num[1]=3;
|
||||
dis_buff.d_num[2]=0;
|
||||
dis_buff.d_num[3]=0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
display_and_button_loop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user