
四张图片及生成的bin文件图片格式

描述:
将图片保存为 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);
- }