您好,歡迎來電子發(fā)燒友網! ,新用戶?[免費注冊]

您的位置:電子發(fā)燒友網>源碼下載>單片機編程>

基于MCU的U盤源碼實現flash的windos文件系統(tǒng)

大?。?/span>264 人氣: 2010-02-24 需要積分:0
你又知道了的空間

用戶級別:注冊會員

貢獻文章:

貢獻資料:

基于MCU的U盤源碼實現flash的windos文件系統(tǒng).rar

#include "d12ci.h"
#include "main.h"
//#include "44b.h"

extern EPPFLAGS bEPPflags;


void outportdata(unsigned char val)
{
DISABLE;

D12_DATA=val;

ENABLE;
}


void outportcmd(unsigned char val)
{
DISABLE;

D12_COMMAND=val;

ENABLE;
}


unsigned char inportb(void)
{
unsigned char c;
DISABLE;
c = D12_DATA;
ENABLE;
return c;
}


void D12_SetAddressEnable(unsigned char bAddress, unsigned char bEnable)
{
?if(bEPPflags.bits.in_isr == 0)
??DISABLE;

?outportcmd(0xD0);
?if(bEnable)
??bAddress |= 0x80;
?outportdata(bAddress);

?if(bEPPflags.bits.in_isr == 0)
??ENABLE;
//?Uart_Printf("E D12_SetAddressEnable\n");
}

void D12_SetEndpointEnable(unsigned char bEnable)
{
?if(bEPPflags.bits.in_isr == 0)
??DISABLE;

?outportcmd(0xD8);
?if(bEnable)
??outportdata(1);
?else
??outportdata(0);

?if(bEPPflags.bits.in_isr == 0)
??ENABLE;
//?Uart_Printf("E D12_SetEndpointEnable\n");
}

void D12_SetMode(unsigned char bConfig, unsigned char bClkDiv)
{
??if(bEPPflags.bits.in_isr == 0)
??DISABLE;
??outportcmd(0xF3);
??outportdata(bConfig);
??outportdata(bClkDiv);
??if(bEPPflags.bits.in_isr == 0)
???ENABLE;
//?Uart_Printf("E D12_SetMode\n");

}

void D12_SetDMA(unsigned char bMode)
{

??if(bEPPflags.bits.in_isr == 0)
?? ?DISABLE;
??outportcmd(0xFB);
??outportdata(bMode);
?if(bEPPflags.bits.in_isr == 0)
??ENABLE;
//?Uart_Printf("E D12_SetDMA\n");

}
/*
unsigned char D12_GetDMA(void)
{
?outportcmd(0xFB);
?return(inportb());
}
*/
/*
unsigned char D12_ReadEndpointStatus(unsigned char bEndp)
{
?unsigned char c;

?if(bEPPflags.bits.in_isr == 0)
??DISABLE;

?outportcmd(0x80 + bEndp);
?c = inportb();

?if(bEPPflags.bits.in_isr == 0)
??ENABLE;

?return c;
}
*/
void D12_SetEndpointStatus(unsigned char bEndp, unsigned char bStalled)
{
?if(bEPPflags.bits.in_isr == 0)
??DISABLE;

?outportcmd(0x40 + bEndp);
?outportdata(bStalled);

?if(bEPPflags.bits.in_isr == 0)
??ENABLE;
//?Uart_Printf("E D12_SetEndpointStatus\n");
}


/*
void D12_SendResume(void)
{
?outportcmd(0xF6);
}
*/

unsigned char D12_WriteEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
{
?unsigned char i;

?if(bEPPflags.bits.in_isr == 0)
??DISABLE;
?//---------------------
?outportcmd(endp);?//選擇端點
?inportb();??//讀入滿/空狀態(tài)

?outportcmd(0xF0);?//寫緩沖區(qū)命令
?outportdata(0);
?outportdata(len);

?for(i=0; i??outportdata(*(buf+i));

?outportcmd(0xFA);?//駛購沖區(qū)有效
?
?//--------------------------------
?if(bEPPflags.bits.in_isr == 0)
??ENABLE;
//?Uart_Printf("E D12_WriteEndpoint\n");

?return len;
}
void D12_AcknowledgeEndpoint(unsigned char endp)
{
?outportcmd( endp);?//選擇端點
?outportcmd(0xF1);?//應答設置
?if(endp == 0)
??outportcmd(0xF2);?//緩沖區(qū)清零
//?Uart_Printf("E D12_AcknowledgeEndpoint%d\n",endp);
}
unsigned short D12_ReadInterruptRegister(void)
{
?unsigned char b1;
?unsigned int j;
?//outportb(D12_COMMAND, 0xF4);
?outportcmd(0xF4);
?b1 = inportb();
?j = inportb();
?j <<= 8;
?j += b1;
//?if(j) Uart_Printf("E D12_ReadInterruptRegister:%x\n",j);//printf the intterrupt number if it's not zero.
?return j;
}

unsigned char D12_ReadLastTransactionStatus(unsigned char bEndp)
{
?//outportb(D12_COMMAND, 0x40 + bEndp);
?outportcmd(0x40 + bEndp);
//?Uart_Printf("E D12_ReadLastTransactionStatus\n");
?return inportb();
}
unsigned char D12_ReadEndpoint(unsigned char endp, unsigned char len, unsigned char * buf)
{
?unsigned char i, j;


?if(bEPPflags.bits.in_isr == 0)
??DISABLE;
?//--------------------------------
?outportcmd(endp);???//選擇端點
?if((inportb() & D12_FULLEMPTY) == 0) {?//如果緩沖區(qū)為空,則返回
??if(bEPPflags.bits.in_isr == 0)
???ENABLE;
??return 0;
?}

?outportcmd(0xF0);???//讀緩沖區(qū)
?j = inportb();
?j = inportb();

?if(j > len)
??j = len;

?for(i=0; i??*(buf+i) = inportb();

?outportcmd(0xF2);????//緩沖區(qū)清空
?//-------------------------------
?if(bEPPflags.bits.in_isr == 0)
??ENABLE;

//?Uart_Printf("E D12_ReadEndpoint:%d,%d character read\n",endp,j);
?return j;
}

unsigned char D12_SelectEndpoint(unsigned char bEndp)
{
?unsigned char c;

?if(bEPPflags.bits.in_isr == 0)
??DISABLE;

?outportcmd(bEndp);
?c = inportb();

?if(bEPPflags.bits.in_isr == 0)
??ENABLE;

//?Uart_Printf("E D12_SelectEndpoint\n");
?return c;
}

非常好我支持^.^

(0) 0%

不好我反對

(0) 0%

      發(fā)表評論

      用戶評論
      評價:好評中評差評

      發(fā)表評論,獲取積分! 請遵守相關規(guī)定!

      ?