一、原理图

PA1、PA2、PA3接SEG、RCK、SCK。
二、CubeMX配置
PA1、PA2、PA3接Output
三、代码
seg.h
#ifndef __SEG_H
#define __SEG_H
#include "main.h"
#define SER_H HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
#define SER_L HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
#define RCK_H HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET);
#define RCK_L HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_RESET);
#define SCK_H HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
#define SCK_L HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
void seg_set(unsigned char seg1,unsigned char seg2,unsigned char seg3);
#endif
seg.c
#include "seg.h"
const unsigned char seg_buff[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0X39,0X77};
void seg_set(unsigned char seg1,unsigned char seg2,unsigned char seg3)
{
unsigned int seg=(seg_buff[seg3]<<16)|(seg_buff[seg2]<<8)|seg_buff[seg1];
for( int i=0;i<24;i++ )
{
if( seg&0x800000 ) {SER_H;}
else SER_L;
SCK_H;
SCK_L
seg<<=1;
}
RCK_H;
RCK_L;
}
应用
seg_set(1,3,9);
526

被折叠的 条评论
为什么被折叠?



