楼主,您好 我在读U盘的物理扇区时,读到的总是U盘的产品型号,我的程序如下, 因EMAIL老是超时,发不出,我的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相关子程序 //********************************************************* 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检测 Ch375_WR_Data(0x11); temp1=Ch375_RD_Data(); //总是0xFF
Ch375_Command(0x06); //CH375 CHIP检测 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,时能RX*/ TMOD= 0x20; /*TMOD: 定时器工作再模式2, 8位重载*/ TH1= 202; /*设置定时1用作波特率的重载值 256-49000k/48/2/9.6k=203 */ TR1= 1; /*开定时器1*/ CKCON |= 0x02; /*定时器1用系统时钟作为它的时基 /48*/ PCON |= 0x80; /*SMOD00 = 1*/ ReceiveBit=0; ES0=1; //UART中断标志
TMR2CN=0x00; //TC2,时钟选择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; /*开中断标志*/ }
void UART0_ISR (void) interrupt 4 { if(!TI0) //是发送中断还是接收中断 { RI0 = 0; /*清接收标志位*/ Receiver =SBUF0; /*保存接收到的数据*/ ReceiveBit=1; /*置接收标志*/ } TI0 = 0; /*清发送标志位*/ }
void Delay_xxuS(temp) //用示波器校正过,总是>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++; }