📄 cdpaul.txt
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Onhold Revision 5.1
; Modify Version By Leo Lau
; leo8597@yahoo.com.hk
;
; 25 Sep 2006
; more a little function...
; When pause CD, allow using Eject Key, Stop Key to Eject or Stop CD
;
; 24 Sep 2006
; Fix a little bug again...
; Add Mode Sense Function to check CD-Rom tray status open or close
; and modify LCD display to reduce flashing when connect VFD Module
;
; Onhold Revision 5
; Modify Version By Leo Lau
; leo8597@yahoo.com.hk
;
; 29 Jan 2005
; Fix a little bug Open CD-Rom Tray & Change TOC Total Time
;
; Remove 74LS164, BC559, 7 x 1K 1 x & 5.6K Resistor, 1 x LED,
; Redraw PCB Board (Single Side),
; Change 4 x Keys function + IR Receive or 5 x Keys Function
; Open, Stop, Play, Previous, Next & Pause Key
; high to low (remove 4 x 1K Resistor)
; using 4 bit to control LCD
;
; Onhold Revision 3
; Modify Version By Leo Lau
; leo8597@yahoo.com.hk
; 22 Dec 2003
;
; Add More Key for Open, Close, Previous, Stop and Play Key. Change LCD
; Display like a Audio CD Player...
;
; Normal Function is work such as Open CD-Rom Tray, Stop,
; Play, Next & Previous. But some bug may be found...I'm still debug...
;
; onhold (final at89c51 target), with 16x2 character LCD display
; Revision 2
; A Simple 8051 based ATAPI CDROM audio controller
; Copyright (C) 2000,2002 Jason Nunn <jsno@arafura.net.au>
; August 2000
;
; This software comes under the GNU public license agreement. See the COPYING
; file in this distribution.
;
; If you use this code (or parts) of it, then please credit me.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; WWW: http//jsno.arafuraconnect.com.au
;
; If you use this code (or parts) of it, then please credit me.
;
; coded to parse by LA51 assembler (ASM51)
; current target: - DARMICON development board (SAB80C537 @ 12Mhz)
; (by Felino MOLINA & Howard PULLEN- www.ntu.edu.au)
; - 16x2 LM016L compatable LCD display
;
; ====================================================================
;
; designed for one device only (set to master)
;
; design references:
;
; - ATA/ATAPI-5 (T13/1321D R3) (www.t10.org)
; - ATA packet interface for CDROM's (SFF-8020i) (fission.dt.wdc.com)
;
; other references used:
;
; - linux 2.2.x source code (/usr/src/linux/drivers/ide*)
; (had to be referred to seens that the SFF-8020i spec is so shitty)
;
; - ATAPI references & Black magic in ATA/ATAPI
; by Constantine Sapuntzakis <csapuntz@stanford.edu>
; http://www.stanford.edu/~csapuntz/ide.html
; http://www.stanford.edu/~csapuntz/blackmagic.html
;
; - 8052 Basic project page (IDE logger section)
; by Sergey Zorin <zorinsn@rs-pribor.ru>
; http://www.nomad.ee/micros/8052bas.html
; (nb/ very very helpful)
;
; - General ATAPI info (including some source code)
; Hale Landis's ATAPI pages http://www.ata-atapi.com
; (a good introduction to it all, as i knew nothing when i first started
; this project)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CODE_BASE equ 0000h
STACK_START equ 3fh
;ctrl bus
;
; 7 6 5 4 3 2 1 0
;+DA2+DA1+DA0+CS1+CS0+---+---+---+
;| X | X | X | X | X | | | |
;+---+---+---+---+---+---+---+---+
;
ATA_ADDR data p2
;
; LCD ctrl and data lines
;
; nb/ some of the lines on by development board have had the
; "smoke let out of them" (ie- blown up)... hence the uncontingious
; choice of lines used ;)
LCD_RS bit P2.3 ; LCD RS pin
LCD_EN bit P2.0 ; LCD EN pin
LCD_DATA data P2 ; LCD Data
ATA_nReset bit p3.0 ; ATA Reset
ATA_nDIOW bit p3.1
ATA_nDIOR bit p3.2
ATA_INTRQ bit p2.2 ;**
;
; p3.3 Reserve for IR input or other function key
;
EJECT_Key bit p3.3 ;open cd-rom tray
STOP_KEY bit p3.4 ;stop cd-rom
PREVIOUS_TRK bit p3.5 ;previous track
NEXT_TRK bit p3.6 ;next track
PLAY_KEY bit p3.7 ;play audio cd
PAUSE_KEY bit p3.7 ;pause cd-rom
;
;data bus
ATA_DATA_LS data p1
ATA_DATA_MS data p0
; variable data
;
packet_size data 08h
start_track data 09h
end_track data 0ah
current_track data 0bh
next_track data 0ch
toc_track data 0dh
toc_M data 0eh
toc_S data 0fh
toc_F data 10h
toc_M_next data 11h
toc_S_next data 12h
toc_F_next data 13h
start_M data 14h
start_S data 15h
start_F data 16h
end_M data 17h
end_S data 18h
end_F data 19h
next_M data 1ah
next_S data 1bh
next_F data 1ch
audio_status data 1dh
over_track data 1eh
packet_tab data 70h
packet_cmd data 70h
packet_1 data 71h
packet_2 data 72h
packet_3 data 73h
packet_4 data 74h
packet_5 data 75h
packet_6 data 76h
packet_7 data 77h
packet_8 data 78h
packet_9 data 79h
packet_10 data 7ah
packet_11 data 7bh
packet_12 data 7ch
packet_13 data 7dh
packet_14 data 7eh
packet_15 data 7fh
;
Position data 35H
mediatype data 3ch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org CODE_BASE
ljmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; delay routines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delay_100000us:
mov r7,#0c8h
delay_100000us_l0:
mov r6,#0f8h
delay_100000us_l1:
djnz r6,delay_100000us_l1
nop
djnz r7,delay_100000us_l0
ret
;r5 = seconds
delay:
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
acall delay_100000us
djnz r5,delay
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; New LCD routines
;
; Remove 74LS164, Change 4 bit
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SET_LCD:
MOV R5,#1
CALL DELAY
CLR LCD_EN
CALL INIT_LCD
MOV R5,#10
CALL LCD_DELAY
MOV DPTR,#LMESS1 ; CD-Rom Player
MOV A,#1
CALL LCD_PRINT
MOV DPTR,#LMESS2 ; Version 5.0
MOV A,#2
CALL LCD_PRINT
MOV R5,#2
CALL DELAY
Ret
INIT_LCD:
MOV LCD_DATA,#30H
CALL EN1
MOV LCD_DATA,#30H
CALL EN1
MOV LCD_DATA,#30H
CALL EN1
MOV LCD_DATA,#20H
CALL EN1
CALL INIT_LCD1
Ret
EN1:
SETB LCD_EN
CALL DE
CLR LCD_EN
CALL DE
Ret
DE: MOV R7,#5
DJNZ R7,$
Ret
WCOM:
; Write Hi 4 Bit
MOV LCD_DATA,A
CLR LCD_RS
CALL EN1
RLC A
RLC A
RLC A
RLC A
; Write Low 4 Bit
MOV LCD_DATA,A
CLR LCD_RS
CALL EN1
Ret
WDATA:
; Write Hi 4 Bit
MOV LCD_DATA,A
SETB LCD_RS
CALL EN1
RLC A
RLC A
RLC A
RLC A
; Write Low 4 Bit
MOV LCD_DATA,A
SETB LCD_RS
CALL EN1
Ret
INIT_LCD1:
MOV A,#28H
CALL WCOM
MOV A,#0CH ; Cursor On = 0EH Off = 0CH
CALL WCOM
MOV A,#06H
CALL WCOM
CLR_SCREEN:
MOV A,#01H
CALL WCOM
Ret
LCD_PRINT:
CJNE A,#1,LINE2
LINE1:MOV A,#80H
CALL WCOM
CALL CLR_LINE
MOV A,#80H
CALL WCOM
JMP FILL
LINE2:MOV A,#0C0H
CALL WCOM
CALL CLR_LINE
MOV A,#0C0H
CALL WCOM
FILL: CLR A
MOVC A,@A+DPTR
CJNE A,#0,L1
Ret
L1:
CALL WDATA
INC DPTR
JMP FILL
Ret
;
CLR_LINE:
MOV R0,#24
C1: MOV A,#' '
CALL WDATA
DJNZ R0,C1
Ret
LCD_CLEAR:
; CLEAR LINE 1
MOV A,#80H
CALL WCOM
MOV R0,#24
AA: MOV A,#' '
CALL WDATA
DJNZ R0,AA
; CLEAR LINE2
MOV A,#0C0H
CALL WCOM
MOV R0,#24
BB: MOV A,#' '
DJNZ R0,AA
Ret
CLR_LINE1:
MOV A,#80H
CALL WCOM
MOV R0,#24
CC: MOV A,#' '
CALL WDATA
DJNZ R0,CC
Ret
CLR_LINE2:
MOV A,#0C0H
CALL WCOM
MOV R0,#24
CC2: MOV A,#' '
CALL WDATA
DJNZ R0,CC2
Ret
LCD_DELAY:
MOV R6,#50
DD: MOV R7,#100
DJNZ R7,$
DJNZ R6,DD
DJNZ R5,LCD_DELAY
Ret
LCDP1:
PUSH ACC
MOV A,B
ADD A,#80H
CALL WCOM
POP ACC
CALL WDATA
Ret
;
LCDP2:
PUSH ACC
MOV A,B
ADD A,#0C0H
CALL WCOM
POP ACC
CALL WDATA
Ret
SHOW_DIG1:
MOV B,#10
DIV AB
ADD A,#30H
PUSH B
MOV B,POSITION
CALL LCDP1
;
POP B
MOV A,B
ADD A,#30H
INC POSITION
MOV B,POSITION
CALL LCDP1
Ret
SHOW_DIG2:
MOV B,#10
DIV AB
ADD A,#30H
PUSH B
MOV B,POSITION
CALL LCDP2
;
POP B
MOV A,B
ADD A,#30H
INC POSITION
MOV B,POSITION
CALL LCDP2
Ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; atomic routines
;
; Nb/ code assumes 1us clock cycle (12Mhz xtal clock)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
read_cycle:
mov ATA_DATA_LS,#0ffh
mov ATA_DATA_MS,#0ffh
clr ATA_nDIOR
mov a,ATA_DATA_LS
mov b,ATA_DATA_MS
setb ATA_nDIOR
ret
read_cycle_ls:
mov ATA_DATA_LS,#0ffh
clr ATA_nDIOR
mov a,ATA_DATA_LS
setb ATA_nDIOR
ret
write_cycle:
mov ATA_DATA_LS,a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -