新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 51單片機硬盤控制電路以及源程序

        51單片機硬盤控制電路以及源程序

        作者: 時間:2012-10-12 來源:網(wǎng)絡 收藏

        #include at89x51.h>

        /**************************************************
        * HardDisk Control Demo
        * Power BY DDDLZHU
        * 編譯環(huán)境 : KEIL C51 V7.07 支持器件 : AT89C51
        * COPYRIGHT (C) 2004

        ***************************************************/

        #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

        //******************************************************/
        /*這里為初始化硬盤的重要參數(shù),每個硬盤的參數(shù)都不盡相同。若不正確則讀不了盤中的數(shù)據(jù)。計算方法如下:
        先看清楚你的 硬盤表面標簽中的數(shù)據(jù),里面有三個重要參數(shù):
        1。柱面數(shù)(Cylinder)
        2。磁頭數(shù)(Head)
        3。磁道數(shù)(Sector)
        其中 _MaxHead=0xA+Head
        _MaxSector=Sector
        例如我的130M硬盤(很老吧,哈哈),磁頭數(shù)為15,十六進制為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:驅動器忙; *
        DRDY:驅動器準備好; *
        DWF:驅動器寫失敗; *
        DSC:尋道結束; *
        DRQ:請求服務,驅動器希望通過數(shù)據(jù)與CPU交換一字節(jié)數(shù)據(jù);*
        CORR:當可以糾正的讀錯誤發(fā)生時,該位置1,數(shù)據(jù)傳輸將繼續(xù)進行 *
        IDX:收到綜引信號; *
        ERR:命令執(zhí)行出錯。 *
        *************************************************************/

        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;ims;i++)
        for(j=0;j255;j++);
        }

        /*******************************************************
        *讀
        ********************************************************/
        byte ReadReg(byte Addr)
        {
        RegAddr=Addr;
        DataL=0xff;
        Read=0;
        Status=DataL;
        Read=1;
        return Status;
        }

        /*******************************************************
        *等待BSY信號
        ********************************************************/
        byte WaitBSY(void)
        {
        byte timeOut=0;
        do{
        ReadReg(_Status_Command);
        timeOut++;
        // if(timeOut>=254) return(0xff);
        }while(BSY);
        return(1);
        }

        51單片機相關文章:51單片機教程



        上一頁 1 2 下一頁

        評論


        相關推薦

        技術專區(qū)

        關閉
        主站蜘蛛池模板: 乐山市| 广水市| 深圳市| 土默特右旗| 武川县| 乌拉特后旗| 杂多县| 珠海市| 中西区| 金华市| 婺源县| 牟定县| 普兰县| 安塞县| 内丘县| 阜新| 鸡泽县| 辽源市| 青浦区| 永年县| 大同市| 山东| 富民县| 汝南县| 武夷山市| 富锦市| 东乡族自治县| 博野县| 井研县| 怀仁县| 双流县| 宝坻区| 通城县| 赫章县| 哈尔滨市| 大悟县| 昭觉县| 镇巴县| 乌苏市| 武功县| 新源县|