本帖最后由 dingsujie 于 2013-9-22 12:05 编辑
/***************************** SPI初始化 ************************************/
void SPI_74HC595_Init(void)
{ GPIO_Init(GPIOE, SPI_CS, GPIO_MODE_OUT_PP_HIGH_FAST);
SPI_DeInit();
SPI_74HC595_CS_HIGH();//不使能从设备
SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_32,SPI_MODE_MASTER,\
SPI_CLOCKPOLARITY_HIGH,SPI_CLOCKPHASE_2EDGE,\
SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x07);
SPI_Cmd(ENABLE);/* 使能SPI */
}
/***************************** SPI_74HC595_SendByte ************************************/
void SPI_74HC595_SendByte(uchar HC595Data1)
{
SPI_74HC595_CS_LOW();
/* Loop while DR register in not emplty */
while (SPI_GetFlagStatus( SPI_FLAG_TXE) == RESET);
/* Send byte through the SPI1 peripheral */
SPI_SendData(HC595Data1);
SPI_74HC595_CS_HIGH();
}
/********************************* 显示函数 *****************************************************/
void Display(void)
{ uchar i=0;
GPIO_Write(GPIOB, 0xFF);
for(i=0;i<3;i++)
{
SPI_74HC595_SendByte(Disbuff);
delay_d(12);
}
}
/********************************* 数字更新显示函数 *****************************************************/
void RefreshDisbuff(void)
{
uint i=0,j=0,temp=0;
for(i=0;i<5;i++)
{
Disbuff[1]=NUM[1*5+i];
// Disbuff[1]=0xff;
//Disbuff[2]=0x00;
Disbuff[0]=NUM[0*5+i];
Disbuff[2]=NUM[1*5+i];
Display();
switch(i)
{
case 0:GPIO_Write(GPIOB, 0xFD);break;
case 1:GPIO_Write(GPIOB, 0xFB);break;
case 2:GPIO_Write(GPIOB, 0xF7);break;
case 3:GPIO_Write(GPIOB, 0xEF);break;
case 4:GPIO_Write(GPIOB, 0xDF);break;
default:{;}
}
delay_d(500);
}
file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/1072989515/QQ/WinTemp/RichOle/%25(Z73Z4O%25N%7D3]6P(9XQ56%7B7.jpg
STM8采用SPI模式驱动74HC595出现乱码,具体情况为显示错位,请大侠帮忙分析 |