STM32CubeMX-Keil_uVision5/FinalHomework/Core/Src/HC595.c

83 lines
1.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "main.h"
#include "Hanzi.h"
#define HC595_PORT GPIOC
//GPIO置位拉高
#define OE_SET HC595_PORT->BSRR=HC595_OE_Pin
#define RCLK_SET HC595_PORT->BSRR=HC595_RCLK_Pin
#define SRCLK_SET HC595_PORT->BSRR=HC595_SRCLK_Pin
#define SER_SET HC595_PORT->BSRR=HC595_SER_Pin
//GPIO复位拉低
#define OE_CLR HC595_PORT->BRR=HC595_OE_Pin
#define RCLK_CLR HC595_PORT->BRR=HC595_RCLK_Pin
#define SRCLK_CLR HC595_PORT->BRR=HC595_SRCLK_Pin
#define SER_CLR HC595_PORT->BRR=HC595_SER_Pin
#define LATCH595 {RCLK_CLR;RCLK_SET;RCLK_CLR;}
extern uint8_t mPos;
extern uint8_t mNum;
void SendOneByte(uint8_t dat)
{
uint8_t i;
OE_CLR;
for(i=0;i<8;i++)
{
if((dat&0x80))
SER_SET;
else
SER_CLR;
dat <<= 1;
SRCLK_CLR;//SRCLK=0;
SRCLK_SET;// SRCLK=1;
}
}
/*******************************************************
SendTwoBytes(uint16_t dat,bit dir)
函数功能向HC595芯片发送两个字节
入口参数dat发送数据dir1:先发高位;0:先发低位
返回参数:无
********************************************************/
void SendTwoBytes(uint16_t dat)
{
uint8_t i;
OE_CLR;
for(i=0;i<16;i++)
{
if((dat &0x8000))
SER_SET;
else
SER_CLR;
dat <<= 1;
SRCLK_CLR;//SRCLK=0;
SRCLK_SET;// SRCLK=1;
}
}
/*******************************************************
//函数名称HanziDiplay()
//函数功能:静态显示一个汉字
//入口参数:无
//返回参数:无
********************************************************/
void HanziDiplay(void)
{
uint16_t temp;
SendTwoBytes(ScanTab[mPos]);
temp=HanziTab[2*mPos+1+32*mNum];
temp=(temp<<8)|HanziTab[2*mPos+32*mNum];
SendTwoBytes(temp);
LATCH595;
if(++mPos>=16)
{
mPos=0;
}
}