分类: 嵌入式
2011-07-04 17:07:44
工程代码: 6_从SD中读取BIN图片显示LCD上.rar
四张图片及生成的bin文件图片格式 bin文件.rar
描述:
将图片保存为 bin格式,然后在stm32中读取 bin文件,
最后显示bin文件在 LCD上。128*160 图片 生成的 bin文件挺大的,但是STM32RB的内存大小只有20K,所以不能一次定义 数组空间,将一个bin文件都读取到 数组中,我们可以这么实现:定义一行 像素点数组 u8 data[320] 为什么是320大小呢, 一个像素点是16位真彩色, 所以生成的16进制 有4位, 所以说,一个像素点包含了数组中的 2 位。
产生 bin 图片文件
四张图片及生成的bin文件图片格式 bin文件.rar
描述:
将图片保存为 bin格式,然后在stm32中读取 bin文件,
最后显示bin文件在 LCD上。128*160 图片 生成的 bin文件挺大的,但是STM32RB的内存大小只有20K,所以不能一次定义 数组空间,将一个bin文件都读取到 数组中,我们可以这么实现:定义一行 像素点数组 u8 data[320] 为什么是320大小呢, 一个像素点是16位真彩色, 所以生成的16进制 有4位, 所以说,一个像素点包含了数组中的 2 位。
- /*在lcd显示上, 本来是 -------------->y方向
- |
- |
- |
- |
- |
- |
- |
- x方向
- 那么y方向应该是 128像素点, x方向是160像素点
- 但是在 LCD_PutString LCD_show_number 这些函数中, 已经事项
- 将 x y 方向转换了,------------------>x 转换后的
- |
- |
- |
- |
- 转换后的y方向
- 在 显示bin图片过程中,是没有经过 转换的, x方向是 向下的, y方向是水平的
- x = 160 y = 128
- */
- void LCD_show_picture_2(u8 *pic)//显示lcd 2行像素点
- {
- //int i,j,k;
- int j = 0, k = 0;
- unsigned char picH,picL;
- // k=0;
- // for(i = x; i < x 2; i )/
- //{
- for(j=0;j<160;j ) //显示一行 x 像素点
- {
- picH=pic[k];//读取像素点的 高位 颜色
- k ;
- picL=pic[k];//读取像素点的 低位 颜色
- k ;
- LCD_DataWrite(picH,picL);
- }
- // }
- }
- void sd_show_picture_bin_1(void)//LCD显示SD中 bin 图片
- {
- UINT br;
- u16 i;
- u8 data[320]; //存储一行像素点160 的 16进制颜色信息 160*2=320
- res = f_mount(0, &fs);//打开文件,不存在则创建,可读 可写
- res = f_open(&file, "1.bin", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
- for(i = 0; i < 128; i )//y方向是 128行
- {
- res = f_read(&file,data,320,&br);//x方向160个像素点,每个像素点 2 个
- LCD_show_picture_2(data);//显示 1 行像素点
- // f_lseek(&file2,0); // /* Move Pointer to the top of the file */
- // f_lseek(&file2,512);//Index为要显示的文字的点阵数组 处于SD卡字库中的起始位置。
- }
- f_close(&file);
- }
- /*
- * Author : 余威先
- * Date: 2011.6.19
- * 开发板上:PD2 ~ LED2
- * PA8 ~ LED0
- * PA15 ~ KEY1
- * PA13 ~ KEY2
- * 修改Date: 2011.6.30 19:20
- * rcc时钟配置: SYSCLK = 16MHZ
- * AHB = 16MHZ
- * APB1 = 8 MHZ // TIM2 TIM3 TIM4
- * APB2 = 16 MHZ //GPIO A B C D
- * 修改Date:2011.7.3 21:00
- 简单描述:
- 2011.7.3 21:00 移植 fatfs 成功 ff8b
- 2011.7.4 8:48 读取SD中 yu.txt中数据,LCD显示读到的数据
- 2011.7.4 13:14 读取SD中 图片bin数据 显示在LCD上 循环显示 4张图片
- */
- #include "stm32f10x.h"
- #include "rcc.h"
- #include "systick.h"
- #include "led.h"
- #include "delay.h"
- //#include "key.h"
- #include "tim3.h"
- #include "usart1.h"
- #include "lcd.h"
- #include "rtc.h"
- #include "flash.h"
- #include "sd_spi.h"
- #include "..\FATS\ff.h"
- #include "..\FATS\integer.h"
- #include "..\FATS\ffconf.h"
- #include "..\FATS\diskio.h"
- //#include "picture.h"
- volatile u8 sec = 0; // 全局变量 秒 时 小时
- volatile u8 min = 0;
- volatile u8 hour = 0;
- FATFS fs;
- FRESULT res;
- FIL file;
- u8 send_buffer[512] = {97,6};
- u8 receiv_buffer[512] = {0,0};
- u32 capacity = 0;
- void write_file(void);
- void sd_show_picture_bin_1(void); //显示SD中 1.bin 图片
- void sd_show_picture_bin_2(void); //显示SD中 2.bin 图片
- void sd_show_picture_bin_3(void);
- void sd_show_picture_bin_4(void);
- void LCD_show_picture_2(u8 *pic); //显示LCD一行像素点 160个点
- int main(void)
- {
- // u16 i = 0;//
- RCC_Configuration(); //系统时钟配置
- delay_init(); // 延时 初始化
- // RTC_Configuration(); //RTC系统 配置
- // RTC_NVIC_Configuration(); //RTC中断配置
- // RTC_Init();// RTC 时钟初始化
- SPI1_Configuration(); //SPI1 初始化
- // SD_Init(); //SD卡 初始化
- LCD_Init(); //LCD 彩屏初始化
- write_cmd(0x2C); //LCD 写数据命令
- DrawFull_single_colour(0xff, 0xff); //显示 纯白色
- // LCD_show_picture(Image_pic);//显示 flash中图片
- while(1) //循环显示 4 张 bin图片
- {
- sd_show_picture_bin_1();
- delay_s(2);
- sd_show_picture_bin_2();
- delay_s(2);
- sd_show_picture_bin_3();
- delay_s(2);
- sd_show_picture_bin_4();
- delay_s(2);
- }
- // capacity = SD_GetCapacity(); //获取 容量
- // LCD_show_number(48,128,capacity); //打印低16位
- // LCD_show_number(0,128,capacity>>16); //打印高16位
- // LCD_PutString(0,0, "start to write file..");
- // write_file();
- #if 0
- for(i = 0; i < 256; i ) //发送数据填充
- send_buffer[i] = i;
- for(i = 0; i < 256; i ) //发送数据填充
- send_buffer[i 256] = i;
- SD_WriteSingleBlock(0, send_buffer); //写数据到 块 中
- SD_ReadSingleBlock(0, receiv_buffer); //从 块 中 读数据
- for(i = 0; i < 512; i ) // 显示从块中读取到的数据, 一个字节最大255
- {
- LCD_show_number(8,32,receiv_buffer[i]);
- delay_s(1);
- }
- #endif
- while(1) //无限循环, 中断中 显示 秒时钟
- {
- #if 0
- LCD_show_number_2(40,16,hour);
- LCD_show_number_2(64,16,min);
- LCD_show_number_2(88,16,sec);
- #endif
- }
- // return 0;
- }
- /*在lcd显示上, 本来是 -------------->y方向
- |
- |
- |
- |
- |
- |
- |
- x方向
- 那么y方向应该是 128像素点, x方向是160像素点
- 但是在 LCD_PutString LCD_show_number 这些函数中, 已经事项
- 将 x y 方向转换了,------------------>x 转换后的
- |
- |
- |
- |
- 转换后的y方向
- 在 显示bin图片过程中,是没有经过 转换的, x方向是 向下的, y方向是水平的
- x = 160 y = 128
- */
- void LCD_show_picture_2(u8 *pic)//显示lcd 2行像素点
- {
- //int i,j,k;
- int j = 0, k = 0;
- unsigned char picH,picL;
- // k=0;
- // for(i = x; i < x 2; i )/
- //{
- for(j=0;j<160;j ) //显示一行 x 像素点
- {
- picH=pic[k];//读取像素点的 高位 颜色
- k ;
- picL=pic[k];//读取像素点的 低位 颜色
- k ;
- LCD_DataWrite(picH,picL);
- }
- // }
- }
- void sd_show_picture_bin_1(void)//LCD显示SD中 bin 图片
- {
- UINT br;
- u16 i;
- u8 data[320]; //存储一行像素点160 的 16进制颜色信息 160*2=320
- res = f_mount(0, &fs);//打开文件,不存在则创建,可读 可写
- res = f_open(&file, "1.bin", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
- for(i = 0; i < 128; i )//y方向是 128行
- {
- res = f_read(&file,data,320,&br);//x方向160个像素点,每个像素点 2 个
- LCD_show_picture_2(data);//显示 1 行像素点
- // f_lseek(&file2,0); // /* Move Pointer to the top of the file */
- // f_lseek(&file2,512);//Index为要显示的文字的点阵数组 处于SD卡字库中的起始位置。
- }
- f_close(&file);
- }
为了实现从SD中读取图片数据,并且显示在LCD上。 这里首先实现了
直接读取图片数据,显示LCD上。
图片16进制文件大小都 203KB了,生成的 hex文件 124KB
,flash大小总共才128KB
主要代码实现:
直接读取图片数据,显示LCD上。
图片16进制文件大小都 203KB了,生成的 hex文件 124KB
,flash大小总共才128KB
主要代码实现:
- void LCD_show_picture(const u8 *pic)
- {
- int i,j,k;
- unsigned char picH,picL;
- k=0;
- for(i=0;i<128;i++)
- {
- for(j=0;j<160;j++)
- {
- picH=pic[k];
- k++;
- picL=pic[k];
- k++;
- LCD_DataWrite(picH,picL);
- }
- }
- }
- #ifndef __PICTURE_H
- #define __PICTURE_H
- #include "stm32f10x.h"
- //SPI 彩屏图片数组
- extern const u8 Image_pic[];
- #endif
- #include "picture.h"
- const u8 Image_pic[]=
- {
- 0x42,0x04,0x52,0xA7,0x4A,0x86,0x3A,0x44,0x32,0x82,0x53,0x64,0x4B,0x43,0x3A,0xA3,0x2A,0x22,0x4B,0x04,0x42,0xE2,0x5B,0xC5,0x5B,0xA4,0x3A,0xA2,0x32,0x41,0x32,0x82,
- 0x4B,0x65,0x2A,0x41,0x42,0xC3,0x4B,0x23,0x53,0x64,0x53,0x65,0x42,0xA3,0x3A,0x62,0x4B,0x05,0x6C,0x29,0x64,0x08,0x4B,0x24,0x32,0xA2,0x64,0x28,0x6C,0x28,0x4A,0xE4,
- 0x53,0x06,0x3A,0x25,0x31,0xC2,0x4A,0xC4,0x73,0xE7,0x7C,0x28,0x73,0xC7,0x63,0x46,0x6B,0x88,0x5B,0x25,0x5B,0x66,0x52,0xE5,0x52,0xA5,0x5A,0xE6,0x42,0x02,0x6B,0x68,
- 0xA5,0x0E,0x94,0x6C,0x63,0x06,0x7B,0x6A,0x20,0x60,0x7B,0x49,0x72,0xE7,0x39,0x62,0x6B,0x47,0x4A,0x85,0x6B,0x66,0x42,0x02,0x63,0x86,0x5B,0x84,0x53,0x43,0x6C,0x26,
- 0x6