資源描述:
《51單片機硬盤控制源程序》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、51單片機硬盤控制電路以及源程序2011-01-3010:19#include/***************************************************?????????????????HardDiskControlDemo*????PowerBYDDDLZHU*???編譯環(huán)境:KEILC51V7.07???支持器件:AT89C51??????*???????????????????COPYRIGHT(C)2004????????????????????????*******************
2、********************************/#definebyteunsignedchar#defineuintunsignedint/*************************************************//線路連接定義。如電路有變直接修改就可以了*************************************************/#defineDataHP1??????????????#defineDataLP0#defineRegAddrP2#defineReadP3_4#defi
3、neWriteP3_3#defineRstP3_2/*************************************************//線路連接定義。如電路有變直接修改就可以了*************************************************///寄存器地址定義#define_Status_Control0x16#define_Data0x8#define_Err_Features0x9#define_SecCount0xa#define_SecNum0xb#define_CylinderL0xc#d
4、efine_CylinderH0xd#define_DeviceAndHead0xe#define_Status_Command0xf//**************************************************************************************//*這里為初始化硬盤的重要參數(shù),每個硬盤的參數(shù)都不盡相同。若不正確則讀不了盤中的數(shù)據(jù)。計算方法如下:先看清楚你的硬盤表面標(biāo)簽中的數(shù)據(jù),里面有三個重要參數(shù):1。柱面數(shù)(Cylinder)2。磁頭數(shù)(Head)3。磁道數(shù)(Sector)其中_Max
5、Head=0xA+Head????_MaxSector=Sector例如我的130M硬盤(很老吧,哈哈),磁頭數(shù)為15,十六進(jìn)制為0xf,所以_MaxHead=0xAF,磁道數(shù)為17,所以_MaxSector=0x11*/#define_MaxHead0xAF#define_MaxSector0x11//************************************************************************************bytebdataStatus="0x00";sbitERR="Status"^0
6、;sbitIDX="Status"^1;sbitCORR="Status"^2;sbitDRQ="Status"^3;sbitDSC="Status"^4;sbitDF="Status"^5;sbitDRDY="Status"^6;sbitBSY="Status"^7;//*************************************************************D7??D6??D5??D4??D3??D2???D1??D0???????????????????*BSY?DRDY?DWF?DSCDRQ?CORR?IDX?
7、?ERR??????????????????*BSY:驅(qū)動器忙;????????????????????????????????????????????*DRDY:驅(qū)動器準(zhǔn)備好;???????????????????????????????????????*DWF:驅(qū)動器寫失敗;????????????????????????????????????????*DSC:尋道結(jié)束;?????????????????????????????????????????????*DRQ:請求服務(wù),驅(qū)動器希望通過數(shù)據(jù)寄存器與CPU交換一字節(jié)數(shù)據(jù);*CORR:當(dāng)可以
8、糾正的讀錯誤發(fā)生時,該位置1,數(shù)據(jù)傳輸將繼續(xù)進(jìn)行*IDX:收到綜引信號;??????????????????