Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4390527
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

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 位。

  1. /*在lcd显示上, 本来是 -------------->y方向
  2.                      |
  3.                      |
  4.                      |
  5.                      |
  6.                      |
  7.                      |
  8.                      |
  9.                      x方向
  10. 那么y方向应该是 128像素点, x方向是160像素点
  11. 但是在 LCD_PutString LCD_show_number 这些函数中, 已经事项
  12. 将 x y 方向转换了,------------------>x 转换后的
  13.                  |
  14.                  |
  15.                  |
  16.                  |    
  17.                  转换后的y方向
  18. 在 显示bin图片过程中,是没有经过 转换的, x方向是 向下的, y方向是水平的
  19. x = 160 y = 128

  20. */
  21. void LCD_show_picture_2(u8 *pic)//显示lcd 2行像素点
  22. {
  23.     //int i,j,k;
  24.     int j = 0, k = 0;
  25.     unsigned char picH,picL;
  26.  
  27. //    k=0;
  28. //    for(i = x; i < x 2; i )/
  29.     //{
  30.         for(j=0;j<160;j ) //显示一行 x 像素点
  31.         {
  32.             picH=pic[k];//读取像素点的 高位 颜色
  33.             k ;
  34.             picL=pic[k];//读取像素点的 低位 颜色
  35.             k ;
  36.             LCD_DataWrite(picH,picL);
  37.         }
  38. //    }
  39.         
  40. }

  41. void sd_show_picture_bin_1(void)//LCD显示SD中 bin 图片
  42. {
  43.     UINT br;
  44.     u16 i;
  45.     u8 data[320]; //存储一行像素点160 的 16进制颜色信息 160*2=320

  46.     res = f_mount(0, &fs);//打开文件,不存在则创建,可读 可写
  47.     res = f_open(&file, "1.bin", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
  48.     
  49.     for(i = 0; i < 128; i )//y方向是 128行
  50.     {
  51.         res = f_read(&file,data,320,&br);//x方向160个像素点,每个像素点 2 个
  52.         LCD_show_picture_2(data);//显示 1 行像素点
  53.     //    f_lseek(&file2,0); // /* Move Pointer to the top of the file */
  54.       //    f_lseek(&file2,512);//Index为要显示的文字的点阵数组 处于SD卡字库中的起始位置。
  55.     }         
  56.     f_close(&file);    
  57. }




  1. /*
  2. *    Author :     余威先
  3. *    Date:         2011.6.19    
  4. * 开发板上:PD2 ~ LED2
  5. * PA8 ~ LED0
  6. * PA15 ~ KEY1
  7. * PA13 ~ KEY2
  8. * 修改Date: 2011.6.30 19:20
  9. * rcc时钟配置: SYSCLK = 16MHZ
  10. * AHB = 16MHZ
  11. *              APB1 = 8 MHZ // TIM2 TIM3 TIM4
  12. *                 APB2 = 16 MHZ //GPIO A B C D
  13. * 修改Date:2011.7.3 21:00
  14.     简单描述:
  15.      2011.7.3 21:00 移植 fatfs 成功 ff8b
  16.             2011.7.4 8:48 读取SD中 yu.txt中数据,LCD显示读到的数据
  17.             2011.7.4 13:14 读取SD中 图片bin数据 显示在LCD上 循环显示 4张图片
  18.     
  19. */
  20. #include "stm32f10x.h"
  21. #include "rcc.h"
  22. #include "systick.h"
  23. #include "led.h"
  24. #include "delay.h"
  25. //#include "key.h"
  26. #include "tim3.h"
  27. #include "usart1.h"
  28. #include "lcd.h"
  29. #include "rtc.h"
  30. #include "flash.h"
  31. #include "sd_spi.h"
  32. #include "..\FATS\ff.h"
  33. #include "..\FATS\integer.h"
  34. #include "..\FATS\ffconf.h"
  35. #include "..\FATS\diskio.h"
  36. //#include "picture.h"

  37. volatile u8 sec = 0; // 全局变量 秒 时 小时
  38. volatile u8 min = 0;
  39. volatile u8 hour = 0;

  40. FATFS fs;
  41. FRESULT res;
  42. FIL file;

  43. u8 send_buffer[512] = {97,6};
  44. u8 receiv_buffer[512] = {0,0};
  45. u32 capacity = 0;
  46. void write_file(void);
  47. void sd_show_picture_bin_1(void); //显示SD中 1.bin 图片
  48. void sd_show_picture_bin_2(void); //显示SD中 2.bin 图片
  49. void sd_show_picture_bin_3(void);
  50. void sd_show_picture_bin_4(void);
  51. void LCD_show_picture_2(u8 *pic); //显示LCD一行像素点 160个点

  52. int main(void)
  53. {    
  54. //    u16 i = 0;//

  55.     RCC_Configuration(); //系统时钟配置
  56.     delay_init();     // 延时 初始化

  57. //    RTC_Configuration(); //RTC系统 配置
  58. //    RTC_NVIC_Configuration(); //RTC中断配置
  59. //    RTC_Init();// RTC 时钟初始化

  60.     SPI1_Configuration(); //SPI1 初始化
  61. //    SD_Init();             //SD卡 初始化

  62.     LCD_Init();         //LCD 彩屏初始化

  63.     write_cmd(0x2C); //LCD 写数据命令
  64.     DrawFull_single_colour(0xff, 0xff);    //显示 纯白色
  65. //    LCD_show_picture(Image_pic);//显示 flash中图片
  66.     
  67.     while(1) //循环显示 4 张 bin图片
  68.     {
  69.         sd_show_picture_bin_1();
  70.         delay_s(2);
  71.         sd_show_picture_bin_2();
  72.         delay_s(2);
  73.         sd_show_picture_bin_3();
  74.         delay_s(2);
  75.         sd_show_picture_bin_4();
  76.         delay_s(2);
  77.     }

  78. //    capacity = SD_GetCapacity();    //获取 容量
  79. //    LCD_show_number(48,128,capacity); //打印低16位
  80. //    LCD_show_number(0,128,capacity>>16); //打印高16位

  81. //    LCD_PutString(0,0, "start to write file..");
  82. //    write_file();
  83. #if 0
  84.     for(i = 0; i < 256; i ) //发送数据填充
  85.         send_buffer[i] = i;    
  86.     
  87.     for(i = 0; i < 256; i ) //发送数据填充
  88.         send_buffer[i 256] = i;    

  89.     SD_WriteSingleBlock(0, send_buffer); //写数据到 块 中
  90.     SD_ReadSingleBlock(0, receiv_buffer); //从 块 中 读数据

  91.     for(i = 0; i < 512; i ) // 显示从块中读取到的数据, 一个字节最大255
  92.     {
  93.         LCD_show_number(8,32,receiv_buffer[i]);
  94.         delay_s(1);
  95.     }
  96. #endif

  97.     while(1) //无限循环, 中断中 显示 秒时钟
  98.     {
  99.         #if 0
  100.         LCD_show_number_2(40,16,hour);
  101.         LCD_show_number_2(64,16,min);
  102.         LCD_show_number_2(88,16,sec);    
  103.         #endif
  104.     }
  105. //    return 0;
  106. }

  107. /*在lcd显示上, 本来是 -------------->y方向
  108.                      |
  109.                      |
  110.                      |
  111.                      |
  112.                      |
  113.                      |
  114.                      |
  115.                      x方向
  116. 那么y方向应该是 128像素点, x方向是160像素点
  117. 但是在 LCD_PutString LCD_show_number 这些函数中, 已经事项
  118. 将 x y 方向转换了,------------------>x 转换后的
  119.                  |
  120.                  |
  121.                  |
  122.                  |    
  123.                  转换后的y方向
  124. 在 显示bin图片过程中,是没有经过 转换的, x方向是 向下的, y方向是水平的
  125. x = 160 y = 128

  126. */
  127. void LCD_show_picture_2(u8 *pic)//显示lcd 2行像素点
  128. {
  129.     //int i,j,k;
  130.     int j = 0, k = 0;
  131.     unsigned char picH,picL;
  132.  
  133. //    k=0;
  134. //    for(i = x; i < x 2; i )/
  135.     //{
  136.         for(j=0;j<160;j ) //显示一行 x 像素点
  137.         {
  138.             picH=pic[k];//读取像素点的 高位 颜色
  139.             k ;
  140.             picL=pic[k];//读取像素点的 低位 颜色
  141.             k ;
  142.             LCD_DataWrite(picH,picL);
  143.         }
  144. //    }
  145.         
  146. }

  147. void sd_show_picture_bin_1(void)//LCD显示SD中 bin 图片
  148. {
  149.     UINT br;
  150.     u16 i;
  151.     u8 data[320]; //存储一行像素点160 的 16进制颜色信息 160*2=320

  152.     res = f_mount(0, &fs);//打开文件,不存在则创建,可读 可写
  153.     res = f_open(&file, "1.bin", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
  154.     
  155.     for(i = 0; i < 128; i )//y方向是 128行
  156.     {
  157.         res = f_read(&file,data,320,&br);//x方向160个像素点,每个像素点 2 个
  158.         LCD_show_picture_2(data);//显示 1 行像素点
  159.     //    f_lseek(&file2,0); // /* Move Pointer to the top of the file */
  160.       //    f_lseek(&file2,512);//Index为要显示的文字的点阵数组 处于SD卡字库中的起始位置。
  161.     }         
  162.     f_close(&file);    
  163. }
  产生 bin 图片文件 









          
阅读(4503) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~