大循环中 动态扫描4位数码管,每隔 0.5 s 向左移动一个字符。 实现滚动显示 "HELLO. **"
unsigned char led_table[] =
{ 0x89, 0x86, 0xc7, 0xc7, 0x40, 0xFF, 0xFF, 0x86, 0xc7, 0x86, 0xc6, 0x8E, 0x88, 0xc8, 0x92, 0xFF, 0xFF, 0xFF };
int main( void )
{
unsigned char LedValueIndex = 0;
unsigned char LedDig = 0;
unsigned int Times = 0;
unsigned char tx_buffer[2];
struct spi_ioc_transfer tx[] =
{
{
.tx_buf = ( unsigned long ) tx_buffer,
.rx_buf = 0,
.len = 2,
.delay_usecs = 0,
.speed_hz = 10000,
.bits_per_word = 8,
},
};
if( SPI1_Init() == -1 )
{
return 0;
}
while( 1 )
{
tx_buffer[0] = led_table[LedValueIndex + LedDig];
tx_buffer[1] = 1 << LedDig;
ioctl( spi_fd, SPI_IOC_MESSAGE(1), & tx );
write( RCK_fd, "0", 1 );
usleep( 100 );
write( RCK_fd, "1", 1 );
usleep( 1000 );
if( ++LedDig > 3 )
LedDig = 0;
if( ++Times > 500 )
{
Times = 0;
if( ++LedValueIndex > 14 )
LedValueIndex = 0;
}
}
return 0;
}
|