日本ab视频-日本ab在线-日本a黄-日本a黄色片-国产亚洲精品第一综合linode-国产亚洲精品高清在线

新聞資訊
SD卡AVR接口程序,基于ATmega32,編寫(xiě)ICCAVR6.31A
2010-11-23


SD卡接口程序,基于ATmega32,編寫(xiě)ICCAVR6.31A

[code="C"]

/************************************************************/
/*           SD Code for   M32L             */
/*       By   pasyong        */
/*       2006-4         */
/*       Base ICC6.31A             */
/************************************************************/
#include <iom32v.h>
#include <macros.h>
#include "1011.h"
#define uchar unsigned char
#define uint unsigned int
#define MMC_CS_PIN     BIT(4)    //PORTB.4
#define MMC_PORT       PORTB   

 uchar reading=0,a=0,pointer=0;
void sd_port_init()
{
MMC_PORT =MMC_CS_PIN;
}
uchar BUFFER[512];                   //扇區(qū)緩沖區(qū)
uint i=0;
void delay_nus(uint n)
 {
 unsigned char  b;
  for (b = 1; b<n; b++)
   ;
 }
//****************************************************************************
//Send a Command to MMC/SD-Card
//Return: the second byte of response register of MMC/SD-Card
//****************************************************************************
uchar SD_Write_Command(uchar cmd,unsigned long arg)
{
   uchar tmp;
   uchar retry=0;
  
   //MMC_PORT =MMC_CS_PIN;       //SD卡關(guān)閉  
   //send 8 Clock Impulse
   Write_Byte_SPI(0xFF);
  
   //set MMC_Chip_Select to low (MMC/SD-Card active)
  MMC_PORT&=~MMC_CS_PIN;       //SD卡使能

   Write_Byte_SPI(cmd 0x40);   //送頭命令
   Write_Byte_SPI(arg>>24);
   Write_Byte_SPI(arg>>16);     //send 6 Byte Command to MMC/SD-Card
   Write_Byte_SPI(arg>>8);
   Write_Byte_SPI(arg&0xff);
   Write_Byte_SPI(0x95);       //僅僅對(duì)RESET有效的CRC效驗(yàn)碼
 
   //get 8 bit response
   //Read_Byte_MMC(); //read the first byte,ignore it.
   do
   {  //Only last 8 bit is used here.Read it out.
      tmp = Read_Byte_SPI();
      retry++;
   }
   while((tmp==0xff)&&(retry<100));  //當(dāng)沒(méi)有收到有效的命令的時(shí)候
  
   if(reading==0)
   MMC_PORT =MMC_CS_PIN;            //MMC_CS_PIN=1;
   else MMC_PORT&=~MMC_CS_PIN;      //MMC_CS_PIN=0;  
   return(tmp);
}
//****************************************************************************
//SD卡初始化(SPI-MODE)
//****************************************************************************
uchar SD_Init(void)

   uchar retry,temp;
   uchar i;
   MMC_PORT&=~MMC_CS_PIN;      //SD卡使能
 
  delay_nus(250);  //Wait MMC/SD ready...
   for (i=0;i<0x0f;i++)
   {
      Write_Byte_SPI(0xff); //send 74 clock at least!!!
   }
   //Send Command CMD0 to MMC/SD Card
   retry=0;
  
   do
   { //retry 200 times to send CMD0 command
     temp=SD_Write_Command(0,0);
     retry++;
     if(retry==100)
     {
      ;//CMD0 Error!
     }
   }
   while(temp!=1); 
  
   //Send Command CMD1 to MMC/SD-Card
   retry=0;
   do
   { //retry 100 times to send CMD1 command
     temp=SD_Write_Command(1,0);
     retry++;
     if(retry==100)
     {
     ;
     }
   }
   while(temp!=0);
   retry=0;
    SD_Write_Command(16,512);     //設(shè)置一次讀寫(xiě)B(tài)LOCK的長(zhǎng)度為512個(gè)字節(jié)
 
   MMC_PORT =MMC_CS_PIN;   //MMC_CS_PIN=1;  //set MMC_Chip_Select to high
   return(0); //All commands have been taken.
}
//****************************************************************************
//從SD卡讀一個(gè)扇區(qū)  Return 0 if no Error.
//****************************************************************************
uchar SD_Read_Block(unsigned long address)

   uchar temp=0;uint i=0;
   reading=1;
   temp=SD_Write_Command(17,address);     //讀出RESPONSE    
   while (Read_Byte_SPI()!= 0xfe)
   {;}  //直到讀取到了數(shù)據(jù)的開(kāi)始頭0XFE,才繼續(xù)
   for(i=0; i<512; i++)
 {
 BUFFER[i]=Read_Byte_SPI();
 }
   Read_Byte_SPI();//CRC - Byte
   Read_Byte_SPI();//CRC - Byte
   reading=0;
   MMC_PORT =MMC_CS_PIN;        //關(guān)閉SD卡
   return(temp);
}

[/code]


關(guān)注有人微信公眾號(hào)
了解更多信息

主站蜘蛛池模板: 亚洲尹人香蕉网在线视颅 | 日韩视频在线免费观看 | 欧美又硬又粗又长又大 | 日本成人免费在线观看 | 国产精品高清视亚洲一区二区 | 免费看一级做a爰片久久 | 国产1区2区在线观看 | 抄逼| 香蕉在线精品视频在线观看2 | 日韩欧美在线综合网高清 | 国产三级精品三级在线专区91 | 日本道在线 | 国产欧美日韩不卡一区二区三区 | 国产麻豆va精品视频 | 91精品国产网曝事件门 | 蜜桃臀久久伊人福利 | 在线h观看 | 日本亚洲中午字幕乱码 | 中国麻豆 | 六月丁香啪啪 | 免费日韩在线视频 | 厚颜无耻韩国动漫免费观看5 | 蜜臀麻豆 | 99福利资源久久福利资源 | 成年黄网站色视频免费观看 | 国产手机看片 | 国产精品久久一区二区三区 | 久久这里知有精品99re66 | 国产精品久久久久蜜芽 | 日韩一级片播放 | 日本高清不卡二区 | 亚洲人成综合网站在线 | 五月激情久久 | 两个人的视频在线免费观看 | 天堂在线观看免费观看 | 成人黄网大全在线观看 | 一区二区三区欧美视频 | 4438五月| 四虎sihu新版影院亚洲精品 | 久久99这里只有精品国产 | 久久香蕉国产线看观看8青草 |