之前也显示过gif,但是因为mcu空间不够,gif显示不全,有点遗憾。
AT-START-WB415开发板,MCU有256K flash,正好够我显示gif。
首先将gif分割为179张图片,每幅bmp像素80x80,总时间为5500毫秒,彩色屏显示(黑,白)为(0,0xffff)二值模式。
即一个像素一个int型,一张bmp需要6400*2=12800byte,179张bmp=12800*179=2.2Mbytes,所以单片机空间是远远不够的。
节省空间的办法,可以用先用(0,0xff)保存黑白两色,显示时通过软件处理,一张图只要6400bytes,则179张图需要1.1Mbyte字节。
以此类推,用0表示黑色像素,用1保存白色像素,(0,1)二进制模式,软件处理,将8个像素组合为1字节存储再单片机内,一张图只要800bytes,
最后179张需要140Kbytes。
每幅图显示时间为30ms,一个周期5500ms,正好一个循环完成
- int main(void)
- {
- uint32_t num = 0;
-
- system_clock_config();
- at32_board_init();
- gpio_config();
- spi_config();
- LCD_Init();
- PrintfClockInfo("clock acquisition, wait a minute...");
-
- while(1)
- {
- //delay_ms(1000);
- //at32_led_toggle(LED3);
- //printf("we are family !\r\n");
-
- at32_led_toggle(LED3);
- LCD_DrawPic_ZZZ(num,0,0,bit80x80);
- delay_ms(30);
-
- if(++num >= 179)
- {
- num =0;
- }
-
- }
- }
使用官方自带的串口需要注意的是,需要 取消勾选 C99 Mode 和 GNU extensions 两项,否则会出错。
软件处理像素
- #define BIT(x) ((unsigned int)((unsigned int)1<<x))
- /*----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- //画图
- void LCD_DrawPic_ZZZ(u8 index, u16 x, u16 y,const unsigned char *p)
- {
- u8 n;
- u32 i;
- u16 picX;
- u16 temp;
-
- LCD_SetWindows(x,y,x+80-1,y+80-1);
- i = index*800; //bmp1 = 800 bytes
- for(; i<800+index*800; i++)
- {
- picX = *(p+i);
- for(n=0,temp=0; n<8; n++)
- {
- temp = (picX & BIT((7-n))) >> (7-n);
- if(temp>0) temp=0xffff;
- Lcd_WriteData_16Bit(temp);
- }
- }
- }
图片太大,就不上传了。
最后附上代码
AT-START-WB415-Demo-v1.1.zip
(93.4 KB, 下载次数: 16)
|