标题: PIC18读取SD卡示例PIC18 SD BMP Reader源码 [打印本页]

作者: chengfgc    时间: 2017-12-19 10:32
标题: PIC18读取SD卡示例PIC18 SD BMP Reader源码
很久之前学习PIC的时候找的资料,对读写SD卡很有帮助!!!

实物图:


仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. /***************************************************

  2. PIC18F SD/MMC Bitmap File Reader
  3. May 2010

  4. *****************************************************/
  5. #include <htc.h>
  6. #include <string.h>

  7. #define _XTAL_FREQ 48000000

  8. #pragma config FOSC     = HSPLL_HS
  9. #pragma config PLLDIV   = 5                                // (20 MHz crystal on PICDEM FS USB board)
  10. #pragma config CPUDIV   = OSC1_PLL2                // Clock source from 96MHz PLL/2

  11. #pragma config PWRT = ON
  12. #pragma config BOR = ON
  13. #pragma config BORV = 2
  14. #pragma config WDT = OFF
  15. #pragma config DEBUG = ON
  16. #pragma config LVP = OFF

  17. #define TRUE 1
  18. #define FALSE 0
  19. #include "pff.h"
  20. #include "lcd3310.h"
  21. #include "lcd_bmp.h"

  22. FATFS Fs;                        /* File system object */
  23. DIR Dir;                        /* Directory object */
  24. FILINFO Fno;                /* File information */

  25. void delay(void);

  26. void main(void)
  27. {
  28.         BYTE res, i;

  29.         while(1){
  30.                 delay();
  31.                 lcd_init();
  32.                 lcd_clear();
  33.                 lcd_text(0,1, "PIC BMP Reader");
  34.                 lcd_text(0,3, "insert SDcard!");
  35.                 if (pf_mount(&Fs) ) continue;        /* Initialize FS */
  36.                 lcd_text(0,3, " initialized ");
  37.                 delay();
  38.                 delay();
  39.                 while(1){
  40.                         if (pf_opendir(&Dir, "")) break;                                // open root directory
  41.                         while (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) {
  42.                                 if( strstr(Fno.fname, ".BMP") ){                        // BMP file
  43.                                         if(pf_open(Fno.fname)) continue;                // open file
  44.                                         draw_bitmap(Fno.fname);

  45.                                         delay();
  46.                                         delay();
  47.                                         delay();
  48.                                 }

  49.                                
  50.                         }
  51. ……………………

  52. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
PIC18-SD-BMP-Reader.rar (1.03 MB, 下载次数: 48)







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1