硬盘控制电路以及原程序

[05-30 04:13:38]   来源:http://www.88dzw.com  单片机电路图   阅读:8249

文章摘要://send_string("Now Sending \n");while(i){ReadData();send_char(Data_bufferH);send_char(Data_bufferL);i-=2;}}/*硬盘寻址**/WriteCHS(byte head,uint cylinder,byte sector,byte read_count){WaitBSY();WriteReg(_DeviceAndHead,0xa0|head);WriteReg(_CylinderH,(char)(cylinder>>8)); WriteReg(_Cylinder

硬盘控制电路以及原程序,标签:电路图讲解,电路图练习,http://www.88dzw.com
//send_string("Now Sending  \n");
while(i){
ReadData();



send_char(Data_bufferH);
send_char(Data_bufferL);
i-=2;
}
}




/*********************************************************
硬盘寻址
**********************************************************/
WriteCHS(byte head,uint cylinder,byte sector,byte read_count)
{
WaitBSY();
WriteReg(_DeviceAndHead,0xa0|head);
WriteReg(_CylinderH,(char)(cylinder>>8));
WriteReg(_CylinderL,(char)(cylinder&0x00ff));
WriteReg(_SecNum,sector);
WriteReg(_SecCount,read_count);



}



/**********************************************************
*用途:将硬盘的返回数据读入BUFFER数组                      *
***********************************************************/
void SendData()
{ uint i;
i=512*15;
do{ReadReg(_Status_Command);}while(BSY|!DRQ);
if(ERR){
  send_string("\x0d\x0a Error\x0d\x0a");
    }
while(i){ReadData();send_char(Data_bufferL);send_char(Data_bufferH);i-=2;}
}



// 激活硬盘(转动)
void SpinUP()
{
WaitBSY();
  WriteReg(_Status_Command,0xE1);



}
// 让硬盘休眠(停转)/
void SpinDown()
{
WaitBSY();
  WriteReg(_Status_Command,0xE0);



}




void main(void)
{
//Initialize
SCON=0x50;  //串口初始化
TMOD=0x20;   //波特率为57600bps
TCON=0x40;
PCON=0x80;
TH1=0xFf;
TL1=0xFf;

TR1=1;
send_string("IDE Control Demo.     Power By DDDLZHU\x0d\x0a");//send welcome word



Rst=0; //IDE 复位
delay(50);
Rst=1;
delay(255);



send_string("Reset Driver OK...\x0d\x0a");
Init();   //初始化硬盘
send_string("Initialize Driver OK,Now Read ID\x0d\x0a");
send_string("HardDisk ID is ....\x0d\x0a");
DriverID();  //读硬盘id
send_string("\n\nNow Read The First Sector On this HardDisk\x0d\x0a\x0d\x0a");
delay(244);
delay(244);
delay(244);
delay(244);
WriteCHS(0,0,1,16); //写地址
WaitBSY();



WriteReg(_Status_Command,0x20);   //发送读命令
SendData();
send_string("\x0d\x0a\x0d\x0a Read OK,Now Shut Down The HardDisk..\x0d\x0a");
SpinDown();    //硬盘停转    
while(1);
}






//**************************************串口子程序
void send_char(unsigned char word)
{
TI=0;
SBUF=word;
while(TI==0);
TI=0;




}



void send_string(unsigned char *word)
{
TI=0;
while(*word!=0)
  {



  SBUF=*word;
  while(TI==0);
  TI=0;
  word++;
  }



}



unsigned char get_char(void)
{
RI=0;
REN=1;



while(RI==0);
return(SBUF);
RI=0;
REN=0;




}




//88888888888888888888888888888888888888888

上一页  [1] [2] [3] [4] 


Tag:单片机电路图电路图讲解,电路图练习电子电路图 - 单片机电路图

《硬盘控制电路以及原程序》相关文章