回复【12楼】潜龙探渊:
---------------------------------
由于DMX512播放文件有30M那么大,所以无法缓存那么大的数据,我是采用先读取SD卡BIN中的数据,每次读512一个,然后通过DMX_SendPacket();这样一直循环发送,可这样会有个读取数据的延时,导致LED闪烁,请问如何解决此问题???
void DMX512_Play_bin(unsigned char *pic_name)
{
int i, j;
unsigned char tmp_name[20];
// WORD data;
BYTE * pdata = pColorData;
BYTE * tmp_pdata;
unsigned int read_num;
sprintf((char*)tmp_name,"0:%s",pic_name);
f_mount(0, &bmpfs[0]);
bmpres = f_open( &bmpfsrc , (char *)tmp_name, FA_OPEN_EXISTING | FA_READ);
if(bmpres == FR_OK)
{
// printf("Open file success\r\n");
}
else
{
// printf("file open fail!\r\n");
return;
}
for(j=0;j<300;j++) //300表示一幅图片含有300x512字节的信息
{
tmp_pdata = NULL;
f_lseek (&bmpfsrc,(512*j));
f_read(&bmpfsrc,pdata,512,&read_num);
tmp_pdata = pdata;
for(i=1;i<512;i++)
{
DMX_buf = LD_WORD(tmp_pdata);
}
DMX_SendPacket();
}
f_close(&bmpfsrc);
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
void DMX_SendPacket(void)
{
u16 pDMX_buf=0;
//配置为普通IO
GPIO_Tx_Normal_Config(); //设置发送的引脚为普通IO
GPIO_ResetBits(GPIOA,GPIO_Pin_2); //输出低电平
delay_us(150); //延时150us
GPIO_SetBits(GPIOA,GPIO_Pin_2); //输出高电平
delay_us(13); //延时13us
GPIO_Tx_Usart_Config(); //设置发送的引脚为串口
USART2->DR = 0x0100 | 0x00; //第0帧前导码,发送起始码
while((USART2->SR&0X40)==0); //循环发送,直到发送完毕
while(pDMX_buf < 512) //1-512
{
while((USART2->SR&0X40)==0); //循环发送,直到发送完毕
if(USART2->SR & (1<<6))
{
USART2->DR = 0x0100 | DMX_buf[pDMX_buf];
pDMX_buf++;
}
}
}
int main(void)
{
NVIC_Configuration();
// ili9320_Initializtion();
RCC_Configuration();
GPIO_ConfigurationA();
DMX_init();
while(1)
{
DMX512_Play_bin("/DMX512.bin");
// DMX_SendPacket();
}
}
|