Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/22/02 07:47
Read: times


 
#23225 - RE: Reading hard disk with 8051
I don't know why the bit error was set.Now can read though still I don`t understand.

The steps are:
- Init HD: do reset
- Wait busyHD
- Read sector 1 in CHS with command 21Hex


Thanks.

This is the code:
DATOL EQU P1
DATOH EQU P4 ;P3
IDE_A0_LINE EQU P5.0
IDE_A1_LINE EQU P5.1
IDE_A2_LINE EQU P5.2
IDE_CS0_LINE EQU P5.3 ;BAJA
IDE_CS1_LINE EQU P5.4 ;BAJA
IDE_WR_LINE EQU P5.5 ;BAJA
IDE_RD_LINE EQU P5.6 ;BAJA
IDE_RST_LINE EQU P5.7 ;BAJA


InitHD1:
SETB IDE_WR_LINE
SETB IDE_RD_LINE
clr IDE_CS1_LINE ;select master disk
setb IDE_CS0_LINE
clr IDE_RST_LINE ;reset
setb IDE_RST_LINE
ret

;READ sector
mov r1,#1 ;write register to read a sector 1
mov r2,#1
mov r3,#0
mov r4,#0
mov r5,#%10100000 ;CHS mode
mov a,#$21 ;read command

; mov a,#$EC
acall ReadHD

fin:
jmp fin

;-----------------------------------------------------
; ReadHD
; Manda un comando de lectura al HD
;-----------------------------------------------------
; Entrada
; A Comando que se le envia al HD, command
; R1 Sector count register
; R2 Sector number register / LBA 0-7
; R3 Cylinder register 0 / LBA 8-15
; R4 Cylinder register 1 / LBA 16-23
; R5 Drive/Head register / LBA 24-27
; Modifica
;
;
ReadHD:

acall estado_bsy ;wait busy

;Drive/Head register
clr IDE_A0_LINE
setb IDE_A1_LINE
setb IDE_A2_LINE
mov DATOL,r5 ;escribimos el registro
mov DATOH,r5
clr IDE_WR_LINE ;iniciamos la escritura
setb IDE_WR_LINE ;finaliza la escritura
;Cylinder register1
setb IDE_A0_LINE
clr IDE_A1_LINE
setb IDE_A2_LINE
mov DATOL,r4 ;escribimos el comando
mov DATOH,r4
clr IDE_WR_LINE ;iniciamos la escritura
setb IDE_WR_LINE ;finaliza la escritura

;Cylinder register0
clr IDE_A0_LINE
clr IDE_A1_LINE
setb IDE_A2_LINE
mov DATOL,r3 ;escribimos el comando
mov DATOH,r3
clr IDE_WR_LINE ;iniciamos la escritura
setb IDE_WR_LINE ;finaliza la escritura

;Sector number register
setb IDE_A0_LINE
setb IDE_A1_LINE
clr IDE_A2_LINE
mov DATOL,r2 ;escribimos el comando
mov DATOH,r2
clr IDE_WR_LINE ;iniciamos la escritura
setb IDE_WR_LINE ;finaliza la escritura

;Sector count register
clr IDE_A0_LINE
setb IDE_A1_LINE
clr IDE_A2_LINE
mov DATOL,r1 ;escribimos el comando
mov DATOH,r1
clr IDE_WR_LINE ;iniciamos la escritura
setb IDE_WR_LINE ;finaliza la escritura

;Enviamos el comando
setb IDE_A0_LINE
setb IDE_A1_LINE
setb IDE_A2_LINE
mov DATOL,a ;escribimos el comando
mov DATOH,a
clr IDE_WR_LINE ;iniciamos la escritura en el reg. de comandos
setb IDE_WR_LINE ;finaliza la escritura
mov dptr,#buffer ;apuntamos dptr a nuestro buffer

ReadHD1:
acall estado_bsy
acall read_buffer
MOV A,R0
ANL A,#%00001000 ;miramos el DRQ para ver si ha terminado la lectura
jnz ReadHD1
ret
;----------FIN ReadHD-------------------------------------

estado_bsy:
push acc
estado_bsy1:
setb IDE_A0_LINE ;Selecciona el DATA REGISTER
setb IDE_A1_LINE
setb IDE_A2_LINE
mov DATOL,#$FF
clr IDE_RD_LINE ;iniciamos lectura del reg. de estado
MOV a,DATOL
setb IDE_RD_LINE
MOV R0,A
;miramos si hay error
anl a,#$01
jnz ErrorHD
mov a,R0
;fin error
anl a,#$80 ;comprobamos el estado,si todavia no ha
jnz estado_bsy1 ;terminado el comando,vuelve a preguntar
pop acc
ret

ErrorHD:
;Error register
setb IDE_A0_LINE
clr IDE_A1_LINE
clr IDE_A2_LINE
mov DATOL,#$FF
mov DATOH,#$FF
clr IDE_RD_LINE ;iniciamos la escritura
mov a,DATOL ;escribimos el comando
mov b,DATOH
setb IDE_RD_LINE ;finaliza la escritura

acall lcd2line ;second line in lcd
mov DPTR,#ErrorS
acall WString
acall ATOLCD
mov r0,#$00
acall lcd1line
pop acc
ret
;--------------FIN ESTADO_BSY--------------------
read_buffer:
clr IDE_A0_LINE ;Selecciona el DATA REGISTER
clr IDE_A1_LINE
clr IDE_A2_LINE
mov DATOL,#$FF
mov DATOH,#$FF
clr IDE_RD_LINE
mov a,DATOH
mov b,DATOL
setb IDE_RD_LINE
movx @dptr,a
inc dptr
mov a,b
movx @dptr,a
inc dptr
ret



List of 10 messages in thread
TopicAuthorDate
Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      
RE: Reading hard disk with 8051            01/01/70 00:00      

Back to Subject List