本站近期与电子报单片机公共实验室合作推出系列教学文章!

欢迎来到51单片机学习网:庆祝51单片机学习网全面改版

返回主页XL2000实验仪 51论坛 单片机教学 本站例程  技术资料  软件下载  产品介绍 学液晶显示 如何购买  

         步进电机  xl600实验仪  红外线遥控  c语言集锦 自制编程器 音响技术 品质技术 音响网址   更新中..51论坛

51单片机学习网XL2000开发套件火热推出,全自动smt贴片工艺,推广期间每套单价998元

点击察看说明书(64页彩色PDF文档)

1.1 系统简介

4.3 ISP引脚连接

端口按键判断

红外线遥控 555硬件振荡器

1.2 模块接口定义

5.1 仿真概述

矩阵按键识别技术

汉字显示屏 PS2键盘实验
2.1 软件安装   5.2 KEIL软件指南

74LS14反向器

1602液晶显示屏 SD 卡实验
2.2 软件界面介绍 

51引脚说明

74LS138译码器

8155试验

485通信实验 
2.3 软件操作

八路跑马灯

74LS164串入并出

24C02储存

DS1302实时时钟
3.1 USB驱动安装

继电器控制

74LS165并入串出 步进电机 产生hex文件
3.2  特别 usb安装 

8路拨动开关

dac0832应用

93c46 演示

常见问题解答
4.1 ISP 介绍 

数码管静态扫描 

模拟/数字转换器

串行双向通信 系统配置指南
4.2  下载头之插头定义

数码管动态扫描

小喇叭警报器 18B20温度显示 购买方式

  

*      实验26 SD SPI模式实验

SD卡全称为 Secrue Digital Memory Card,具有轻巧、可加密、传输速度高、适用于手持设备等优点。

