175 lines
2.8 KiB
C
175 lines
2.8 KiB
C
/*
|
|
* my_main.c
|
|
*
|
|
* Created on: 2021年9月17日
|
|
* Author: wuwenfeng
|
|
*/
|
|
#include "my_main.h"
|
|
#include "button.h"
|
|
|
|
#define HC595_DCK(x) HAL_GPIO_WritePin(HC595_DCK_GPIO_Port, HC595_DCK_Pin, x);
|
|
#define HC595_RCK(x) HAL_GPIO_WritePin(HC595_RCK_GPIO_Port, HC595_RCK_Pin, x);
|
|
#define HC595_SCK(x) HAL_GPIO_WritePin(HC595_SCK_GPIO_Port, HC595_SCK_Pin, x);
|
|
|
|
#define MOTA(x) HAL_GPIO_WritePin(MOTA_GPIO_Port, MOTA_Pin, x);
|
|
#define MOTB(x) HAL_GPIO_WritePin(MOTB_GPIO_Port, MOTB_Pin, x);
|
|
|
|
#define KEY1 HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin)
|
|
#define KEY2 HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin)
|
|
#define KEY3 HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin)
|
|
#define KEY4 HAL_GPIO_ReadPin(KEY4_GPIO_Port, KEY4_Pin)
|
|
|
|
struct button key1,key2,key3,key4;
|
|
|
|
const char d_num_data[2][10]=
|
|
{
|
|
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f},
|
|
{0xed,0x48,0xe6,0x6e,0x4b,0x2f,0xaf,0x68,0xef,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 Send_to_595(char h,char l)
|
|
{
|
|
|
|
for(int a=0;a<8;a++)
|
|
{
|
|
if((h<<a)&0x80)
|
|
{
|
|
HC595_DCK(1);
|
|
}else
|
|
{
|
|
HC595_DCK(0);
|
|
}
|
|
HC595_SCK(1);
|
|
HC595_SCK(0);
|
|
}
|
|
|
|
for(int 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 display()
|
|
{
|
|
char h_buff=0,l_buff=0;
|
|
Send_to_595(h_buff,l_buff);
|
|
|
|
h_buff=0,l_buff=0;
|
|
h_buff=~0x01;
|
|
l_buff=d_num_data[0][dis_buff.d_num[0]];
|
|
if(dis_buff.dot1==1)
|
|
{
|
|
l_buff|=0x80;
|
|
}
|
|
Send_to_595(h_buff,l_buff);
|
|
|
|
h_buff=0,l_buff=0;
|
|
h_buff=~0x80;
|
|
l_buff=d_num_data[1][dis_buff.d_num[1]];
|
|
if(dis_buff.dot2==1)
|
|
{
|
|
l_buff|=0x10;
|
|
}
|
|
Send_to_595(h_buff,l_buff);
|
|
|
|
h_buff=0,l_buff=0;
|
|
h_buff=~0x40;
|
|
l_buff=d_num_data[0][dis_buff.d_num[2]];
|
|
if(dis_buff.dot3==1)
|
|
{
|
|
l_buff|=0x80;
|
|
}
|
|
Send_to_595(h_buff,l_buff);
|
|
|
|
h_buff=0,l_buff=0;
|
|
h_buff=0xC1;
|
|
l_buff=d_num_data[1][dis_buff.d_num[3]];
|
|
if(dis_buff.dot4==1)
|
|
{
|
|
l_buff|=0x10;
|
|
}
|
|
if(dis_buff.led_run==1)
|
|
{
|
|
h_buff|=0x10;
|
|
}
|
|
if(dis_buff.led_err==1)
|
|
{
|
|
h_buff|=0x08;
|
|
}
|
|
if(dis_buff.led_n==1)
|
|
{
|
|
h_buff|=0x04;
|
|
}
|
|
if(dis_buff.led_p==1)
|
|
{
|
|
h_buff|=0x02;
|
|
}
|
|
Send_to_595(h_buff,l_buff);
|
|
}
|
|
|
|
void mymain()
|
|
{
|
|
uint32_t runtime=0;
|
|
|
|
MOTA(0);
|
|
MOTB(0);
|
|
HC595_DCK(0);
|
|
HC595_RCK(0);
|
|
HC595_SCK(0);
|
|
|
|
|
|
|
|
while(1)
|
|
{
|
|
if(HAL_GetTick()>runtime)
|
|
{
|
|
runtime+=1000;
|
|
|
|
dis_buff.d_num[0]=rand()%10;
|
|
dis_buff.d_num[1]=rand()%10;
|
|
dis_buff.d_num[2]=rand()%10;
|
|
dis_buff.d_num[3]=rand()%10;
|
|
dis_buff.dot1=rand()%2;
|
|
dis_buff.dot2=rand()%2;
|
|
dis_buff.dot3=rand()%2;
|
|
dis_buff.dot4=rand()%2;
|
|
dis_buff.led_err=rand()%2;
|
|
dis_buff.led_n=rand()%2;
|
|
dis_buff.led_p=rand()%2;
|
|
dis_buff.led_run=rand()%2;
|
|
}
|
|
|
|
GEI_BUTTON_CODE(&key1,KEY1);
|
|
GEI_BUTTON_CODE(&key2,KEY2);
|
|
GEI_BUTTON_CODE(&key3,KEY3);
|
|
GEI_BUTTON_CODE(&key4,KEY4);
|
|
|
|
display();
|
|
}
|
|
|
|
}
|