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

83 lines
1.7 KiB
C
Raw Permalink Normal View History

2025-01-07 14:57:25 +08:00
#include "main.h"
#include "Hanzi.h"
#define HC595_PORT GPIOC
//GPIO<49><4F>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>
#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<49><4F>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>
#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)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>HC595оƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dat<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>dir<EFBFBD><EFBFBD>1:<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>λ;0:<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>λ
<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
********************************************************/
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;
}
}
/*******************************************************
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>HanziDiplay()
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>̬<EFBFBD><CCAC>ʾһ<CABE><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
********************************************************/
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;
}
}