SD需要高速读写,同时也要使手持等嵌入式设备能方便使用,特设有两个访问接口:SD模式接口和SPI接口。单片机由于速度问题一般用SPI接口(注意本机SD卡为选购件,或自行到电脑城购买

SD卡命令共分为12类,分别为class0class11,支持命令集 如下:

Class0 :(卡的识别、初始化等基本命令集)

CMD0:复位SD .

CMD1:OCR寄存器.

CMD9:CSD寄存器.

CMD10:CID寄存器.

CMD12:停止读多块时的数据传输

CMD13: Card_Status 寄存器

Class2 (读卡命令集):

CMD16:设置块的长度

CMD17:读单块.

CMD18:读多块,直至主机发送CMD12为止 .

Class4(写卡命令集) :

CMD24:写单块.

CMD25:写多块.

CMD27:CSD寄存器 .

Class5 (擦除卡命令集):

CMD32:设置擦除块的起始地址.

CMD33:设置擦除块的终止地址.

CMD38: 擦除所选择的块.

Class6(写保护命令集):

CMD28:设置写保护块的地址.

CMD29:擦除写保护块的地址.

CMD30: Ask the card for the status of the write protection bits

class7:卡的锁定,解锁功能命令集

class8:申请特定命令集 。

class10 11 :保留

其中 class1, class3,class9SPI模式不支持

 

 

SD卡部分的程序请看配套的光盘编程实例程序

 

SD引脚

SD模式

SPI模式

1

DAT3

CS

2

CMD

DI

3

VSS

VSS

4

VDD

VDD

5

CLK

SCLK

6

VSS

VSS

7

DAT0

DO

8

DAT1

Resvered

9

DAT2

Resvered

 

1 用一根4PIN排线一端插入P1.0-1.3,另一端插入sd卡

的接口jp74.2 用两根1 pin线连接SD卡的电源到开发板的电源5V和GND3用一条8PIN的数据排线把CPU部份的P0口

(JP51)连接到八路指示灯部份的JP32烧写配套的光盘编程实例的SD卡程序, 8路跑灯开始做加1显示,如果此

时拔下SD卡,则8路跑灯停止


#include "HAL.H"

//============================================================
//写一字节到SD卡,模拟SPI总线方式
void SdWrite(unsigned char n)
{

unsigned char i;

for(i=8;i;i--)
{
SD_CLK=0;
SD_DI=(n&0x80);
n<<=1;
SD_CLK=1;
}
SD_DI=1; 

//================================================================
//从SD卡读一字节,模拟SPI总线方式
unsigned char SdRead()
{
unsigned char n,i;
for(i=8;i;i--)
{
SD_CLK=0;
SD_CLK=1;
n<<=1;
if(SD_DO) n|=1;

}
return n;
}
//================================================================
//检测SD卡的响应
unsigned char SdResponse()
{
unsigned char i=0,response;

while(i<=8)
{
response = SdRead();
if(response==0x00)
break;
if(response==0x01)
break;
i++;
}
return response;

//================================================================
//发命令到SD卡
void SdCommand(unsigned char command, unsigned long argument, unsigned char CRC)
{

SdWrite(command|0x40);
SdWrite(((unsigned char *)&argument)[0]);
SdWrite(((unsigned char *)&argument)[1]);
SdWrite(((unsigned char *)&argument)[2]);
SdWrite(((unsigned char *)&argument)[3]);
SdWrite(CRC);
}
//================================================================
//初始化SD卡
unsigned char SdInit(void)
{
int delay=0, trials=0;
unsigned char i;
unsigned char response=0x01;

SD_CS=1;
for(i=0;i<=9;i++)
SdWrite(0xff);
SD_CS=0;

//Send Command 0 to put MMC in SPI mode
SdCommand(0x00,0,0x95);


response=SdResponse();

if(response!=0x01)
{
return 0;


while(response==0x01)
{
SD_CS=1;
SdWrite(0xff);
SD_CS=0;
SdCommand(0x01,0x00ffc000,0xff);
response=SdResponse();


SD_CS=1;
SdWrite(0xff);
return 1; 
}
//================================================================
//往SD卡指定地址写数据,一次最多512字节
unsigned char SdWriteBlock(unsigned char *Block, unsigned long address,int len)
{
unsigned int count;
unsigned char dataResp;
//Block size is 512 bytes exactly
//First Lower SS

SD_CS=0;
//Then send write command
SdCommand(0x18,address,0xff);

if(SdResponse()==00)
{
SdWrite(0xff);
SdWrite(0xff);
SdWrite(0xff);
//command was a success - now send data
//start with DATA TOKEN = 0xFE
SdWrite(0xfe);
//now send data
for(count=0;count<len;count++) SdWrite(*Block++);

for(;count<512;count++) SdWrite(0);
//data block sent - now send checksum
SdWrite(0xff); //两字节CRC校验, 为0XFFFF 表示不考虑CRC
SdWrite(0xff);
//Now read in the DATA RESPONSE token
dataResp=SdRead();
//Following the DATA RESPONSE token
//are a number of BUSY bytes
//a zero byte indicates the MMC is busy

while(SdRead()==0);

dataResp=dataResp&0x0f; //mask the high byte of the DATA RESPONSE token
SD_CS=1;
SdWrite(0xff);
if(dataResp==0x0b)
{
//printf("DATA WAS NOT ACCEPTED BY CARD -- CRC ERROR\n");
return 0;
}
if(dataResp==0x05)
return 1;

//printf("Invalid data Response token.\n");
return 0;
}
//printf("Command 0x18 (Write) was not received by the MMC.\n");
return 0;
}
//=======================================================================
//从SD卡指定地址读取数据,一次最多512字节
unsigned char SdReadBlock(unsigned char *Block, unsigned long address,int len)
{
unsigned int count;
//Block size is 512 bytes exactly
//First Lower SS

// printf("MMC_read_block\n");

SD_CS=0;
//Then send write command
SdCommand(0x11,address,0xff);

if(SdResponse()==00)
{
//command was a success - now send data
//start with DATA TOKEN = 0xFE
while(SdRead()!=0xfe);

for(count=0;count<len;count++) *Block++=SdRead(); 

for(;count<512;count++) SdRead();

//data block sent - now send checksum
SdRead();
SdRead();
//Now read in the DATA RESPONSE token
SD_CS=1;
SdRead();
return 1;
}
// printf("Command 0x11 (Read) was not received by the MMC.\n");
return 0;
}

 

 

精致外观

精致外观

精致外观

精致外观

精致外观

精致包装

精致包装

精致包装

配套附件

配套附件

使用手册

使用手册

使用手册

配套附件

配套附件

配套附件

配套附件

配套附件

配套附件

配套附件

精致细节

精致细节

精致细节

精致细节

配套光盘