请教各位大虾,怎样才能提高GPIO的操作速度?
芯片选用的是:STM32F072C8
原来的程序如下:
#define HC595_DATA_HI GPIOB->BSRR |= (1<<HC595_DATA)
#define HC595_DATA_LO GPIOB->BRR |= (1<<HC595_DATA)
#define HC595_CLK_HI GPIOB->BSRR |= (1<<HC595_CLK)
#define HC595_CLK_LO GPIOB->BRR |= (1<<HC595_CLK)
void Handle74HC595(uint8_t tTmp)
{
uint8_t tCnt;
for(tCnt = 0; tCnt<8; tCnt++)
{
if(tTmp&0x01)
{
HC595_DATA_HI;
__nop();
}
else
{
HC595_DATA_LO;
__nop();
}
__nop();
HC595_CLK_LO;
__nop();
HC595_CLK_HI;
tTmp >>= 1;
}
}
以下是我新改的:
void Handle74HC595(register uint8_t tTmp)
{
if(tTmp&0x01)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x02)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x04)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x08)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x10)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x20)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x40)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
if(tTmp&0x80)
{
HC595_DATA_HI; __nop();
}
else
{
HC595_DATA_LO; __nop();
}
HC595_CLK_LO; __nop();
HC595_CLK_HI; __nop();
}
谢谢!
|