資源描述:
《基于atmega128單片機sd卡讀寫程序()》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、基于Atmega128單片機SD卡讀寫程序?qū)嵨飯D對照接線圖以下是一個簡單的測試SD卡讀寫的程序,程序是基于Atmega128單片機編寫的,對于Atmega的其他單片機僅需要做管腳改動就可以使用,其他單片機更改要更大。矚慫潤厲釤瘞睞櫪廡賴。sd.h//******************************************************************聞創(chuàng)溝燴鐺險愛氌譴凈。//SPI各線所占用的端口#defineSD_SS????PB6????????????????#defineSD_SCK????PB1#defineSD_MOSI?????PB2#d
2、efineSD_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<#defineS
5、D_MOSI_H??SD_PORT
6、=(1<#defineSD_MOSI_L??SD_PORT&=~(1<釅錒極額閉鎮(zhèn)檜豬訣錐。#defineSD_MISO_IN???(SD_PIN&(1/-------------------------------------------------------------彈貿(mào)攝爾霽斃攬磚鹵廡。//錯誤號//-------------------------------------------------------------謀蕎摶篋飆鐸懟類蔣薔。#defineINIT_CMD0_ERROR????0xFF#defineINIT_CMD1
7、_ERROR????0xFE#defineWRITE_BLOCK_ERROR??0xFD#defineREAD_BLOCK_ERROR?????0xFC#defineTRUE?????????????0x01//-------------------------------------------------------------廈礴懇蹣駢時盡繼價騷。//MMC/SD命令(命令號從40開始,只列出基本命令,并沒有都使用)//-------------------------------------------------------------煢楨廣鰳鯡選塊網(wǎng)羈淚。#define
8、SD_RESET????????0x40+0?????????????#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#d
9、efineSD_WRITE_BLOCK??????0x40+24#defineSD_WRITE_MULTI_BLOCK0x40+25//片選關(guān)(MMC/SD-CardInvalid)#defineSD_Disable()SD_SS_H//片選開(MMC/SD-CardActive)#defineSD_Enable()SD_SS_LSD_TEST.C//****************************************************************************************/鵝婭盡損鵪慘歷蘢鴛賴。//ICC-AVRapplicat
10、ionbuilder:03-5-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_wr