欢迎来到天天文库
浏览记录
ID:58863701
大小:144.00 KB
页数:20页
时间:2020-09-22
《基于Atmega128单片机SD卡读写程序(分享).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、基于Atmega128单片机SD卡读写程序实物图对照接线图以下是一个简单的测试SD卡读写的程序,程序是基于Atmega128单片机编写的,对于Atmega的其他单片机仅需要做管脚改动就可以使用,其他单片机更改要更大。sd.h//******************************************************************//SPI各线所占用的端口#defineSD_SS PB6 #defineSD_SCK PB1#defineSD_MOSI PB2#defineSD_
2、MISO PB3//******************************************************************#defineSD_DDR DDRB#defineSD_PORT PORTB#defineSD_PIN PINB#defineSD_SS_H SD_PORT
3、=(1<#defineSDSS_L SD_PORT&=~(1<#defineSD_SCK_H SD_PORT
4、=(1<#defineSD_SCK_L SD_PORT&=~(1<#defineSD_MOS
5、I_H SD_PORT
6、=(1<#defineSD_MOSI_L SD_PORT&=~(1<#defineSD_MISO_IN (SD_PIN&(1/-------------------------------------------------------------//错误号//-------------------------------------------------------------#defineINIT_CMD0_ERROR 0xFF#defineINIT_CMD1_ERROR 0xFE#defineWRI
7、TE_BLOCK_ERROR 0xFD#defineREAD_BLOCK_ERROR 0xFC#defineTRUE 0x01//-------------------------------------------------------------//MMC/SD命令(命令号从40开始,只列出基本命令,并没有都使用)//-------------------------------------------------------------#defineSD_RESET 0x40+0
8、 #defineSD_INIT 0x40+1#defineSD_READ_CSD 0x40+9#defineSD_READ_CID 0x40+10#defineSD_STOP_TRANSMISSION0x40+12#defineSD_SEND_STATUS 0x40+13#defineSD_SET_BLOCKLEN 0x40+16#defineSD_READ_BLOCK 0x40+17#defineSD_READ_MULTI_BLOCK0x40+18#defineSD_WRITE_BLOC
9、K 0x40+24#defineSD_WRITE_MULTI_BLOCK0x40+25//片选关(MMC/SD-CardInvalid)#defineSD_Disable()SD_SS_H//片选开(MMC/SD-CardActive)#defineSD_Enable()SD_SS_LSD_TEST.C//****************************************************************************************///ICC-AVRapplicationbuilder:03-5
10、-208:39:11//Target:M128//Crystal:3.6864Mhz#include#include#include 'sd.h'voiduart0_init(void);voidputchar(unsignedcharcontent);voidputstr(unsignedchar*s);voidSD_Port_Init(void);unsignedcharSD_Init(void);unsignedcharSD_write_sector(unsignedlongaddr,unsignedchar*Buffer);unsignedch
11、arSD_read_sector(unsignedlongaddr,unsign
此文档下载收益归作者所有