⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d12_test1.c

📁 用d12开发的sd/mmc读卡器 都是源码哈~
💻 C
字号:
#include<avr/io.h>
#include"D12/D12_Operation.h"
#include"D12/CHAP_9.h"
#include"D12/D12_Int.h"
#include"MMC_SD/MMC_SD.h"

#define LED_DDR  DDRB
#define LED_PORT PORTB
#define LED_BIT  1

#define LED_ON()  LED_PORT |=  1<<LED_BIT
#define LED_OFF() LED_PORT &= ~(1<<LED_BIT)

extern unsigned char DISK_CAPACITY[8];





int main()
{
	U8 i;
	U32 Cap;
	U8 retry = 0;

	USB_Delay(0xffff);
	
	D12_PORT_INI();
	
	MMC_SD_Init();
	LED_DDR |= 1<<LED_BIT;
	while(MMC_SD_Reset())// retry 100 times
	{
		retry++;
		if(retry>100)break;
	}
	if(retry<100)//if success
	{
		//LED_ON();

		//读SD卡容量
		Cap = (MMC_SD_ReadCapacity()/512)-1;//读到的是总容量,不是能寻址到的扇区地址,所以要减1处理
		DISK_CAPACITY[0] = ((U8 *)(&Cap))[3];//转成大端格式
		DISK_CAPACITY[1] = ((U8 *)(&Cap))[2];
		DISK_CAPACITY[2] = ((U8 *)(&Cap))[1];
		DISK_CAPACITY[3] = ((U8 *)(&Cap))[0];

		if(D12_Read_Chip_ID()==0x1210)
		{
			//puts("Find Pdiusbd12, chip id = 0x1210");
			
			USB_Init();
			while(1)
			{
				while(!D12_INT) //检测中断
				{
					//PORTB |= 0x02;
					i = D12_Read_Interrupt_Register()&0xff;
					UsbIntProc(i);			
				}
			}
		}
		else ;
	}
//	LED_ON();
	while(1);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -