83 lines
1.7 KiB
C
83 lines
1.7 KiB
C
#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:发送数据,dir:1:先发高位;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;
|
||
}
|
||
}
|