sd卡读写程序(SDcardreadandwriteprogram)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

sd 卡读写程序( SD card read and write program )

SD card read and write program

Objective: To study the SD card / / operation

Design / software

1, using SPI communication / / SD card

2, go to SD / / in order to 0-255 a total of 256 data, and then read back LCD1602 display

/ / hardware requirements:

S11 ON / / dial switch

Jumper J18 / / all connected

#include //dsPIC30F6014 standard header file

_FOSC( CSW_FSCM_O&F FX T_PLL4); //4 doubler crystal oscillator, Failsafe clock closed

_FWDT (WDT_OFF); / / close the watchdog timer

_FBORPO(RP BOR_OFF& MCLR_EN);/ / reset prohibited MCLRr eset enable.

_FGS (CODE_PROT_OFF); / / code protection against #define CS PORTGbits.RG9 / / SD card selection pin definition #define RSL TB4 / / definition LCDc ontrol bits (note here can only register with LATB, you cannot directly use the

PORTB register)

#define RW TB5

#define e TB6

Unsigned char __attribute__ ((address (0x900)))

lcd[3]={0,0,0};

Void (spi_init); / / declaration system initial function

Void (spi_low); / / that produces low baud rate (using the SD card initialization function)

Void (spi_high); / / that produce high baud rate function (SD

card initialization after use)

Unsigned char (sd_reset); / / that the SD card

initialization function

Unsigned char SD_SendComman(udn signed char CMDu nsigned, long

ARG); / / write SD card command function statement

Unsigned char SPI_WriteByte (unsigned char VAL); / / write a byte function statement

Unsigned char SPI_ReadByte (void); / / that receive a byte function

Unsigned char SD_WriteSingleBlock (unsigned long sector); / / that single BLOCK data write SD card function

Unsigned char SD_ReadSingleBlock (unsigned long sector); / / read SD card data function single BLOCK statement

Void (lcd_display); / / state results display function

Void (delay); / / state delay function (shown by)

/ / system initialization function

Void spi_init ()

{

TRISG=0x00d0; / / set the SDI output, C output port for the other

TRISB=0X0000; / / set for the output port B

TRISD=0X0000; / / set for the output port D

SPI2CON=0x0278; / / idle bus is high, fosc/64

SPI2STAT=0x8000; / / the end of sampling the output data of input data, the rising edge of data transmission

Write a LCD program

/ / write a byte of data function

After changing the level / / on the need to insert a delay time, otherwise the LCD react.

Void write (unsigned char x)

{

PORTD=x; / / PORTD port to send data to be displayed

Delay ();

Rs=1; / / the byte data, rather than command

Delay ();

Rw=0; / / the operation for writing,

Instead of reading

Delay ();

E=0; / / low enable signal

(delay); / / keep the enable signal is low for a period of time

Delay ();

E=1; / / pull high enable signal needed by the rising edge of the LCD operation

相关文档
最新文档