论坛元老
 
- 积分
- 4478
- 金钱
- 4478
- 注册时间
- 2018-5-14
- 在线时间
- 959 小时
|
发表于 2021-3-17 11:17:42
|
显示全部楼层
- #include "stm32f0xx.h"
- typedef union{
- uint8_t Bytes;
- struct{
- uint8_t Bit0:1;
- uint8_t Bit1:1;
- uint8_t Bit2:1;
- uint8_t Bit3:1;
- uint8_t Bit4:1;
- uint8_t Bit5:1;
- uint8_t Bit6:1;
- uint8_t Bit7:1;
- };
- }HC595_DataBytes_Typedef;
- void HC595_IO_Init(void);
- void HC595_WriteByte(HC595_DataBytes_Typedef *HC595_Data);
- #include "HC595.h"
- void HC595_IO_Init(void)
- {
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB,ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_15;
- GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- }
- void HC595_SCK_Set(void)
- {
- GPIO_SetBits(GPIOA,GPIO_Pin_15);
- }
- void HC595_SCK_Reset(void)
- {
- GPIO_ResetBits(GPIOA,GPIO_Pin_15);
- }
- void HC595_RCK_Set(void)
- {
- GPIO_SetBits(GPIOA,GPIO_Pin_12);
- }
- void HC595_RCK_Reset(void)
- {
- GPIO_ResetBits(GPIOA,GPIO_Pin_12);
- }
- void HC595_SER_Set(void)
- {
- GPIO_SetBits(GPIOB,GPIO_Pin_11);
- }
- void HC595_SER_Reset(void)
- {
- GPIO_ResetBits(GPIOB,GPIO_Pin_11);
- }
- void HC595_WriteByte(HC595_DataBytes_Typedef *HC595_Data)
- {
- uint8_t IO_Set;
- IO_Set=HC595_Data->Bytes;
- int8_t i=8;
- for(i=7;i>=0;i--)
- {
- HC595_SCK_Reset();
- if(((IO_Set>>i)&0x01)==1)
- {
- HC595_SER_Set();
- }
- else
- {
- HC595_SER_Reset();
- }
- HC595_SCK_Set();
- }
- HC595_RCK_Reset();
- HC595_RCK_Set();
- }
复制代码 |
|