<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)控制硬盤(pán)的C語(yǔ)言源碼程序

          51單片機(jī)控制硬盤(pán)的C語(yǔ)言源碼程序

          作者: 時(shí)間:2016-11-28 來(lái)源:網(wǎng)絡(luò) 收藏
          #include
          /////////////////////////////////////////////////////////////////////////////////////////////////////
          // 單片機(jī)教程httP://www.ipbb.cn
          // Power BY DDDLZHU
          // 編譯環(huán)境 : KEIL C51 V7.07 支持器件 : AT89C51
          ///////////////////////////////////////////////////////////////////////////////////////////////////////
          #define byte unsigned char
          #define uint unsigned int
          ///////////////////////////////////////////////////////////////////////////////////////////////////
          //線路連接定義。如電路有變直接修改就可以了
          ///////////////////////////////////////////////////////////////////////////////////////////////////
          #define DataH P1
          #define DataL P0
          #define RegAddr P2
          #define Read P3_4
          #define Write P3_3
          #define Rst P3_2
          ///////////////////////////////////////////////////////////////////////////////////////////////////
          //線路連接定義。如電路有變直接修改就可以了
          ///////////////////////////////////////////////////////////////////////////////////////////////////
          //寄存器地址定義
          #define _Status_Control 0x16
          #define _Data 0x8
          #define _Err_Features 0x9
          #define _SecCount 0xa
          #define _SecNum 0xb
          #define _CylinderL 0xc
          #define _CylinderH 0xd
          #define _DeviceAndHead 0xe
          #define _Status_Command 0xf
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          ///這里為初始化硬盤(pán)的重要參數(shù),每個(gè)硬盤(pán)的參數(shù)都不盡相同。若不正確則讀不了盤(pán)中的數(shù)據(jù)。計(jì)算方法如下:
          先看清楚你的 硬盤(pán)表面標(biāo)簽中的數(shù)據(jù),里面有三個(gè)重要參數(shù):
          1。柱面數(shù)(Cylinder)
          2。磁頭數(shù)(Head)
          3。磁道數(shù)(Sector)
          其中 _MaxHead=0xA+Head
          _MaxSector=Sector
          例如我的130M硬盤(pán)(很老吧,哈哈),磁頭數(shù)為15,十六進(jìn)制為0xf,所以_MaxHead=0xAF,磁道數(shù)為17,所以_MaxSector=0x11
          ///
          #define _MaxHead 0xAF
          #define _MaxSector 0x11
          //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          byte bdata Status=0x00;
          sbit ERR=Status^0;
          sbit IDX=Status^1;
          sbit CORR=Status^2;
          sbit DRQ=Status^3;
          sbit DSC=Status^4;
          sbit DF=Status^5;
          sbit DRDY=Status^6;
          sbit BSY=Status^7;
          //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          // D7 D6 D5 D4 D3 D2 D1 D0 //
          BSY DRDY DWF DSC DRQ CORR IDX ERR //
          BSY:驅(qū)動(dòng)器忙; //
          DRDY:驅(qū)動(dòng)器準(zhǔn)備好; //
          DWF:驅(qū)動(dòng)器寫(xiě)失敗; //
          DSC:尋道結(jié)束; //
          DRQ:請(qǐng)求服務(wù),驅(qū)動(dòng)器希望通過(guò)數(shù)據(jù)寄存器與CPU交換一字節(jié)數(shù)據(jù);//
          CORR:當(dāng)可以糾正的讀錯(cuò)誤發(fā)生時(shí),該位置1,數(shù)據(jù)傳輸將繼續(xù)進(jìn)行 //
          IDX:收到綜引信號(hào); //
          ERR:命令執(zhí)行出錯(cuò)。 //
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          byte Data_bufferH=0x0;
          byte Data_bufferL=0x0;
          ////////////////////////////////串口子程序
          void send_string(unsigned char //word);
          void send_char(unsigned char word);
          unsigned char get_char(void);
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          :延遲函數(shù)
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          void delay(byte ms)
          { byte i,j;
          for(i=0;i
          for(j=0;j<255;j++);
          }
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          //讀寄存器
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          byte ReadReg(byte Addr)
          {
          RegAddr=Addr;
          DataL=0xff;
          Read=0;
          Status=DataL;
          Read=1;
          return Status;
          }
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          //等待BSY信號(hào)
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          byte WaitBSY(void)
          {
          byte timeOut=0;
          do{
          ReadReg(_Status_Command);
          timeOut++;
          // if(timeOut>=254) return(0xff);
          }while(BSY);
          return(1);
          }
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////
          //寫(xiě)寄存器值
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          void WriteReg(byte Addr,byte Data)
          {
          RegAddr=Addr;
          Write=0;
          DataL=Data;
          Write=1;
          }
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          讀數(shù)據(jù)儲(chǔ)存器中數(shù)據(jù)
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          void ReadData(void)
          {
          DataH=0xff;
          DataL=0xff;
          RegAddr=_Data;
          Read=0;
          Data_bufferL=DataL;
          Data_bufferH=DataH;
          Read=1;
          }
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          寫(xiě)數(shù)據(jù)寄存器中數(shù)據(jù)
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          void WriteData(void)
          {
          RegAddr=_Data;
          Write=0;
          DataL=Data_bufferL;
          DataH=Data_bufferH;
          Write=1;
          }

          上一頁(yè) 1 2 下一頁(yè)

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();