📄 main.i
字号:
#line 1 "System\main.c" /0 #line 1 "C:\KEIL\C51\INC\ATMEL\REG51.H" /0 sfr P0 = 0x80; sfr P1 = 0x90; sfr P2 = 0xA0; sfr P3 = 0xB0; sfr PSW = 0xD0; sfr ACC = 0xE0; sfr B = 0xF0; sfr SP = 0x81; sfr DPL = 0x82; sfr DPH = 0x83; sfr PCON = 0x87; sfr TCON = 0x88; sfr TMOD = 0x89; sfr TL0 = 0x8A; sfr TL1 = 0x8B; sfr TH0 = 0x8C; sfr TH1 = 0x8D; sfr IE = 0xA8; sfr IP = 0xB8; sfr SCON = 0x98; sfr SBUF = 0x99; sbit CY = 0xD7; sbit AC = 0xD6; sbit F0 = 0xD5; sbit RS1 = 0xD4; sbit RS0 = 0xD3; sbit OV = 0xD2; sbit P = 0xD0; sbit TF1 = 0x8F; sbit TR1 = 0x8E; sbit TF0 = 0x8D; sbit TR0 = 0x8C; sbit IE1 = 0x8B; sbit IT1 = 0x8A; sbit IE0 = 0x89; sbit IT0 = 0x88; sbit EA = 0xAF; sbit ES = 0xAC; sbit ET1 = 0xAB; sbit EX1 = 0xAA; sbit ET0 = 0xA9; sbit EX0 = 0xA8; sbit PS = 0xBC; sbit PT1 = 0xBB; sbit PX1 = 0xBA; sbit PT0 = 0xB9; sbit PX0 = 0xB8; sbit RD = 0xB7; sbit WR = 0xB6; sbit T1 = 0xB5; sbit T0 = 0xB4; sbit INT1 = 0xB3; sbit INT0 = 0xB2; sbit TXD = 0xB1; sbit RXD = 0xB0; sbit SM0 = 0x9F; sbit SM1 = 0x9E; sbit SM2 = 0x9D; sbit REN = 0x9C; sbit TB8 = 0x9B; sbit RB8 = 0x9A; sbit TI = 0x99; sbit RI = 0x98; #line 1 "System\main.c" /0 #line 1 "C:\KEIL\C51\INC\ABSACC.H" /0 #line 24 "C:\KEIL\C51\INC\ABSACC.H" /1 #line 29 "C:\KEIL\C51\INC\ABSACC.H" /0 #line 2 "System\main.c" /0 static unsigned char code LCD1[16]= "TOPLOW DESIGN "; static unsigned char code LCD2[16]= "Copyright(C)2004"; static unsigned char code ERROR[16]="ERROR "; static unsigned char code PASS[16]= "PASS "; unsigned char buffer0,buffer1; unsigned char buffer[16]; unsigned char STATUS; sbit BFLAG=ACC^7; sbit BSY=ACC^7; sbit DRDY=ACC^6; sbit DRQ=ACC^3; sbit ERR=ACC^0; sbit RESET=P3^5; sbit READ=P3^0; sbit WRITE=P3^1; sbit ILT=ACC^0; sbit INTRQ=P3^3; void delay(unsigned int time) { unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<255;j++); } void putch(unsigned char ch) { SBUF=ch; TI=0; while(!TI); } unsigned char getch(void) { unsigned char temp; while(!RI); temp=SBUF; RI=0; return(temp); } void wait(void) { do{ACC=((unsigned char volatile xdata *) 0)[0x0008];} while(BFLAG==1); } void IniLcd(void) { ((unsigned char volatile xdata *) 0)[0x0008]=0x38; wait(); ((unsigned char volatile xdata *) 0)[0x0008]=0x08; wait(); ((unsigned char volatile xdata *) 0)[0x0008]=0x01; wait(); ((unsigned char volatile xdata *) 0)[0x0008]=0x06; wait(); ((unsigned char volatile xdata *) 0)[0x0008]=0x0c; wait(); } void LcdDis(unsigned char FL,unsigned char Lcd1[16],unsigned char SL,unsigned char Lcd2[16]) { unsigned char k; ((unsigned char volatile xdata *) 0)[0x0008]=FL|0x80; wait(); for(k=0;k<16;k++){ ((unsigned char volatile xdata *) 0)[0x0009]=Lcd1[k]; wait(); } ((unsigned char volatile xdata *) 0)[0x0008]=SL|0xc0; wait(); for(k=0;k<16;k++){ ((unsigned char volatile xdata *) 0)[0x0009]=Lcd2[k]; wait(); } } void ReadReg(unsigned char ADD) { ((unsigned char volatile xdata *) 0)[0x0007]=0x92; ((unsigned char volatile xdata *) 0)[0x0006]=ADD; READ=0; ACC=((unsigned char volatile xdata *) 0)[0x0004]; STATUS=ACC; READ=1; } void WriteReg(unsigned char ADD,unsigned char DATA) { ((unsigned char volatile xdata *) 0)[0x0007]=0x80; ((unsigned char volatile xdata *) 0)[0x0006]=ADD; WRITE=0; ((unsigned char volatile xdata *) 0)[0x0004]=DATA; WRITE=1; } void ReadData() { ((unsigned char volatile xdata *) 0)[0x0007]=0x92; ((unsigned char volatile xdata *) 0)[0x0006]=0x00; READ=0; buffer0=((unsigned char volatile xdata *) 0)[0x0004]; buffer1=((unsigned char volatile xdata *) 0)[0x0005]; READ=1; } void WriteData(unsigned char Data0,unsigned char Data1) { ((unsigned char volatile xdata *) 0)[0x0007]=0x80; ((unsigned char volatile xdata *) 0)[0x0006]=0x00; WRITE=0; ((unsigned char volatile xdata *) 0)[0x0004]=Data0; ((unsigned char volatile xdata *) 0)[0x0005]=Data1; WRITE=1; } WriteCHS(unsigned char head,unsigned int cylinder,unsigned char sector) { do{ReadReg(0x07);}while(BSY); WriteReg(0x06,0xe0&head); WriteReg(0x05,cylinder>>8); WriteReg(0x04,cylinder&0x00ff); WriteReg(0x03,sector); WriteReg(0x02,0x01); } WriteCommand(command) { do{ReadReg(0x07);}while(BSY); WriteReg(0x07,command); } void GetData() { unsigned int i=512; do{ReadReg(0x07);}while(BSY|!DRQ); if(ERR){ LcdDis(0,ERROR,0,LCD2); putch(255); } while(i){ReadData();putch(buffer0);putch(buffer1);i-=2;} } void IniHard(void) { do{ WriteReg(0x06,0xa0); ReadReg(0x07); }while(!DRDY|BSY); WriteReg(0x06,0x20); WriteReg(0x02,64); WriteReg(0x07,0x91); do{ReadReg(0x07);}while(BSY); WriteReg(0x07,0x10); do{ReadReg(0x07);}while(BSY); } void DriveID(void) { unsigned int i=512; do{ReadReg(0x07);}while(BSY); WriteReg(0x07,0xec); do{ReadReg(0x07);}while(BSY|!DRQ); while(i){ReadData();putch(buffer0);putch(buffer1);i-=2;} } void HardDiskControl(void) { unsigned int i; SCON=0x50; TMOD=0x21; PCON=0x80; TCON=0x51; EA=1; EX0=0; TH1=0xD0; TL1=0xD0; TI=1; RESET=0; delay(50); RESET=1; delay(255); IniHard(); WriteCHS(0,0,0); WriteCommand(0x20); GetData(); IniLcd(); LcdDis(0,LCD1,0,LCD2); for(i=0;i<512;i++){ putch(i); delay(255); } while(1); } void main(void){ HardDiskControl(); DriveID(); WriteData(0X00,0X01); getch(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -