很久之前学习PIC的时候找的资料,对读写SD卡很有帮助!!!
实物图:
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- /***************************************************
- PIC18F SD/MMC Bitmap File Reader
- May 2010
- *****************************************************/
- #include <htc.h>
- #include <string.h>
- #define _XTAL_FREQ 48000000
- #pragma config FOSC = HSPLL_HS
- #pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board)
- #pragma config CPUDIV = OSC1_PLL2 // Clock source from 96MHz PLL/2
- #pragma config PWRT = ON
- #pragma config BOR = ON
- #pragma config BORV = 2
- #pragma config WDT = OFF
- #pragma config DEBUG = ON
- #pragma config LVP = OFF
- #define TRUE 1
- #define FALSE 0
- #include "pff.h"
- #include "lcd3310.h"
- #include "lcd_bmp.h"
- FATFS Fs; /* File system object */
- DIR Dir; /* Directory object */
- FILINFO Fno; /* File information */
- void delay(void);
- void main(void)
- {
- BYTE res, i;
- while(1){
- delay();
- lcd_init();
- lcd_clear();
- lcd_text(0,1, "PIC BMP Reader");
- lcd_text(0,3, "insert SDcard!");
- if (pf_mount(&Fs) ) continue; /* Initialize FS */
- lcd_text(0,3, " initialized ");
- delay();
- delay();
- while(1){
- if (pf_opendir(&Dir, "")) break; // open root directory
- while (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) {
- if( strstr(Fno.fname, ".BMP") ){ // BMP file
- if(pf_open(Fno.fname)) continue; // open file
- draw_bitmap(Fno.fname);
- delay();
- delay();
- delay();
- }
-
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
PIC18-SD-BMP-Reader.rar
(1.03 MB, 下载次数: 48)
|