樓主,您好 我在讀U盤的物理扇區(qū)時(shí),讀到的總是U盤的產(chǎn)品型號(hào),我的程序如下, 因EMAIL老是超時(shí),發(fā)不出,我的EMAIL:MICHAEL.DU@AVERA-TECH.COM
//HOST //*********************************************************
#include "c8051F410.h" #include "main.h"
//************************************************ // main ASM // system clock=50M //************************************************
void main(void) { PCA0MD &= ~0x40; /*watch dog*/ Sys_Clk_Init(); Port_Init();
// Flash_Init(); // Flash_RD_ID();
// Main_Init(); Ch375_Init();
while(Ch375_Counter != 0x14) { Ch375_Command(0x51); Ch375_Counter=Ch375_Status(); Delay_xxuS(50000); Delay_xxuS(50000); }
Ch375_RD_Page(); while(1); } void Ch375_RD_Page(void) { data char i;
Fat_Pointer=0x00; Ch375_Command(0x54); // while(Ch375_INT); // i=Ch375_Status(); Ch375_WR_Data(0x8a); Ch375_WR_Data(0x00); Ch375_WR_Data(0x00); Ch375_WR_Data(0x00); Ch375_WR_Data(0x01);
while(Ch375_INT); i=Ch375_Status();
for(i=0;i<8;i++) { Ch375_Command(0x28);
for(Ch375_Counter=0x00;Ch375_Counter<65;Ch375_Counter++) { Fat_Data[Fat_Pointer]=Ch375_RD_Data(); Fat_Pointer++; } Ch375_Command(0x55); while(Ch375_INT); // Ch375_Status();
} }
//********************************************************* // ch375相關(guān)子程序 //********************************************************* void U_Communication(void) { if(J2a_Pointer>=512) { Ch375_Command(0x56); } }
char Ch375_Init(void) { char temp=0; char temp1;
Ch375_Command(0x05); Delay_xxuS(40000);
Ch375_Command(0x15); //工作模式輸入 Delay_xxuS(100); Ch375_WR_Data(0x06); temp1=Ch375_RD_Data();
Ch375_Command(0x06); //CH375 CHIP檢測(cè) Ch375_WR_Data(0x11); temp1=Ch375_RD_Data(); //總是0xFF
Ch375_Command(0x06); //CH375 CHIP檢測(cè) Ch375_WR_Data(0x11); temp1=Ch375_RD_Data();
Ch375_Command(0x06); Ch375_WR_Data(0x34); temp1=Ch375_RD_Data();
Ch375_Command(0x51); //工作模式輸入 temp1=Ch375_RD_Data();
return(temp1); }
char Ch375_Status(void) { char temp; Ch375_Command(0x22); temp=Ch375_RD_Data(); return(temp); }
void Usb_Err(void) {
}
void Sram_To_Usb(void) {
}
void Usb_To_Sram(void) {
}
void Ch375_Command(command) { idata volatile char nop_nop;
P1MDOUT=0xff; Ch375_A0=1; P1=command; Ch375_CE=0; Ch375_WE=0; nop_nop++; nop_nop++; nop_nop++; nop_nop++; Ch375_WE=1; Ch375_CE=1; Ch375_A0=0;
for(nop_nop=0;nop_nop<5;nop_nop) nop_nop++; }
void Ch375_WR_Data(value) { idata volatile char nop_nop; P1MDOUT=0xff; P1=value; Ch375_CE=0; Ch375_WE=0; nop_nop++; nop_nop++; nop_nop++; nop_nop++; Ch375_WE=1; Ch375_CE=1; for(nop_nop=0;nop_nop<2;nop_nop) nop_nop++; }
char Ch375_RD_Data(void) { idata volatile char nop_nop; unsigned char para;
P1MDOUT=0x00; P1=0xff; Ch375_CE=0; Ch375_RE=0; nop_nop++; nop_nop++; nop_nop++; nop_nop++; para=P1; Ch375_RE=1; Ch375_CE=1; // P1=0xff; for(nop_nop=0;nop_nop<2;nop_nop) nop_nop++; return(para); }
//************************************************** // sys_clk_init() //************************************************** void Sys_Clk_Init(void) { int i = 0;
PFE0CN &= ~0x20; FLSCL = 0x10; PFE0CN |= 0x20; OSCICN = 0x87; CLKMUL = 0x80; for (i = 0; i < 20; i++); // Wait 5us for initialization CLKMUL |= 0xC0; while ((CLKMUL & 0x20) == 0); CLKSEL = 0x02; }
//************************************************** // Port_Init() //************************************************** void Port_Init(void) { P0MDIN=0xff; P1MDIN=0xff; P2MDIN=0xff; P0=0x2b; P2=0xff; // P1=0xff; P0MDOUT=0xdc; // P1MDOUT=0xff; P2MDOUT=0xf7; XBR0=0x01; //enable uart0 XBR1=0x40; //enable port
Ch375_CE=1; Ch375_A0=0;
Flash_CE=1; //init i/o Flash_RE=1; Flash_WE=1; Flash_R_B=1; //OPEN DRAIN Flash_CLE=0; Flash_ALE=0;
J2a_CS=1; J2a_INT=1; J2a_RST=0; }
//************************************************** // 中斷 //************************************************** void INT_Init (void) { SCON0= 0x50; /*SCON0:模式1,8位UART,時(shí)能RX*/ TMOD= 0x20; /*TMOD: 定時(shí)器工作再模式2, 8位重載*/ TH1= 202; /*設(shè)置定時(shí)1用作波特率的重載值 256-49000k/48/2/9.6k=203 */ TR1= 1; /*開定時(shí)器1*/ CKCON |= 0x02; /*定時(shí)器1用系統(tǒng)時(shí)鐘作為它的時(shí)基 /48*/ PCON |= 0x80; /*SMOD00 = 1*/ ReceiveBit=0; ES0=1; //UART中斷標(biāo)志
TMR2CN=0x00; //TC2,時(shí)鐘選擇SYSTEM CLOCK/12 TMR2RLL=0x3D; //10mS TMR2RLH=0x5D; TMR2L=0x3D; TMR2H=0x5D; TR2=0;
IT01CF=0x01; //INT0 低電平中斷 P0.1 IT0=0; EX0=0; //允許INT0中斷 EA=0; /*開中斷標(biāo)志*/ }
void UART0_ISR (void) interrupt 4 { if(!TI0) //是發(fā)送中斷還是接收中斷 { RI0 = 0; /*清接收標(biāo)志位*/ Receiver =SBUF0; /*保存接收到的數(shù)據(jù)*/ ReceiveBit=1; /*置接收標(biāo)志*/ } TI0 = 0; /*清發(fā)送標(biāo)志位*/ }
void Delay_xxuS(temp) //用示波器校正過(guò),總是>temp uS { int idata x; for(x=0;x Delay_1uS(); }
void Delay_1uS(void) { idata char xx; for(xx=0;xx<10;xx) xx++; }
void Delay() { data int x; for(x = 0;x <300;x) x++; }